cli: hardcode NEO and GAS token info
Don't make extra network queries for already known contracts.
This commit is contained in:
parent
8407031605
commit
f66199c99f
2 changed files with 19 additions and 0 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/cli/flags"
|
||||
"github.com/nspcc-dev/neo-go/cli/options"
|
||||
|
@ -16,6 +17,11 @@ import (
|
|||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
neoToken = wallet.NewToken(client.NeoContractHash, "NEO", "neo", 0)
|
||||
gasToken = wallet.NewToken(client.GasContractHash, "GAS", "gas", 8)
|
||||
)
|
||||
|
||||
func newNEP5Commands() []cli.Command {
|
||||
balanceFlags := []cli.Flag{
|
||||
walletPathFlag,
|
||||
|
@ -163,6 +169,12 @@ func getNEP5Balance(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
func getMatchingToken(w *wallet.Wallet, name string) (*wallet.Token, error) {
|
||||
switch strings.ToLower(name) {
|
||||
case "neo":
|
||||
return neoToken, nil
|
||||
case "gas":
|
||||
return gasToken, nil
|
||||
}
|
||||
return getMatchingTokenAux(func(i int) *wallet.Token {
|
||||
return w.Extra.Tokens[i]
|
||||
}, len(w.Extra.Tokens), name)
|
||||
|
|
|
@ -16,6 +16,13 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
)
|
||||
|
||||
var (
|
||||
// NeoContractHash is a hash of the NEO native contract.
|
||||
NeoContractHash, _ = util.Uint160DecodeStringBE("3b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c")
|
||||
// GasContractHash is a hash of the GAS native contract.
|
||||
GasContractHash, _ = util.Uint160DecodeStringBE("897720d8cd76f4f00abfa37c0edd889c208fde9b")
|
||||
)
|
||||
|
||||
// NEP5Decimals invokes `decimals` NEP5 method on a specified contract.
|
||||
func (c *Client) NEP5Decimals(tokenHash util.Uint160) (int64, error) {
|
||||
result, err := c.InvokeFunction(tokenHash.StringLE(), "decimals", []smartcontract.Parameter{}, nil)
|
||||
|
|
Loading…
Reference in a new issue