-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move ics20 code to 20-transfer * clean code * fix compiling error * add transfer module * address ICS20 comments from review * add routing callbacks * clean code * add missing err return * modify err type * modify err type * add supply handling * modify proof type * add comments for msg and packet data * add timeout supply handling * modify module account name * use supply keeper for burn and mint coins * restructure keeper * update alias and module.go * golangci linter * add ics20 handler to IBC handler * update callbacks
- Loading branch information
1 parent
2a6a77a
commit f3120bf
Showing
34 changed files
with
1,100 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()} | ||
} |
Oops, something went wrong.