Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICS 20 implementation #5250

Merged
merged 24 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func NewSimApp(
staking.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

app.IBCKeeper = ibc.NewKeeper(app.cdc, keys[ibc.StoreKey], ibc.DefaultCodespace)
app.IBCKeeper = ibc.NewKeeper(app.cdc, keys[ibc.StoreKey], ibc.DefaultCodespace, app.BankKeeper)

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
Expand Down
1 change: 1 addition & 0 deletions x/ibc/04-channel/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var SubModuleCdc *codec.Codec

func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*exported.PacketI)(nil), nil)
cdc.RegisterConcrete(Packet{}, "ibc/channel/Packet", nil)
cdc.RegisterConcrete(OpaquePacket{}, "ibc/channel/OpaquePacket", nil)

cdc.RegisterConcrete(MsgChannelOpenInit{}, "ibc/channel/MsgChannelOpenInit", nil)
Expand Down
1 change: 0 additions & 1 deletion x/ibc/04-channel/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const (
AttributeKeyReceiverPort = "receiver_port"
AttributeKeyChannelID = "channel_id"
AttributeKeySequence = "sequence"
AttributeKeyPacket = "packet"
)

// IBC channel events vars
Expand Down
26 changes: 26 additions & 0 deletions x/ibc/20-transfer/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package transfer

import (
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
)

type (
MsgTransfer = types.MsgTransfer
TransferPacketData = types.TransferPacketData
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
Keeper = keeper.Keeper
)

const (
SubModuleName = types.SubModuleName
StoreKey = types.StoreKey
QuerierRoute = types.QuerierRoute
RouterKey = types.RouterKey
)

var (
RegisterCdc = types.RegisterCodec

NewKeeper = keeper.NewKeeper
NewMsgTransfer = types.NewMsgTransfer
)
70 changes: 70 additions & 0 deletions x/ibc/20-transfer/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cli

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
)

// IBC transfer flags
var (
FlagSource = "source"
)

// GetTxCmd returns the transaction commands for IBC fungible token transfer
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
txCmd := &cobra.Command{
Use: "transfer",
Short: "IBC fungible token transfer transaction subcommands",
}
txCmd.AddCommand(
GetTransferTxCmd(cdc),
)

return txCmd
}

// GetTransferTxCmd returns the command to create a NewMsgTransfer transaction
func GetTransferTxCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "transfer [src-port] [src-channel] [receiver] [amount]",
Short: "Transfer fungible token through IBC",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
ctx := context.NewCLIContext().WithCodec(cdc).WithBroadcastMode(flags.BroadcastBlock)

sender := ctx.GetFromAddress()
srcPort := args[0]
srcChannel := args[1]
receiver, err := sdk.AccAddressFromBech32(args[2])
if err != nil {
return err
}

// parse coin trying to be sent
coins, err := sdk.ParseCoins(args[3])
if err != nil {
return err
}

source := viper.GetBool(FlagSource)

msg := types.NewMsgTransfer(srcPort, srcChannel, coins, sender, receiver, source)
if err := msg.ValidateBasic(); err != nil {
return err
}

return utils.GenerateOrBroadcastMsgs(ctx, txBldr, []sdk.Msg{msg})
},
}
cmd.Flags().Bool(FlagSource, false, "Pass flag for sending token from the source chain")
return cmd
}
24 changes: 24 additions & 0 deletions x/ibc/20-transfer/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package transfer

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
)

// HandleMsgTransfer defines the sdk.Handler for MsgTransfer
func HandleMsgTransfer(ctx sdk.Context, k Keeper, msg MsgTransfer) (res sdk.Result) {
err := k.SendTransfer(ctx, msg.SourcePort, msg.SourceChannel, msg.Amount, msg.Sender, msg.Receiver, msg.Source)
if err != nil {
return sdk.ResultFromError(err)
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender.String()),
sdk.NewAttribute(types.AttributeKeyReceiver, msg.Receiver.String()),
))

return sdk.Result{Events: ctx.EventManager().Events()}
}
Loading