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 all 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
16 changes: 9 additions & 7 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/ibc"
ibctransfer "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
Expand Down Expand Up @@ -60,12 +61,13 @@ var (

// module account permissions
maccPerms = map[string][]string{
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: {supply.Burner},
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: {supply.Burner},
ibctransfer.GetModuleAccountName(): {supply.Minter, supply.Burner},
}
)

Expand Down Expand Up @@ -175,7 +177,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, app.SupplyKeeper)

// 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
61 changes: 61 additions & 0 deletions x/ibc/20-transfer/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package transfer

// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/keeper
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types

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

const (
DefaultPacketTimeout = keeper.DefaultPacketTimeout
DefaultCodespace = types.DefaultCodespace
CodeInvalidAddress = types.CodeInvalidAddress
CodeErrSendPacket = types.CodeErrSendPacket
CodeInvalidPacketData = types.CodeInvalidPacketData
CodeInvalidChannelOrder = types.CodeInvalidChannelOrder
CodeInvalidPort = types.CodeInvalidPort
CodeInvalidVersion = types.CodeInvalidVersion
AttributeKeyReceiver = types.AttributeKeyReceiver
SubModuleName = types.SubModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
QuerierRoute = types.QuerierRoute
BoundPortID = types.BoundPortID
)

var (
// functions aliases
NewKeeper = keeper.NewKeeper
RegisterCodec = types.RegisterCodec
ErrInvalidAddress = types.ErrInvalidAddress
ErrSendPacket = types.ErrSendPacket
ErrInvalidPacketData = types.ErrInvalidPacketData
ErrInvalidChannelOrder = types.ErrInvalidChannelOrder
ErrInvalidPort = types.ErrInvalidPort
ErrInvalidVersion = types.ErrInvalidVersion
GetEscrowAddress = types.GetEscrowAddress
GetDenomPrefix = types.GetDenomPrefix
GetModuleAccountName = types.GetModuleAccountName
NewMsgTransfer = types.NewMsgTransfer

// variable aliases
ModuleCdc = types.ModuleCdc
AttributeValueCategory = types.AttributeValueCategory
)

type (
Keeper = keeper.Keeper
BankKeeper = types.BankKeeper
ChannelKeeper = types.ChannelKeeper
ClientKeeper = types.ClientKeeper
ConnectionKeeper = types.ConnectionKeeper
SupplyKeeper = types.SupplyKeeper
MsgTransfer = types.MsgTransfer
PacketData = types.PacketData
PacketDataAlias = types.PacketDataAlias
)
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
}
17 changes: 17 additions & 0 deletions x/ibc/20-transfer/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package transfer

import (
"fmt"

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

// InitGenesis sets distribution information for genesis
func InitGenesis(ctx sdk.Context, keeper Keeper) {
// check if the module account exists
moduleAcc := keeper.GetTransferAccount(ctx)
if moduleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.GetModuleAccountName()))
}
}
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