-
Notifications
You must be signed in to change notification settings - Fork 40
/
transfer_ownership.go
60 lines (47 loc) · 1.38 KB
/
transfer_ownership.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package commands
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/bnb-chain/node/common/client"
"github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/plugins/tokens/ownership"
)
const flagNewOwner = "new-owner"
func transferOwnershipCmd(cmdr Commander) *cobra.Command {
cmd := &cobra.Command{
Use: "transfer-ownership",
Short: "transfer the ownership of token",
RunE: cmdr.transferOwnership,
}
cmd.Flags().StringP(flagSymbol, "s", "", "symbol of the token to be transferred owner")
cmd.Flags().StringP(flagNewOwner, "", "", "new owner of the token")
return cmd
}
func (c Commander) transferOwnership(cmd *cobra.Command, args []string) error {
cliCtx, txBldr := client.PrepareCtx(c.Cdc)
from, err := cliCtx.GetFromAddress()
if err != nil {
return err
}
symbol := viper.GetString(flagSymbol)
if !types.IsValidMiniTokenSymbol(symbol) {
err = types.ValidateTokenSymbol(symbol)
if err != nil {
return err
}
}
symbol = strings.ToUpper(symbol)
newOwnerStr := viper.GetString(flagNewOwner)
if len(newOwnerStr) == 0 {
return fmt.Errorf("newOwner can not be empty")
}
newOwner, err := sdk.AccAddressFromBech32(newOwnerStr)
if err != nil {
return err
}
msg := ownership.NewTransferOwnershipMsg(from, symbol, newOwner)
return client.SendOrPrintTx(cliCtx, txBldr, msg)
}