OSDN Git Service

Dev (#148)
[bytom/bytom.git] / protocol / bc / legacy / block_commitment.go
1 package legacy
2
3 import (
4         "io"
5
6         "github.com/bytom/encoding/blockchain"
7         "github.com/bytom/protocol/bc"
8 )
9
10 // BlockCommitment store the TransactionsMerkleRoot && AssetsMerkleRoot
11 type BlockCommitment struct {
12         // TransactionsMerkleRoot is the root hash of the Merkle binary hash
13         // tree formed by the hashes of all transactions included in the
14         // block.
15         TransactionsMerkleRoot bc.Hash
16
17         // AssetsMerkleRoot is the root hash of the Merkle Patricia Tree of
18         // the set of unspent outputs with asset version 1 after applying
19         // the block.
20         AssetsMerkleRoot bc.Hash
21 }
22
23 func (bc *BlockCommitment) readFrom(r *blockchain.Reader) error {
24         if _, err := bc.TransactionsMerkleRoot.ReadFrom(r); err != nil {
25                 return err
26         }
27         _, err := bc.AssetsMerkleRoot.ReadFrom(r)
28         return err
29 }
30
31 func (bc *BlockCommitment) writeTo(w io.Writer) error {
32         _, err := bc.TransactionsMerkleRoot.WriteTo(w)
33         if err != nil {
34                 return err
35         }
36         _, err = bc.AssetsMerkleRoot.WriteTo(w)
37         if err != nil {
38                 return err
39         }
40         return err
41 }