Search Apps Documentation Source Content File Folder Download Copy Actions Download

zz_acknowledgement_example_filetest.gno

3.55 Kb · 96 lines
 1// PKGPATH: gno.land/r/aib/main
 2package main
 3
 4import (
 5	"time"
 6
 7	"gno.land/p/aib/ibc/types"
 8	"gno.land/p/aib/ics23"
 9	"gno.land/r/aib/ibc/core"
10)
11
12func main(cur realm) {
13	// Acknowledge the packet
14	specs := ics23.IavlSpec()
15	ackPacket := types.MsgAcknowledgement{
16		Packet: types.Packet{
17			Sequence:          42,                        // XXX update
18			SourceClient:      "clientID",                // XXX update
19			DestinationClient: "counterPartyID",          // XXX update
20			TimeoutTimestamp:  uint64(time.Now().Unix()), // XXX update: must be the same as the timestamp of the send packet
21			Payloads: []types.Payload{{
22				SourcePort:      "appID", // XXX update
23				DestinationPort: "appID", //XXX update
24				Encoding:        "application/x-protobuf",
25				Value:           []byte{}, // XXX update
26				Version:         "v1",     // XXX update: version of app (transfer uses v1)
27			}},
28		},
29		Acknowledgement: types.Acknowledgement{
30			// XXX update: this is the response of the app sent in the RecvPacket
31			// response of the counterparty client.
32			AppAcknowledgements: [][]byte{[]byte(`{"response":{"result":"BQ=="}}`)},
33		},
34		// Write the proof of acknowledgement written during the RecvPacket of the
35		// counterparty client.
36		// NOTE proof generated by ./cmd/gen-proof MERKLE_PREFIX CLIENT_ID acknowledgement APP_ACK
37		ProofAcked: []ics23.CommitmentProof{
38
39			// iavl proof
40			ics23.CommitmentProof_Exist{
41				Exist: &ics23.ExistenceProof{
42					Key:   []byte("\x70\x72\x65\x66\x69\x78\x32\x30\x37\x2d\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2d\x34\x32\x03\x00\x00\x00\x00\x00\x00\x00\x01"),
43					Value: []byte("\x21\x29\x3f\x61\xea\x42\x91\xdc\x31\x88\xaa\x8b\xe6\xde\x66\xeb\x0e\xe0\x5b\x10\x03\x25\xb0\x31\x3b\x25\x84\xf2\xc0\x96\x11\xaf"),
44					Leaf: &ics23.LeafOp{
45						Hash:         specs.LeafSpec.Hash,
46						PrehashKey:   specs.LeafSpec.PrehashKey,
47						PrehashValue: specs.LeafSpec.PrehashValue,
48						Length:       specs.LeafSpec.Length,
49						Prefix:       []byte("\x00\x02\x02"),
50					},
51					Path: []*ics23.InnerOp{
52						{
53							Hash:   specs.InnerSpec.Hash,
54							Prefix: []byte("\x02\x04\x02\x20\x35\xf8\xea\x80\x53\x90\xe0\x84\x85\x4f\x39\x9b\x42\xcc\xde\xae\xa3\x3a\x1d\xed\xc1\x15\x63\x8a\xc4\x8d\x06\x00\x63\x7d\xba\x1f\x20"),
55							Suffix: []byte(""),
56						},
57						{
58							Hash:   specs.InnerSpec.Hash,
59							Prefix: []byte("\x04\x08\x02\x20"),
60							Suffix: []byte("\x20\x79\x8e\x2c\xaa\x96\xfd\xfb\xa3\x76\xdd\xeb\x47\x99\x99\x54\xd2\xf4\x7e\x65\x16\x22\x64\xb0\x53\x6a\xb5\xdf\xf7\xfc\x0a\x2e\x07"),
61						},
62						{
63							Hash:   specs.InnerSpec.Hash,
64							Prefix: []byte("\x06\x0c\x02\x20\x9a\xf3\x7d\xd5\x95\xa0\x19\x08\x03\xb5\xe0\x5a\xae\xf4\x2a\xe3\xfa\xd4\x99\xe4\xfb\xe3\x7f\x7c\xd3\x1c\xad\xff\x22\xa9\xee\x74\x20"),
65							Suffix: []byte(""),
66						},
67					},
68				},
69			},
70
71			// rootmulti proof
72			ics23.CommitmentProof_Exist{
73				Exist: &ics23.ExistenceProof{
74					Key:   []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"),
75					Value: []byte("\x54\x67\x6b\x16\xcf\xa5\x41\x3e\x30\x2b\x0d\xff\x76\x7d\x1d\xa8\x11\x44\x0b\x38\x36\x08\xc7\xd8\xab\x6a\x1b\x36\x47\x82\x1f\x1d"),
76					Leaf: &ics23.LeafOp{
77						Hash:         specs.LeafSpec.Hash,
78						PrehashKey:   specs.LeafSpec.PrehashKey,
79						PrehashValue: specs.LeafSpec.PrehashValue,
80						Length:       specs.LeafSpec.Length,
81						Prefix:       []byte("\x00"),
82					},
83					Path: []*ics23.InnerOp{},
84				},
85			},
86		},
87		ProofHeight: types.NewHeight(1, 2000), // XXX update
88	}
89
90	res := core.Acknowledgement(cross(cur), ackPacket)
91
92	println(res)
93}
94
95// Error:
96// invalid Payload #0: payload value cannot be empty