-
Notifications
You must be signed in to change notification settings - Fork 41
/
info.go
69 lines (55 loc) · 1.37 KB
/
info.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
65
66
67
68
69
package commands
import (
"fmt"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/bnb-chain/node/common"
"github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/wire"
)
func getTokenInfoCmd(cmdr Commander) *cobra.Command {
cmd := &cobra.Command{
Use: "info <symbol>",
Short: "Query token/mini-token info",
RunE: cmdr.runGetToken,
}
cmd.Flags().StringP(flagSymbol, "s", "", "symbol of the token")
return cmd
}
func (c Commander) runGetToken(cmd *cobra.Command, args []string) error {
ctx := context.NewCLIContext().WithCodec(c.Cdc)
symbol := viper.GetString(flagSymbol)
if len(symbol) == 0 {
return errors.New("you must provide the symbol")
}
var key []byte
if types.IsMiniTokenSymbol(symbol) {
key = calcMiniTokenKey(strings.ToUpper(symbol))
} else {
key = []byte(strings.ToUpper(symbol))
}
res, err := ctx.QueryStore(key, common.TokenStoreName)
if err != nil {
return err
}
if len(res) == 0 {
fmt.Printf("No such token(%v) exists\n", symbol)
return nil
}
// decode the value
var token types.IToken
err = c.Cdc.UnmarshalBinaryBare(res, &token)
if err != nil {
return err
}
// print out the toke info
output, err := wire.MarshalJSONIndent(c.Cdc, &token)
if err != nil {
return err
}
fmt.Println(string(output))
return nil
}