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

keys.gno

1.16 Kb · 49 lines
 1package cometbls
 2
 3import (
 4	"strconv"
 5	"strings"
 6
 7	"gno.land/p/onbloc/ibc/union/types"
 8)
 9
10const (
11	ModuleName = "cometbls"
12
13	ClientType = ModuleName
14)
15
16var moduleKey = []byte("wasm")
17
18func makeStoreKey(addr types.H256, key []byte) []byte {
19	out := make([]byte, 0, 1+32+1+len(key))
20	out = append(out, 0x03)
21	out = append(out, addr[:]...)
22	out = append(out, 0x00)
23	out = append(out, key...)
24
25	return out
26}
27
28// heightKey renders a height as a fixed-width, lexicographically sortable bptree
29// key. CometBLS uses a single revision, so the revision-height ordering matches
30// numeric ordering.
31func heightKey(height types.Height) string {
32	return zeroPadDecimalUint64(height.RevisionNumber) + "-" + zeroPadDecimalUint64(height.RevisionHeight)
33}
34
35// zeroPadDecimalUint64 converts a uint64 number into a zero-padded 20-character string.
36//
37// num (uint64): The number to encode.
38//
39// Returns:
40// A zero-padded string representation of the number.
41func zeroPadDecimalUint64(num uint64) string {
42	// Convert the value to a decimal string.
43	s := strconv.FormatUint(num, 10)
44
45	// Zero-pad to a total length of 20 characters.
46	zerosNeeded := 20 - len(s)
47
48	return strings.Repeat("0", zerosNeeded) + s
49}