MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / Hash

Method Hash

types/block.go:440–475  ·  view source on GitHub ↗

Hash returns the hash of the header. It computes a Merkle tree from the header fields ordered as they appear in the Header. Returns nil if ValidatorHash is missing, since a Header is not valid unless there is a ValidatorsHash (corresponding to the validator set).

()

Source from the content-addressed store, hash-verified

438// since a Header is not valid unless there is
439// a ValidatorsHash (corresponding to the validator set).
440func (h *Header) Hash() tmbytes.HexBytes {
441 if h == nil || len(h.ValidatorsHash) == 0 {
442 return nil
443 }
444 hbz, err := h.Version.Marshal()
445 if err != nil {
446 return nil
447 }
448
449 pbt, err := gogotypes.StdTimeMarshal(h.Time)
450 if err != nil {
451 return nil
452 }
453
454 pbbi := h.LastBlockID.ToProto()
455 bzbi, err := pbbi.Marshal()
456 if err != nil {
457 return nil
458 }
459 return merkle.HashFromByteSlices([][]byte{
460 hbz,
461 cdcEncode(h.ChainID),
462 cdcEncode(h.Height),
463 pbt,
464 bzbi,
465 cdcEncode(h.LastCommitHash),
466 cdcEncode(h.DataHash),
467 cdcEncode(h.ValidatorsHash),
468 cdcEncode(h.NextValidatorsHash),
469 cdcEncode(h.ConsensusHash),
470 cdcEncode(h.AppHash),
471 cdcEncode(h.LastResultsHash),
472 cdcEncode(h.EvidenceHash),
473 cdcEncode(h.ProposerAddress),
474 })
475}
476
477// StringIndented returns an indented string representation of the header.
478func (h *Header) StringIndented(indent string) string {

Callers 2

StringIndentedMethod · 0.95

Calls 4

HashFromByteSlicesFunction · 0.92
cdcEncodeFunction · 0.85
MarshalMethod · 0.45
ToProtoMethod · 0.45

Tested by 1