From 29d6ababae271f6dbe30b515d1f7310058e47f02 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 27 Aug 2020 14:57:13 +0300 Subject: [PATCH] [#14] Adopt stackitems in morph requests Signed-off-by: Alex Vanin --- pkg/morph/client/balance/balanceOf.go | 2 +- pkg/morph/client/balance/decimals.go | 2 +- pkg/morph/client/client.go | 7 ++++--- pkg/morph/client/container/eacl.go | 2 +- pkg/morph/client/container/get.go | 2 +- pkg/morph/client/container/list.go | 4 ++-- pkg/morph/client/netmap/ir_list.go | 6 +++--- pkg/morph/client/netmap/netmap.go | 16 ++++++++-------- pkg/morph/client/static.go | 4 ++-- 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/pkg/morph/client/balance/balanceOf.go b/pkg/morph/client/balance/balanceOf.go index 2a6e16c2b..028fca0f9 100644 --- a/pkg/morph/client/balance/balanceOf.go +++ b/pkg/morph/client/balance/balanceOf.go @@ -41,7 +41,7 @@ func (c *Client) BalanceOf(args GetBalanceOfArgs) (*GetBalanceOfValues, error) { return nil, errors.Errorf("unexpected stack item count (%s): %d", c.balanceOfMethod, ln) } - amount, err := client.IntFromStackParameter(prms[0]) + amount, err := client.IntFromStackItem(prms[0]) if err != nil { return nil, errors.Wrapf(err, "could not get integer stack item from stack item (%s)", c.balanceOfMethod) } diff --git a/pkg/morph/client/balance/decimals.go b/pkg/morph/client/balance/decimals.go index 12169d85a..fb65b76a5 100644 --- a/pkg/morph/client/balance/decimals.go +++ b/pkg/morph/client/balance/decimals.go @@ -33,7 +33,7 @@ func (c *Client) Decimals(args DecimalsArgs) (*DecimalsValues, error) { return nil, errors.Errorf("unexpected stack item count (%s): %d", c.decimalsMethod, ln) } - decimals, err := client.IntFromStackParameter(prms[0]) + decimals, err := client.IntFromStackItem(prms[0]) if err != nil { return nil, errors.Wrapf(err, "could not get integer stack item from stack item (%s)", c.decimalsMethod) } diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 308285e1b..0370cbbe6 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/rpc/client" sc "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/pkg/errors" @@ -55,7 +56,7 @@ func (c *Client) Invoke(contract util.Uint160, fee util.Fixed8, method string, a params = append(params, param) } - cosigner := []transaction.Cosigner{ + cosigner := []transaction.Signer{ { Account: c.acc.PrivateKey().PublicKey().GetScriptHash(), Scopes: transaction.Global, @@ -92,7 +93,7 @@ func (c *Client) Invoke(contract util.Uint160, fee util.Fixed8, method string, a // TestInvoke invokes contract method locally in neo-go node. This method should // be used to read data from smart-contract. -func (c *Client) TestInvoke(contract util.Uint160, method string, args ...interface{}) ([]sc.Parameter, error) { +func (c *Client) TestInvoke(contract util.Uint160, method string, args ...interface{}) ([]stackitem.Item, error) { var params = make([]sc.Parameter, 0, len(args)) for i := range args { @@ -104,7 +105,7 @@ func (c *Client) TestInvoke(contract util.Uint160, method string, args ...interf params = append(params, p) } - cosigner := []transaction.Cosigner{ + cosigner := []transaction.Signer{ { Account: c.acc.PrivateKey().PublicKey().GetScriptHash(), Scopes: transaction.Global, diff --git a/pkg/morph/client/container/eacl.go b/pkg/morph/client/container/eacl.go index b2ee42b70..b90dc7220 100644 --- a/pkg/morph/client/container/eacl.go +++ b/pkg/morph/client/container/eacl.go @@ -42,7 +42,7 @@ func (c *Client) EACL(args EACLArgs) (*EACLValues, error) { return nil, errors.Errorf("unexpected stack item count (%s): %d", c.eaclMethod, ln) } - eacl, err := client.BytesFromStackParameter(prms[0]) + eacl, err := client.BytesFromStackItem(prms[0]) if err != nil { return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.eaclMethod) } diff --git a/pkg/morph/client/container/get.go b/pkg/morph/client/container/get.go index fb9e6d866..fa71a0d7b 100644 --- a/pkg/morph/client/container/get.go +++ b/pkg/morph/client/container/get.go @@ -42,7 +42,7 @@ func (c *Client) Get(args GetArgs) (*GetValues, error) { return nil, errors.Errorf("unexpected stack item count (%s): %d", c.getMethod, ln) } - cnrBytes, err := client.BytesFromStackParameter(prms[0]) + cnrBytes, err := client.BytesFromStackItem(prms[0]) if err != nil { return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.getMethod) } diff --git a/pkg/morph/client/container/list.go b/pkg/morph/client/container/list.go index 4ea6dde2f..bc3a9ae2a 100644 --- a/pkg/morph/client/container/list.go +++ b/pkg/morph/client/container/list.go @@ -48,7 +48,7 @@ func (c *Client) List(args ListArgs) (*ListValues, error) { return nil, errors.Errorf("unexpected stack item count (%s): %d", c.listMethod, ln) } - prms, err = client.ArrayFromStackParameter(prms[0]) + prms, err = client.ArrayFromStackItem(prms[0]) if err != nil { return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", c.listMethod) } @@ -58,7 +58,7 @@ func (c *Client) List(args ListArgs) (*ListValues, error) { } for i := range prms { - cid, err := client.BytesFromStackParameter(prms[i]) + cid, err := client.BytesFromStackItem(prms[i]) if err != nil { return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.listMethod) } diff --git a/pkg/morph/client/netmap/ir_list.go b/pkg/morph/client/netmap/ir_list.go index 035c0553f..2587fc123 100644 --- a/pkg/morph/client/netmap/ir_list.go +++ b/pkg/morph/client/netmap/ir_list.go @@ -34,7 +34,7 @@ func (c *Client) InnerRingList(args InnerRingListArgs) (*InnerRingListValues, er return nil, errors.Errorf("unexpected stack item count (%s): %d", c.innerRingListMethod, ln) } - prms, err = client.ArrayFromStackParameter(prms[0]) + prms, err = client.ArrayFromStackItem(prms[0]) if err != nil { return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", c.innerRingListMethod) } @@ -44,12 +44,12 @@ func (c *Client) InnerRingList(args InnerRingListArgs) (*InnerRingListValues, er } for i := range prms { - nodePrms, err := client.ArrayFromStackParameter(prms[i]) + nodePrms, err := client.ArrayFromStackItem(prms[i]) if err != nil { return nil, errors.Wrap(err, "could not get stack item array (Node #%d)") } - key, err := client.BytesFromStackParameter(nodePrms[0]) + key, err := client.BytesFromStackItem(nodePrms[0]) if err != nil { return nil, errors.Wrapf(err, "could not parse stack item (Key #%d)", i) } diff --git a/pkg/morph/client/netmap/netmap.go b/pkg/morph/client/netmap/netmap.go index 8efb4238a..ed58bc079 100644 --- a/pkg/morph/client/netmap/netmap.go +++ b/pkg/morph/client/netmap/netmap.go @@ -1,7 +1,7 @@ package netmap import ( - "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/pkg/errors" ) @@ -37,7 +37,7 @@ func (c *Client) NetMap(args GetNetMapArgs) (*GetNetMapValues, error) { return nil, errors.Errorf("unexpected stack item count (%s): %d", c.netMapMethod, ln) } - prms, err = client.ArrayFromStackParameter(prms[0]) + prms, err = client.ArrayFromStackItem(prms[0]) if err != nil { return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", c.netMapMethod) } @@ -58,8 +58,8 @@ func (c *Client) NetMap(args GetNetMapArgs) (*GetNetMapValues, error) { return res, nil } -func peerInfoFromStackItem(prm smartcontract.Parameter) (*PeerInfo, error) { - prms, err := client.ArrayFromStackParameter(prm) +func peerInfoFromStackItem(prm stackitem.Item) (*PeerInfo, error) { + prms, err := client.ArrayFromStackItem(prm) if err != nil { return nil, errors.Wrapf(err, "could not get stack item array (PeerInfo)") } else if ln := len(prms); ln != nodeInfoFixedPrmNumber { @@ -69,25 +69,25 @@ func peerInfoFromStackItem(prm smartcontract.Parameter) (*PeerInfo, error) { res := new(PeerInfo) // Address - res.address, err = client.BytesFromStackParameter(prms[0]) + res.address, err = client.BytesFromStackItem(prms[0]) if err != nil { return nil, errors.Wrap(err, "could not get byte array from stack item (Address)") } // Public key - if res.key, err = client.BytesFromStackParameter(prms[1]); err != nil { + if res.key, err = client.BytesFromStackItem(prms[1]); err != nil { return nil, errors.Wrap(err, "could not get byte array from stack item (Public key)") } // Options - if prms, err = client.ArrayFromStackParameter(prms[2]); err != nil { + if prms, err = client.ArrayFromStackItem(prms[2]); err != nil { return nil, errors.Wrapf(err, "could not get stack item array (Options)") } res.opts = make([][]byte, 0, len(prms)) for i := range prms { - opt, err := client.BytesFromStackParameter(prms[i]) + opt, err := client.BytesFromStackItem(prms[i]) if err != nil { return nil, errors.Wrapf(err, "could not get byte array from stack item (Option #%d)", i) } diff --git a/pkg/morph/client/static.go b/pkg/morph/client/static.go index c903b3af9..404d54632 100644 --- a/pkg/morph/client/static.go +++ b/pkg/morph/client/static.go @@ -3,8 +3,8 @@ package client import ( "errors" - sc "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) // StaticClient is a wrapper over Neo:Morph client @@ -53,7 +53,7 @@ func (s StaticClient) Invoke(method string, args ...interface{}) error { } // TestInvoke calls TestInvoke method of Client with static internal script hash. -func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]sc.Parameter, error) { +func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackitem.Item, error) { return s.client.TestInvoke( s.scScriptHash, method,