Skip to content

Commit

Permalink
fix: remove tokenIndex for airdrop approval
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Nov 16, 2023
1 parent 82ea9a8 commit a3e37eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
5 changes: 1 addition & 4 deletions plugins/airdrop/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

const (
flagAmount = "amount"
flagTokenIndex = "token-index"
flagTokenSymbol = "token-symbol"
flagRecipient = "recipient"
)
Expand All @@ -42,10 +41,9 @@ func GetApprovalCmd(cdc *codec.Codec) *cobra.Command {
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))

amount := viper.GetInt64(flagAmount)
tokenIndex := viper.GetInt64(flagTokenIndex)
tokenSymbol := viper.GetString(flagTokenSymbol)
recipient := viper.GetString(flagRecipient)
msg := airdrop.NewAirdropApprovalMsg(uint64(tokenIndex), tokenSymbol, uint64(amount), common.HexToAddress(recipient).Hex())
msg := airdrop.NewAirdropApprovalMsg(tokenSymbol, uint64(amount), common.HexToAddress(recipient).Hex())

sdkErr := msg.ValidateBasic()
if sdkErr != nil {
Expand All @@ -55,7 +53,6 @@ func GetApprovalCmd(cdc *codec.Codec) *cobra.Command {
},
}

cmd.Flags().Int64(flagTokenIndex, 0, "owner token index")
cmd.Flags().String(flagTokenSymbol, "", "owner token symbol")
cmd.Flags().Int64(flagAmount, 0, "amount of token")
cmd.Flags().String(flagRecipient, "", "bsc recipient address")
Expand Down
10 changes: 3 additions & 7 deletions plugins/airdrop/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,32 @@ const (

var _ sdk.Msg = AirdropApproval{}

func NewAirdropApprovalMsg(tokenIndex uint64, tokenSymbol string, amount uint64, recipient string) AirdropApproval {
func NewAirdropApprovalMsg(tokenSymbol string, amount uint64, recipient string) AirdropApproval {
return AirdropApproval{
TokenIndex: tokenIndex,
TokenSymbol: tokenSymbol,
Amount: amount,
Recipient: recipient,
}
}

func newAirDropApprovalSignData(tokenIndex uint64, tokenSymbol string, amount uint64, recipient string) airDropApprovalSignData {
func newAirDropApprovalSignData(tokenSymbol string, amount uint64, recipient string) airDropApprovalSignData {
var tokenSymbolBytes [32]byte
copy(tokenSymbolBytes[:], []byte(tokenSymbol))

return airDropApprovalSignData{
TokenIndex: hex.EncodeToString(big.NewInt(int64(tokenIndex)).FillBytes(make([]byte, 32))),
TokenSymbol: hex.EncodeToString(tokenSymbolBytes[:]),
Amount: hex.EncodeToString(big.NewInt(int64(amount)).FillBytes(make([]byte, 32))),
Recipient: recipient,
}
}

type airDropApprovalSignData struct {
TokenIndex string `json:"token_index"` // hex string(32 bytes)
TokenSymbol string `json:"token_symbol"` // hex string(32 bytes)
Amount string `json:"amount"` // hex string(32 bytes)
Recipient string `json:"recipient"` // eth address(20 bytes)
}

type AirdropApproval struct {
TokenIndex uint64 `json:"token_index"`
TokenSymbol string `json:"token_symbol"`
Amount uint64 `json:"amount"`
Recipient string `json:"recipient"` // eth address
Expand All @@ -58,7 +54,7 @@ func (msg AirdropApproval) GetInvolvedAddresses() []sdk.AccAddress {

// GetSignBytes implements types.Msg.
func (msg AirdropApproval) GetSignBytes() []byte {
b, err := json.Marshal(newAirDropApprovalSignData(msg.TokenIndex, msg.TokenSymbol, msg.Amount, msg.Recipient))
b, err := json.Marshal(newAirDropApprovalSignData(msg.TokenSymbol, msg.Amount, msg.Recipient))
if err != nil {
panic(err)
}
Expand Down

0 comments on commit a3e37eb

Please sign in to comment.