From a8a6c8c13d349d672065304935cf85972c9a73f1 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 22 Jul 2021 19:52:17 +0300 Subject: [PATCH] query: display zeroes for unknown addresses This: Voted: null Amount : 0 Block: 0 is better than this: failed to convert account state from stackitem: invalid stackitem length --- cli/query/query.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/query/query.go b/cli/query/query.go index 17585d0a7..732719897 100644 --- a/cli/query/query.go +++ b/cli/query/query.go @@ -20,6 +20,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/urfave/cli" ) @@ -238,9 +239,11 @@ func queryVoter(ctx *cli.Context) error { return cli.NewExitError("result stack is empty", 1) } st := new(state.NEOBalance) - err = st.FromStackItem(res.Stack[0]) - if err != nil { - return cli.NewExitError(fmt.Errorf("failed to convert account state from stackitem: %w", err), 1) + if _, ok := res.Stack[0].(stackitem.Null); !ok { + err = st.FromStackItem(res.Stack[0]) + if err != nil { + return cli.NewExitError(fmt.Errorf("failed to convert account state from stackitem: %w", err), 1) + } } dec, err := c.NEP17Decimals(neoHash) if err != nil {