-
Notifications
You must be signed in to change notification settings - Fork 4
/
send_msgs.go
47 lines (39 loc) · 1.61 KB
/
send_msgs.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
47
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
"time"
)
func (k Keeper) SendTx(ctx sdk.Context, controllerId, connectionId string, msgs []sdk.Msg, timeout uint64) error {
portID, err := icatypes.NewControllerPortID(controllerId)
if err != nil {
return err
}
channelID, found := k.IcaControllerKeeper.GetActiveChannelID(ctx, connectionId, portID)
if !found {
return sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID)
}
chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID))
if !found {
return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability")
}
data, err := icatypes.SerializeCosmosTx(k.cdc, msgs)
if err != nil {
return err
}
packetData := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: data,
}
// timeoutTimestamp set to max value with the unsigned bit shifted to satisfy hermes timestamp conversion
// it is the responsibility of the auth module developer to ensure an appropriate timeout timestamp
timeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + timeout*uint64(time.Minute.Nanoseconds())
_, err = k.IcaControllerKeeper.SendTx(ctx, chanCap, connectionId, portID, packetData, timeoutTimestamp)
if err != nil {
return err
}
return nil
}