-
Notifications
You must be signed in to change notification settings - Fork 40
/
issue_tiny.go
64 lines (53 loc) · 1.67 KB
/
issue_tiny.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
61
62
63
64
package commands
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/bnb-chain/node/common/client"
"github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/plugins/tokens/issue"
)
func issueTinyTokenCmd(cmdr Commander) *cobra.Command {
cmd := &cobra.Command{
Use: "issue-tiny",
Short: "issue a new tiny-token",
RunE: cmdr.issueTinyToken,
}
cmd.Flags().String(flagTokenName, "", "name of the new token")
cmd.Flags().StringP(flagSymbol, "s", "", "symbol of the new token")
cmd.Flags().Int64P(flagTotalSupply, "n", 0, "total supply of the new token")
cmd.Flags().Bool(flagMintable, false, "whether the token can be minted")
cmd.Flags().String(flagTokenUri, "", "uri of the token information")
_ = cmd.MarkFlagRequired(flagTotalSupply)
return cmd
}
func (c Commander) issueTinyToken(cmd *cobra.Command, args []string) error {
cliCtx, txBldr := client.PrepareCtx(c.Cdc)
from, err := cliCtx.GetFromAddress()
if err != nil {
return err
}
name := viper.GetString(flagTokenName)
if len(name) == 0 {
return errors.New("you must provide the name of the token")
}
symbol := viper.GetString(flagSymbol)
err = types.ValidateIssueMiniSymbol(symbol)
if err != nil {
return err
}
supply := viper.GetInt64(flagTotalSupply)
err = checkMiniSupplyAmount(supply, int8(types.TinyRangeType))
if err != nil {
return err
}
mintable := viper.GetBool(flagMintable)
tokenURI := viper.GetString(flagTokenUri)
err = validateTokenURI(tokenURI)
if err != nil {
return err
}
// build message
msg := issue.NewIssueTinyMsg(from, name, symbol, supply, mintable, tokenURI)
return client.SendOrPrintTx(cliCtx, txBldr, msg)
}