SetHash() computes and sets the BlockHash to BlockHeader.Hash
()
| 98 | |
| 99 | // SetHash() computes and sets the BlockHash to BlockHeader.Hash |
| 100 | func (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 |
| 117 | type jsonBlockHeader struct { |