github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/protocol/bc/types/block_commitment.go (about)

     1  package types
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/bytom/bytom/encoding/blockchain"
     7  	"github.com/bytom/bytom/protocol/bc"
     8  )
     9  
    10  // BlockCommitment store the TransactionsMerkleRoot && TransactionStatusHash
    11  type BlockCommitment struct {
    12  	// TransactionsMerkleRoot is the root hash of the Merkle binary hash tree
    13  	// formed by the hashes of all transactions included in the block.
    14  	TransactionsMerkleRoot bc.Hash `json:"transaction_merkle_root"`
    15  
    16  	// TransactionStatusHash is the root hash of the Merkle binary hash tree
    17  	// formed by the hashes of all transaction verify results
    18  	TransactionStatusHash bc.Hash `json:"transaction_status_hash"`
    19  }
    20  
    21  func (bc *BlockCommitment) readFrom(r *blockchain.Reader) error {
    22  	if _, err := bc.TransactionsMerkleRoot.ReadFrom(r); err != nil {
    23  		return err
    24  	}
    25  
    26  	_, err := bc.TransactionStatusHash.ReadFrom(r)
    27  	return err
    28  }
    29  
    30  func (bc *BlockCommitment) writeTo(w io.Writer) error {
    31  	if _, err := bc.TransactionsMerkleRoot.WriteTo(w); err != nil {
    32  		return err
    33  	}
    34  
    35  	_, err := bc.TransactionStatusHash.WriteTo(w)
    36  	return err
    37  }