/
block_commitment.go
49 lines (42 loc) · 1.12 KB
/
block_commitment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package legacy
import (
"io"
"chain/encoding/blockchain"
"chain/protocol/bc"
)
type BlockCommitment struct {
// TransactionsMerkleRoot is the root hash of the Merkle binary hash
// tree formed by the hashes of all transactions included in the
// block.
TransactionsMerkleRoot bc.Hash
// AssetsMerkleRoot is the root hash of the Merkle Patricia Tree of
// the set of unspent outputs with asset version 1 after applying
// the block.
AssetsMerkleRoot bc.Hash
// ConsensusProgram is the predicate for validating the next block.
ConsensusProgram []byte
}
func (bc *BlockCommitment) readFrom(r *blockchain.Reader) error {
_, err := bc.TransactionsMerkleRoot.ReadFrom(r)
if err != nil {
return err
}
_, err = bc.AssetsMerkleRoot.ReadFrom(r)
if err != nil {
return err
}
bc.ConsensusProgram, err = blockchain.ReadVarstr31(r)
return err
}
func (bc *BlockCommitment) writeTo(w io.Writer) error {
_, err := bc.TransactionsMerkleRoot.WriteTo(w)
if err != nil {
return err
}
_, err = bc.AssetsMerkleRoot.WriteTo(w)
if err != nil {
return err
}
_, err = blockchain.WriteVarstr31(w, bc.ConsensusProgram)
return err
}