Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

types.gno

0.69 Kb · 37 lines
 1package cometbls
 2
 3import (
 4	"crypto/sha256"
 5
 6	"gno.land/p/nt/ufmt/v0"
 7)
 8
 9// MerkleRoot is the commitment root (app hash).
10// Mirrors ibc.core.commitment.v1.MerkleRoot.
11type MerkleRoot struct {
12	Hash []byte
13}
14
15// GetHash implements RootI interface
16func (mr MerkleRoot) GetHash() []byte {
17	return mr.Hash
18}
19
20// Empty returns true if the root is empty
21func (mr MerkleRoot) Empty() bool {
22	return len(mr.GetHash()) == 0
23}
24
25// validateHash returns an error if the hash is not empty, but its
26// size != tmhash.Size.
27func validateHash(h []byte) error {
28	if len(h) > 0 && len(h) != sha256.Size {
29		return ufmt.Errorf(
30			"expected size to be %d bytes, got %d bytes",
31			sha256.Size,
32			len(h),
33		)
34	}
35
36	return nil
37}