OSDN Git Service

7ad0bcec9fcc0103588055ca97cebf7a2e2fa396
[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 type BlockCommitment struct {
11         // TransactionsMerkleRoot is the root hash of the Merkle binary hash
12         // tree formed by the hashes of all transactions included in the
13         // block.
14         TransactionsMerkleRoot bc.Hash
15
16         // AssetsMerkleRoot is the root hash of the Merkle Patricia Tree of
17         // the set of unspent outputs with asset version 1 after applying
18         // the block.
19         AssetsMerkleRoot bc.Hash
20 }
21
22 func (bc *BlockCommitment) readFrom(r *blockchain.Reader) error {
23         _, err := bc.TransactionsMerkleRoot.ReadFrom(r)
24         if err != nil {
25                 return err
26         }
27         _, err = bc.AssetsMerkleRoot.ReadFrom(r)
28         if err != nil {
29                 return err
30         }
31         return err
32 }
33
34 func (bc *BlockCommitment) writeTo(w io.Writer) error {
35         _, err := bc.TransactionsMerkleRoot.WriteTo(w)
36         if err != nil {
37                 return err
38         }
39         _, err = bc.AssetsMerkleRoot.WriteTo(w)
40         if err != nil {
41                 return err
42         }
43         return err
44 }