BytesToBlockHash() converts block bytes into a block hash
(blockBytes []byte)
| 202 | |
| 203 | // BytesToBlockHash() converts block bytes into a block hash |
| 204 | func (x *Block) BytesToBlockHash(blockBytes []byte) (hash []byte, err ErrorI) { |
| 205 | // ensure the block isn't empty |
| 206 | if blockBytes == nil { |
| 207 | // exit with error |
| 208 | return nil, ErrNilBlock() |
| 209 | } |
| 210 | // get the block header field |
| 211 | blockHeaderWithHash, e := codec.GetRawProtoField(blockBytes, 1) |
| 212 | if e != nil { |
| 213 | return nil, ErrProtoParse(e) |
| 214 | } |
| 215 | // nullify the hash included in the block header |
| 216 | blockHeaderWithoutHash, e := codec.NullifyProtoField(blockHeaderWithHash, 2) |
| 217 | if e != nil { |
| 218 | return nil, ErrProtoParse(e) |
| 219 | } |
| 220 | // exit |
| 221 | return crypto.Hash(blockHeaderWithoutHash), nil |
| 222 | } |
| 223 | |
| 224 | // jsonBlock is the Block implementation of json.Marshaller and json.Unmarshaler |
| 225 | type jsonBlock struct { |
no test coverage detected