MCPcopy
hub / github.com/canopy-network/canopy / SetHash

Method SetHash

lib/block.go:100–114  ·  view source on GitHub ↗

SetHash() computes and sets the BlockHash to BlockHeader.Hash

()

Source from the content-addressed store, hash-verified

98
99// SetHash() computes and sets the BlockHash to BlockHeader.Hash
100func (x *BlockHeader) SetHash() ([]byte, ErrorI) {
101 // set the hash to empty
102 x.Hash = nil
103 // convert the block header object reference to bytes
104 bz, err := Marshal(x)
105 // if an error occurred during the bytes conversion
106 if err != nil {
107 // exit with error
108 return nil, err
109 }
110 // set the hash to the hash of the block header bytes
111 x.Hash = crypto.Hash(bz)
112 // exit with the block header bytes
113 return x.Hash, nil
114}
115
116// jsonBlockHeader is the BlockHeader implementation of json.Marshaller and json.Unmarshaler
117type jsonBlockHeader struct {

Callers 10

TestCheckBlockHeaderFunction · 0.95
TestSetHashFunction · 0.95
TestBlockHeaderJSONFunction · 0.95
ProduceProposalMethod · 0.80
ApplyAndValidateBlockMethod · 0.80
HashMethod · 0.80
ApplyBlockMethod · 0.80
NewTestBlockHashMethod · 0.80
NewTestBlockHash2Method · 0.80

Calls 2

HashFunction · 0.92
MarshalFunction · 0.70

Tested by 6

TestCheckBlockHeaderFunction · 0.76
TestSetHashFunction · 0.76
TestBlockHeaderJSONFunction · 0.76
NewTestBlockHashMethod · 0.64
NewTestBlockHash2Method · 0.64