Skip to content

Commit

Permalink
Add godoc for exported method and consts
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Nov 6, 2023
1 parent 8cf3b4a commit a9a25e9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/trie/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
)

const (
// NoMaxValueSize is the numeric representation used to indicate that there is no max value size.
NoMaxValueSize = -1
// V1MaxValueSize is the maximum size of a value to be hashed in state trie version 1.
V1MaxValueSize = 32
)

Expand All @@ -29,13 +31,20 @@ const (
V1
)

// ErrParseVersion is returned when parsing a state trie version fails.
var ErrParseVersion = errors.New("parsing version failed")

// DefaultStateVersion sets the state version we should use as default
// See https://github.com/paritytech/substrate/blob/5e76587825b9a9d52d8cb02ba38828adf606157b/primitives/storage/src/lib.rs#L435-L439
const DefaultStateVersion = V1

// Entry is a key-value pair used to build a trie
type Entry struct{ Key, Value []byte }

// Entries is a list of entry used to build a trie
type Entries []Entry

// String returns a string representation of trie version
func (v Version) String() string {
switch v {
case V0:
Expand All @@ -47,10 +56,12 @@ func (v Version) String() string {
}
}

// ShouldHashValue returns true if the value should be hashed based on trie version
func (v Version) ShouldHashValue(value []byte) bool {
return v == V1 && len(value) > V1MaxValueSize
}

// Root returns the root hash of the trie built using the given entries
func (v Version) Root(entries Entries) (common.Hash, error) {
t := NewEmptyTrie()

Expand All @@ -64,8 +75,6 @@ func (v Version) Root(entries Entries) (common.Hash, error) {
return t.Hash()
}

var ErrParseVersion = errors.New("parsing version failed")

// ParseVersion parses a state trie version string.
func ParseVersion[T string | uint32](v T) (version Version, err error) {
var s string
Expand Down

0 comments on commit a9a25e9

Please sign in to comment.