Skip to content

Commit

Permalink
fix: rename airdrop to token-recover
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Nov 28, 2023
1 parent 4fe054d commit feee0f2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ import (
"github.com/bnb-chain/node/common/upgrade"
"github.com/bnb-chain/node/common/utils"
"github.com/bnb-chain/node/plugins/account"
"github.com/bnb-chain/node/plugins/airdrop"
"github.com/bnb-chain/node/plugins/bridge"
bTypes "github.com/bnb-chain/node/plugins/bridge/types"
"github.com/bnb-chain/node/plugins/dex"
"github.com/bnb-chain/node/plugins/dex/list"
"github.com/bnb-chain/node/plugins/dex/order"
dextypes "github.com/bnb-chain/node/plugins/dex/types"
tokenRecover "github.com/bnb-chain/node/plugins/recover"
"github.com/bnb-chain/node/plugins/tokens"
"github.com/bnb-chain/node/plugins/tokens/issue"
"github.com/bnb-chain/node/plugins/tokens/ownership"
Expand Down Expand Up @@ -1158,7 +1158,7 @@ func MakeCodec() *wire.Codec {
bridge.RegisterWire(cdc)
oracle.RegisterWire(cdc)
ibc.RegisterWire(cdc)
airdrop.RegisterWire(cdc)
tokenRecover.RegisterWire(cdc)
return cdc
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/bnbcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"github.com/bnb-chain/node/common"
"github.com/bnb-chain/node/common/types"
accountcmd "github.com/bnb-chain/node/plugins/account/client/cli"
airdropcmd "github.com/bnb-chain/node/plugins/airdrop/client/cli"
apiserv "github.com/bnb-chain/node/plugins/api"
bridgecmd "github.com/bnb-chain/node/plugins/bridge/client/cli"
dexcmd "github.com/bnb-chain/node/plugins/dex/client/cli"
recovercmd "github.com/bnb-chain/node/plugins/recover/client/cli"
tokencmd "github.com/bnb-chain/node/plugins/tokens/client/cli"
"github.com/bnb-chain/node/version"
)
Expand Down Expand Up @@ -100,7 +100,7 @@ func main() {
admin.AddCommands(rootCmd, cdc)
bridgecmd.AddCommands(rootCmd, cdc)
sidecmd.AddCommands(rootCmd, cdc)
airdropcmd.AddCommands(rootCmd, cdc)
recovercmd.AddCommands(rootCmd, cdc)

// prepare and add flags
executor := cli.PrepareMainCmd(rootCmd, "BC", app.DefaultCLIHome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

func AddCommands(cmd *cobra.Command, cdc *codec.Codec) {
airdropCmd := &cobra.Command{
Use: "airdrop",
Short: "airdrop commands",
Use: "recover",
Short: "recover commands",
}

airdropCmd.AddCommand(
client.PostCommands(
GetApprovalCmd(cdc),
SignTokenRecoverRequestCmd(cdc),
)...,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"

"github.com/bnb-chain/node/plugins/airdrop"
airdrop "github.com/bnb-chain/node/plugins/recover"
)

const (
Expand All @@ -31,10 +31,10 @@ const (
flagRecipient = "recipient"
)

func GetApprovalCmd(cdc *codec.Codec) *cobra.Command {
func SignTokenRecoverRequestCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "approval",
Short: "get airdrop approval sign data",
Use: "sign-token-recover-request",
Short: "get token recover request sign data",
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
Expand All @@ -44,8 +44,7 @@ func GetApprovalCmd(cdc *codec.Codec) *cobra.Command {
amount := viper.GetInt64(flagAmount)
tokenSymbol := viper.GetString(flagTokenSymbol)
recipient := viper.GetString(flagRecipient)

msg := airdrop.NewAirdropApprovalMsg(tokenSymbol, uint64(amount), strings.ToLower(common.HexToAddress(recipient).Hex()))
msg := airdrop.NewTokenRecoverRequestMsg(tokenSymbol, uint64(amount), strings.ToLower(common.HexToAddress(recipient).Hex()))

sdkErr := msg.ValidateBasic()
if sdkErr != nil {
Expand Down
34 changes: 17 additions & 17 deletions plugins/airdrop/msg.go → plugins/recover/msg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package airdrop
package recover

import (
"encoding/hex"
Expand All @@ -10,76 +10,76 @@ import (
)

const (
Route = "airdrop"
MsgType = "airdrop_approval"
Route = "recover"
MsgType = "request_token"
)

var _ sdk.Msg = AirdropApproval{}
var _ sdk.Msg = TokenRecoverRequest{}

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

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

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

type airDropApprovalSignData struct {
type tokenRecoverRequestSignData struct {
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 {
type TokenRecoverRequest struct {
TokenSymbol string `json:"token_symbol"`
Amount uint64 `json:"amount"`
Recipient string `json:"recipient"` // eth address
}

// GetInvolvedAddresses implements types.Msg.
func (msg AirdropApproval) GetInvolvedAddresses() []sdk.AccAddress {
func (msg TokenRecoverRequest) GetInvolvedAddresses() []sdk.AccAddress {
return msg.GetSigners()
}

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

// GetSigners implements types.Msg.
func (m AirdropApproval) GetSigners() []sdk.AccAddress {
func (m TokenRecoverRequest) GetSigners() []sdk.AccAddress {
// This is not a real on-chain transaction
// We can get signer from the public key.
return []sdk.AccAddress{}
}

// Route implements types.Msg.
func (AirdropApproval) Route() string {
func (TokenRecoverRequest) Route() string {
return Route
}

// Type implements types.Msg.
func (AirdropApproval) Type() string {
func (TokenRecoverRequest) Type() string {
return MsgType
}

// ValidateBasic implements types.Msg.
func (msg AirdropApproval) ValidateBasic() sdk.Error {
func (msg TokenRecoverRequest) ValidateBasic() sdk.Error {
if msg.TokenSymbol == "" {
return sdk.ErrUnknownRequest("Invalid token symbol")
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/airdrop/wire.go → plugins/recover/wire.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package airdrop
package recover

import (
"github.com/bnb-chain/node/wire"
)

// Register concrete types on wire codec
func RegisterWire(cdc *wire.Codec) {
cdc.RegisterConcrete(AirdropApproval{}, "airdrop/AirdropApproval", nil)
cdc.RegisterConcrete(TokenRecoverRequest{}, "recover/TokenRecoverRequest", nil)
}

0 comments on commit feee0f2

Please sign in to comment.