ics23.gno
0.76 Kb · 37 lines
1package testing
2
3import (
4 "encoding/hex"
5
6 "gno.land/p/aib/ics23"
7)
8
9func NewExistenceProof(spec *ics23.ProofSpec, key []byte, value, leaf string, paths [][]string) *ics23.ExistenceProof {
10 ep := &ics23.ExistenceProof{
11 Key: key,
12 Value: hexDec(value),
13 Leaf: &ics23.LeafOp{
14 Hash: spec.LeafSpec.Hash,
15 PrehashKey: spec.LeafSpec.PrehashKey,
16 PrehashValue: spec.LeafSpec.PrehashValue,
17 Length: spec.LeafSpec.Length,
18 Prefix: hexDec(leaf),
19 },
20 }
21 for i, _ := range paths {
22 ep.Path = append(ep.Path, &ics23.InnerOp{
23 Hash: spec.InnerSpec.Hash,
24 Prefix: hexDec(paths[i][0]),
25 Suffix: hexDec(paths[i][1]),
26 })
27 }
28 return ep
29}
30
31func hexDec(s string) []byte {
32 b, err := hex.DecodeString(s)
33 if err != nil {
34 panic(err)
35 }
36 return b
37}