@@ -15,6 +15,7 @@ import (
15
15
16
16
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
17
17
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
18
+ hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2"
18
19
"github.com/cosmos/ibc-go/v9/modules/core/exported"
19
20
)
20
21
@@ -61,3 +62,103 @@ func (k *Keeper) GetCounterparty(ctx context.Context, clientID string) (types.Co
61
62
k .cdc .MustUnmarshal (bz , & counterparty )
62
63
return counterparty , true
63
64
}
65
+
66
+ // GetPacketReceipt returns the packet receipt from the packet receipt path based on the sourceID and sequence.
67
+ func (k * Keeper ) GetPacketReceipt (ctx context.Context , sourceID string , sequence uint64 ) (string , bool ) {
68
+ store := k .storeService .OpenKVStore (ctx )
69
+ bigEndianBz := sdk .Uint64ToBigEndian (sequence )
70
+ bz , err := store .Get (hostv2 .PacketReceiptKey (sourceID , bigEndianBz ))
71
+ if err != nil {
72
+ panic (err )
73
+ }
74
+ if len (bz ) == 0 {
75
+ return "" , false
76
+ }
77
+ return string (bz ), true
78
+ }
79
+
80
+ // SetPacketReceipt writes the packet receipt under the receipt path
81
+ // This is a public path that is standardized by the IBC V2 specification.
82
+ func (k * Keeper ) SetPacketReceipt (ctx context.Context , sourceID string , sequence uint64 ) {
83
+ store := k .storeService .OpenKVStore (ctx )
84
+ bigEndianBz := sdk .Uint64ToBigEndian (sequence )
85
+ if err := store .Set (hostv2 .PacketReceiptKey (sourceID , bigEndianBz ), []byte {byte (1 )}); err != nil {
86
+ panic (err )
87
+ }
88
+ }
89
+
90
+ // SetPacketAcknowledgement writes the acknowledgement hash under the acknowledgement path
91
+ // This is a public path that is standardized by the IBC V2 specification.
92
+ func (k * Keeper ) SetPacketAcknowledgement (ctx context.Context , sourceID string , sequence uint64 , ackHash []byte ) {
93
+ store := k .storeService .OpenKVStore (ctx )
94
+ bigEndianBz := sdk .Uint64ToBigEndian (sequence )
95
+ if err := store .Set (hostv2 .PacketAcknowledgementKey (sourceID , bigEndianBz ), ackHash ); err != nil {
96
+ panic (err )
97
+ }
98
+ }
99
+
100
+ // HasPacketAcknowledgement check if the packet ack hash is already on the store.
101
+ func (k * Keeper ) HasPacketAcknowledgement (ctx context.Context , sourceID string , sequence uint64 ) bool {
102
+ store := k .storeService .OpenKVStore (ctx )
103
+ bigEndianBz := sdk .Uint64ToBigEndian (sequence )
104
+ found , err := store .Has (hostv2 .PacketAcknowledgementKey (sourceID , bigEndianBz ))
105
+ if err != nil {
106
+ panic (err )
107
+ }
108
+
109
+ return found
110
+ }
111
+
112
+ // GetPacketCommitment returns the packet commitment hash under the commitment path.
113
+ func (k * Keeper ) GetPacketCommitment (ctx context.Context , sourceID string , sequence uint64 ) (string , bool ) {
114
+ store := k .storeService .OpenKVStore (ctx )
115
+ bigEndianBz := sdk .Uint64ToBigEndian (sequence )
116
+ bz , err := store .Get (hostv2 .PacketCommitmentKey (sourceID , bigEndianBz ))
117
+ if err != nil {
118
+ panic (err )
119
+ }
120
+ if len (bz ) == 0 {
121
+ return "" , false
122
+ }
123
+ return string (bz ), true
124
+ }
125
+
126
+ // SetPacketCommitment writes the commitment hash under the commitment path.
127
+ func (k * Keeper ) SetPacketCommitment (ctx context.Context , sourceID string , sequence uint64 , commitment []byte ) {
128
+ store := k .storeService .OpenKVStore (ctx )
129
+ bigEndianBz := sdk .Uint64ToBigEndian (sequence )
130
+ if err := store .Set (hostv2 .PacketCommitmentKey (sourceID , bigEndianBz ), commitment ); err != nil {
131
+ panic (err )
132
+ }
133
+ }
134
+
135
+ // DeletePacketCommitment deletes the packet commitment hash under the commitment path.
136
+ func (k * Keeper ) DeletePacketCommitment (ctx context.Context , sourceID string , sequence uint64 ) {
137
+ store := k .storeService .OpenKVStore (ctx )
138
+ bigEndianBz := sdk .Uint64ToBigEndian (sequence )
139
+ if err := store .Delete (hostv2 .PacketCommitmentKey (sourceID , bigEndianBz )); err != nil {
140
+ panic (err )
141
+ }
142
+ }
143
+
144
+ // GetNextSequenceSend returns the next send sequence from the sequence path
145
+ func (k * Keeper ) GetNextSequenceSend (ctx context.Context , sourceID string ) (uint64 , bool ) {
146
+ store := k .storeService .OpenKVStore (ctx )
147
+ bz , err := store .Get (hostv2 .NextSequenceSendKey (sourceID ))
148
+ if err != nil {
149
+ panic (err )
150
+ }
151
+ if len (bz ) == 0 {
152
+ return 0 , false
153
+ }
154
+ return sdk .BigEndianToUint64 (bz ), true
155
+ }
156
+
157
+ // SetNextSequenceSend writes the next send sequence under the sequence path
158
+ func (k * Keeper ) SetNextSequenceSend (ctx context.Context , sourceID string , sequence uint64 ) {
159
+ store := k .storeService .OpenKVStore (ctx )
160
+ bigEndianBz := sdk .Uint64ToBigEndian (sequence )
161
+ if err := store .Set (hostv2 .NextSequenceSendKey (sourceID ), bigEndianBz ); err != nil {
162
+ panic (err )
163
+ }
164
+ }
0 commit comments