-
Notifications
You must be signed in to change notification settings - Fork 167
/
ibc_module.go
46 lines (39 loc) · 1.3 KB
/
ibc_module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ibctransfer
import (
sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfer "github.com/cosmos/ibc-go/v5/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported"
"github.com/umee-network/umee/v3/x/ibctransfer/keeper"
)
// IBCModule embeds the ICS-20 transfer IBCModule where we only override specific
// methods.
type IBCModule struct {
// embed the ICS-20 transfer's AppModule
ibctransfer.IBCModule
keeper keeper.Keeper
}
func NewIBCModule(am ibctransfer.IBCModule, k keeper.Keeper) IBCModule {
return IBCModule{
IBCModule: am,
keeper: k,
}
}
// OnRecvPacket delegates the OnRecvPacket call to the embedded ICS-20 transfer
// IBCModule and updates metadata if successful.
func (am IBCModule) OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
) ibcexported.Acknowledgement {
ack := am.IBCModule.OnRecvPacket(ctx, packet, relayer)
if ack.Success() {
var data ibctransfertypes.FungibleTokenPacketData
if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err == nil {
// track metadata
am.keeper.PostOnRecvPacket(ctx, packet, data)
}
}
return ack
}