[#14] Adopt stackitems in morph requests

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-08-27 14:57:13 +03:00
parent 0c06eafc60
commit 29d6ababae
9 changed files with 23 additions and 22 deletions

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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,

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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,