[#124] Update neo-go to pre-preview4 version

Neo-go does not use smartcontract.Parameter to return values
anymore, so it's convertes partly removed from neofs-node.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-26 17:46:15 +03:00 committed by Alex Vanin
parent 2bd827a478
commit 174efc9df3
35 changed files with 303 additions and 836 deletions

2
go.mod
View file

@ -12,7 +12,7 @@ require (
github.com/multiformats/go-multiaddr v0.2.0 github.com/multiformats/go-multiaddr v0.2.0
github.com/multiformats/go-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2 github.com/multiformats/go-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2
github.com/multiformats/go-multihash v0.0.13 // indirect github.com/multiformats/go-multihash v0.0.13 // indirect
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78 github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201029071528-352e99d9b91a github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201029071528-352e99d9b91a
github.com/nspcc-dev/neofs-crypto v0.3.0 github.com/nspcc-dev/neofs-crypto v0.3.0
github.com/nspcc-dev/tzhash v1.4.0 github.com/nspcc-dev/tzhash v1.4.0

BIN
go.sum

Binary file not shown.

View file

@ -1,8 +1,6 @@
package client package client
import ( import (
"encoding/hex"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/rpc/client"
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract" sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
@ -72,10 +70,7 @@ func (c *Client) Invoke(contract util.Uint160, fee util.Fixed8, method string, a
return errEmptyInvocationScript return errEmptyInvocationScript
} }
script, err := hex.DecodeString(resp.Script) script := resp.Script
if err != nil {
return errScriptDecode
}
sysFee := resp.GasConsumed + int64(fee) // consumed gas + extra fee sysFee := resp.GasConsumed + int64(fee) // consumed gas + extra fee

View file

@ -85,12 +85,16 @@ func New(key *ecdsa.PrivateKey, endpoint string, opts ...Option) (*Client, error
cli, err := client.New(cfg.ctx, endpoint, client.Options{ cli, err := client.New(cfg.ctx, endpoint, client.Options{
DialTimeout: cfg.dialTimeout, DialTimeout: cfg.dialTimeout,
Network: cfg.magic,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = cli.Init() // magic number is set there based on RPC node answer
if err != nil {
return nil, err
}
return &Client{ return &Client{
logger: cfg.logger, logger: cfg.logger,
client: cli, client: cli,

View file

@ -1,10 +1,8 @@
package client package client
import ( import (
"encoding/binary"
"math/big" "math/big"
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -15,124 +13,6 @@ import (
method. method.
*/ */
// BoolFromStackParameter receives boolean value from the value of a smart contract parameter.
func BoolFromStackParameter(param sc.Parameter) (bool, error) {
switch param.Type {
case sc.BoolType:
val, ok := param.Value.(bool)
if !ok {
return false, errors.Errorf("chain/client: can't convert %T to boolean", param.Value)
}
return val, nil
case sc.IntegerType:
val, ok := param.Value.(int64)
if !ok {
return false, errors.Errorf("chain/client: can't convert %T to boolean", param.Value)
}
return val > 0, nil
case sc.ByteArrayType:
val, ok := param.Value.([]byte)
if !ok {
return false, errors.Errorf("chain/client: can't convert %T to boolean", param.Value)
}
return len(val) != 0, nil
default:
return false, errors.Errorf("chain/client: %s is not a bool type", param.Type)
}
}
// IntFromStackParameter receives numerical value from the value of a smart contract parameter.
func IntFromStackParameter(param sc.Parameter) (int64, error) {
switch param.Type {
case sc.IntegerType:
val, ok := param.Value.(int64)
if !ok {
return 0, errors.Errorf("chain/client: can't convert %T to integer", param.Value)
}
return val, nil
case sc.ByteArrayType:
val, ok := param.Value.([]byte)
if !ok || len(val) > 8 {
return 0, errors.Errorf("chain/client: can't convert %T to integer", param.Value)
}
res := make([]byte, 8)
copy(res[:len(val)], val)
return int64(binary.LittleEndian.Uint64(res)), nil
default:
return 0, errors.Errorf("chain/client: %s is not an integer type", param.Type)
}
}
// BytesFromStackParameter receives binary value from the value of a smart contract parameter.
func BytesFromStackParameter(param sc.Parameter) ([]byte, error) {
if param.Type != sc.ByteArrayType {
if param.Type == sc.AnyType && param.Value == nil {
return nil, nil
}
return nil, errors.Errorf("chain/client: %s is not a byte array type", param.Type)
}
val, ok := param.Value.([]byte)
if !ok {
return nil, errors.Errorf("chain/client: can't convert %T to byte slice", param.Value)
}
return val, nil
}
// ArrayFromStackParameter returns the slice contract parameters from passed parameter.
//
// If passed parameter carries boolean false value, (nil, nil) returns.
func ArrayFromStackParameter(param sc.Parameter) ([]sc.Parameter, error) {
if param.Type == sc.BoolType && !param.Value.(bool) {
return nil, nil
}
if param.Type != sc.ArrayType {
if param.Type == sc.AnyType && param.Value == nil {
return nil, nil
}
return nil, errors.Errorf("chain/client: %s is not an array type", param.Type)
}
val, ok := param.Value.([]sc.Parameter)
if !ok {
return nil, errors.Errorf("chain/client: can't convert %T to parameter slice", param.Value)
}
return val, nil
}
// StringFromStackParameter receives string value from the value of a smart contract parameter.
func StringFromStackParameter(param sc.Parameter) (string, error) {
switch param.Type {
case sc.StringType:
val, ok := param.Value.(string)
if !ok {
return "", errors.Errorf("chain/client: can't convert %T to string", param.Value)
}
return val, nil
case sc.ByteArrayType:
val, ok := param.Value.([]byte)
if !ok {
return "", errors.Errorf("chain/client: can't convert %T to string", param.Value)
}
return string(val), nil
default:
return "", errors.Errorf("chain/client: %s is not a string type", param.Type)
}
}
// BoolFromStackItem receives boolean value from the value of a smart contract parameter. // BoolFromStackItem receives boolean value from the value of a smart contract parameter.
func BoolFromStackItem(param stackitem.Item) (bool, error) { func BoolFromStackItem(param stackitem.Item) (bool, error) {
switch param.Type() { switch param.Type() {

View file

@ -6,52 +6,11 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var ( var (
stringParam = sc.Parameter{
Type: sc.StringType,
Value: "Hello World",
}
intParam = sc.Parameter{
Type: sc.IntegerType,
Value: int64(1),
}
byteWithIntParam = sc.Parameter{
Type: sc.ByteArrayType,
Value: []byte{0x0a},
}
byteArrayParam = sc.Parameter{
Type: sc.ByteArrayType,
Value: []byte("Hello World"),
}
emptyByteArrayParam = sc.Parameter{
Type: sc.ByteArrayType,
Value: []byte{},
}
trueBoolParam = sc.Parameter{
Type: sc.BoolType,
Value: true,
}
falseBoolParam = sc.Parameter{
Type: sc.BoolType,
Value: false,
}
arrayParam = sc.Parameter{
Type: sc.ArrayType,
Value: []sc.Parameter{intParam, byteArrayParam},
}
bigIntValue = new(big.Int).Mul(big.NewInt(math.MaxInt64), big.NewInt(10)) bigIntValue = new(big.Int).Mul(big.NewInt(math.MaxInt64), big.NewInt(10))
stringByteItem = stackitem.NewByteArray([]byte("Hello World")) stringByteItem = stackitem.NewByteArray([]byte("Hello World"))
@ -66,101 +25,6 @@ var (
anyTypeItem = stackitem.Null{} anyTypeItem = stackitem.Null{}
) )
func TestBoolFromStackParameter(t *testing.T) {
t.Run("true assert", func(t *testing.T) {
val, err := BoolFromStackParameter(trueBoolParam)
require.NoError(t, err)
require.True(t, val)
val, err = BoolFromStackParameter(intParam)
require.NoError(t, err)
require.True(t, val)
})
t.Run("false assert", func(t *testing.T) {
val, err := BoolFromStackParameter(falseBoolParam)
require.NoError(t, err)
require.False(t, val)
val, err = BoolFromStackParameter(emptyByteArrayParam)
require.NoError(t, err)
require.False(t, val)
})
t.Run("incorrect assert", func(t *testing.T) {
_, err := BoolFromStackParameter(stringParam)
require.Error(t, err)
})
}
func TestArrayFromStackParameter(t *testing.T) {
t.Run("correct assert", func(t *testing.T) {
val, err := ArrayFromStackParameter(arrayParam)
require.NoError(t, err)
require.Len(t, val, len(arrayParam.Value.([]sc.Parameter)))
})
t.Run("incorrect assert", func(t *testing.T) {
_, err := ArrayFromStackParameter(byteArrayParam)
require.Error(t, err)
})
t.Run("boolean false case", func(t *testing.T) {
val, err := ArrayFromStackParameter(falseBoolParam)
require.NoError(t, err)
require.Nil(t, val)
})
}
func TestBytesFromStackParameter(t *testing.T) {
t.Run("correct assert", func(t *testing.T) {
val, err := BytesFromStackParameter(byteArrayParam)
require.NoError(t, err)
require.Equal(t, byteArrayParam.Value.([]byte), val)
})
t.Run("incorrect assert", func(t *testing.T) {
_, err := BytesFromStackParameter(stringParam)
require.Error(t, err)
})
}
func TestIntFromStackParameter(t *testing.T) {
t.Run("correct assert", func(t *testing.T) {
val, err := IntFromStackParameter(intParam)
require.NoError(t, err)
require.Equal(t, intParam.Value.(int64), val)
val, err = IntFromStackParameter(byteWithIntParam)
require.NoError(t, err)
require.Equal(t, int64(0x0a), val)
val, err = IntFromStackParameter(emptyByteArrayParam)
require.NoError(t, err)
require.Equal(t, int64(0), val)
})
t.Run("incorrect assert", func(t *testing.T) {
_, err := IntFromStackParameter(byteArrayParam)
require.Error(t, err)
})
}
func TestStringFromStackParameter(t *testing.T) {
t.Run("correct assert", func(t *testing.T) {
val, err := StringFromStackParameter(stringParam)
require.NoError(t, err)
require.Equal(t, stringParam.Value.(string), val)
val, err = StringFromStackParameter(byteArrayParam)
require.NoError(t, err)
require.Equal(t, string(byteArrayParam.Value.([]byte)), val)
})
t.Run("incorrect assert", func(t *testing.T) {
_, err := StringFromStackParameter(intParam)
require.Error(t, err)
})
}
func TestBoolFromStackItem(t *testing.T) { func TestBoolFromStackItem(t *testing.T) {
t.Run("true assert", func(t *testing.T) { t.Run("true assert", func(t *testing.T) {
val, err := BoolFromStackItem(trueBoolItem) val, err := BoolFromStackItem(trueBoolItem)

View file

@ -1,8 +1,8 @@
package balance package balance
import ( import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -36,7 +36,7 @@ func (l Lock) Amount() int64 { return l.amount }
func (l Lock) Until() int64 { return l.until } func (l Lock) Until() int64 { return l.until }
// ParseLock from notification into lock structure. // ParseLock from notification into lock structure.
func ParseLock(params []smartcontract.Parameter) (event.Event, error) { func ParseLock(params []stackitem.Item) (event.Event, error) {
var ( var (
ev Lock ev Lock
err error err error
@ -47,13 +47,13 @@ func ParseLock(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse id // parse id
ev.id, err = client.BytesFromStackParameter(params[0]) ev.id, err = client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get lock id") return nil, errors.Wrap(err, "could not get lock id")
} }
// parse user // parse user
user, err := client.BytesFromStackParameter(params[1]) user, err := client.BytesFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get lock user value") return nil, errors.Wrap(err, "could not get lock user value")
} }
@ -64,7 +64,7 @@ func ParseLock(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse lock account // parse lock account
lock, err := client.BytesFromStackParameter(params[2]) lock, err := client.BytesFromStackItem(params[2])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get lock account value") return nil, errors.Wrap(err, "could not get lock account value")
} }
@ -75,13 +75,13 @@ func ParseLock(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse amount // parse amount
ev.amount, err = client.IntFromStackParameter(params[3]) ev.amount, err = client.IntFromStackItem(params[3])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get lock amount") return nil, errors.Wrap(err, "could not get lock amount")
} }
// parse until deadline // parse until deadline
ev.until, err = client.IntFromStackParameter(params[4]) ev.until, err = client.IntFromStackItem(params[4])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get lock deadline") return nil, errors.Wrap(err, "could not get lock deadline")
} }

View file

@ -1,10 +1,11 @@
package balance package balance
import ( import (
"math/big"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -20,9 +21,9 @@ func TestParseLock(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
{}, stackitem.NewMap(),
} }
_, err := ParseLock(prms) _, err := ParseLock(prms)
@ -30,117 +31,62 @@ func TestParseLock(t *testing.T) {
}) })
t.Run("wrong id parameter", func(t *testing.T) { t.Run("wrong id parameter", func(t *testing.T) {
_, err := ParseLock([]smartcontract.Parameter{ _, err := ParseLock([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.IntegerType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong from parameter", func(t *testing.T) { t.Run("wrong from parameter", func(t *testing.T) {
_, err := ParseLock([]smartcontract.Parameter{ _, err := ParseLock([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: id,
},
{
Type: smartcontract.IntegerType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong lock parameter", func(t *testing.T) { t.Run("wrong lock parameter", func(t *testing.T) {
_, err := ParseLock([]smartcontract.Parameter{ _, err := ParseLock([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(user.BytesBE()),
Value: id, stackitem.NewMap(),
},
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong amount parameter", func(t *testing.T) { t.Run("wrong amount parameter", func(t *testing.T) {
_, err := ParseLock([]smartcontract.Parameter{ _, err := ParseLock([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(user.BytesBE()),
Value: id, stackitem.NewByteArray(lock.BytesBE()),
}, stackitem.NewMap(),
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.ByteArrayType,
Value: lock.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong until parameter", func(t *testing.T) { t.Run("wrong until parameter", func(t *testing.T) {
_, err := ParseLock([]smartcontract.Parameter{ _, err := ParseLock([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(user.BytesBE()),
Value: id, stackitem.NewByteArray(lock.BytesBE()),
}, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
{ stackitem.NewMap(),
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.ByteArrayType,
Value: lock.BytesBE(),
},
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseLock([]smartcontract.Parameter{ ev, err := ParseLock([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(user.BytesBE()),
Value: id, stackitem.NewByteArray(lock.BytesBE()),
}, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
{ stackitem.NewBigInteger(new(big.Int).SetInt64(until)),
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.ByteArrayType,
Value: lock.BytesBE(),
},
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.IntegerType,
Value: until,
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -1,7 +1,7 @@
package container package container
import ( 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/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -23,7 +23,7 @@ func (d Delete) ContainerID() []byte { return d.containerID }
func (d Delete) Signature() []byte { return d.signature } func (d Delete) Signature() []byte { return d.signature }
// ParseDelete from notification into container event structure. // ParseDelete from notification into container event structure.
func ParseDelete(params []smartcontract.Parameter) (event.Event, error) { func ParseDelete(params []stackitem.Item) (event.Event, error) {
var ( var (
ev Delete ev Delete
err error err error
@ -34,13 +34,13 @@ func ParseDelete(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse container // parse container
ev.containerID, err = client.BytesFromStackParameter(params[0]) ev.containerID, err = client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get container") return nil, errors.Wrap(err, "could not get container")
} }
// parse signature // parse signature
ev.signature, err = client.BytesFromStackParameter(params[1]) ev.signature, err = client.BytesFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get signature") return nil, errors.Wrap(err, "could not get signature")
} }

View file

@ -3,7 +3,7 @@ package container
import ( import (
"testing" "testing"
"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/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -15,8 +15,8 @@ func TestParseDelete(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
} }
_, err := ParseDelete(prms) _, err := ParseDelete(prms)
@ -24,39 +24,26 @@ func TestParseDelete(t *testing.T) {
}) })
t.Run("wrong container parameter", func(t *testing.T) { t.Run("wrong container parameter", func(t *testing.T) {
_, err := ParsePut([]smartcontract.Parameter{ _, err := ParsePut([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong signature parameter", func(t *testing.T) { t.Run("wrong signature parameter", func(t *testing.T) {
_, err := ParseDelete([]smartcontract.Parameter{ _, err := ParseDelete([]stackitem.Item{
{ stackitem.NewByteArray(containerID),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: containerID,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseDelete([]smartcontract.Parameter{ ev, err := ParseDelete([]stackitem.Item{
{ stackitem.NewByteArray(containerID),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(signature),
Value: containerID,
},
{
Type: smartcontract.ByteArrayType,
Value: signature,
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -4,7 +4,7 @@ import (
"crypto/elliptic" "crypto/elliptic"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"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/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -30,7 +30,7 @@ func (p Put) Signature() []byte { return p.signature }
func (p Put) PublicKey() *keys.PublicKey { return p.publicKey } func (p Put) PublicKey() *keys.PublicKey { return p.publicKey }
// ParsePut from notification into container event structure. // ParsePut from notification into container event structure.
func ParsePut(params []smartcontract.Parameter) (event.Event, error) { func ParsePut(params []stackitem.Item) (event.Event, error) {
var ( var (
ev Put ev Put
err error err error
@ -41,19 +41,19 @@ func ParsePut(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse container // parse container
ev.rawContainer, err = client.BytesFromStackParameter(params[0]) ev.rawContainer, err = client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get container") return nil, errors.Wrap(err, "could not get container")
} }
// parse signature // parse signature
ev.signature, err = client.BytesFromStackParameter(params[1]) ev.signature, err = client.BytesFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get signature") return nil, errors.Wrap(err, "could not get signature")
} }
// parse public key // parse public key
key, err := client.BytesFromStackParameter(params[2]) key, err := client.BytesFromStackItem(params[2])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get public key") return nil, errors.Wrap(err, "could not get public key")
} }

View file

@ -5,7 +5,7 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/util/test" "github.com/nspcc-dev/neofs-node/pkg/util/test"
@ -20,9 +20,9 @@ func TestParsePut(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
{}, stackitem.NewMap(),
} }
_, err := ParsePut(prms) _, err := ParsePut(prms)
@ -30,61 +30,37 @@ func TestParsePut(t *testing.T) {
}) })
t.Run("wrong container parameter", func(t *testing.T) { t.Run("wrong container parameter", func(t *testing.T) {
_, err := ParsePut([]smartcontract.Parameter{ _, err := ParsePut([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong signature parameter", func(t *testing.T) { t.Run("wrong signature parameter", func(t *testing.T) {
_, err := ParsePut([]smartcontract.Parameter{ _, err := ParsePut([]stackitem.Item{
{ stackitem.NewByteArray(containerData),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: containerData,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong key parameter", func(t *testing.T) { t.Run("wrong key parameter", func(t *testing.T) {
_, err := ParsePut([]smartcontract.Parameter{ _, err := ParsePut([]stackitem.Item{
{ stackitem.NewByteArray(containerData),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(signature),
Value: containerData, stackitem.NewMap(),
},
{
Type: smartcontract.ByteArrayType,
Value: signature,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParsePut([]smartcontract.Parameter{ ev, err := ParsePut([]stackitem.Item{
{ stackitem.NewByteArray(containerData),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(signature),
Value: containerData, stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
},
{
Type: smartcontract.ByteArrayType,
Value: signature,
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKey),
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -4,7 +4,7 @@ import (
"context" "context"
"sync" "sync"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result" "github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/subscriber" "github.com/nspcc-dev/neofs-node/pkg/morph/subscriber"
@ -143,7 +143,7 @@ func (s listener) listen(ctx context.Context, intError chan<- error) error {
return nil return nil
} }
func (s listener) listenLoop(ctx context.Context, chEvent <-chan *result.NotificationEvent, intErr chan<- error) { func (s listener) listenLoop(ctx context.Context, chEvent <-chan *state.NotificationEvent, intErr chan<- error) {
loop: loop:
for { for {
select { select {
@ -170,13 +170,13 @@ loop:
} }
} }
func (s listener) parseAndHandle(notifyEvent *result.NotificationEvent) { func (s listener) parseAndHandle(notifyEvent *state.NotificationEvent) {
log := s.log.With( log := s.log.With(
zap.String("script hash LE", notifyEvent.Contract.StringLE()), zap.String("script hash LE", notifyEvent.ScriptHash.StringLE()),
) )
// stack item must be an array of items // stack item must be an array of items
arr, err := client.ArrayFromStackParameter(notifyEvent.Item) arr, err := client.ArrayFromStackItem(notifyEvent.Item)
if err != nil { if err != nil {
log.Warn("stack item is not an array type", log.Warn("stack item is not an array type",
zap.String("error", err.Error()), zap.String("error", err.Error()),
@ -197,7 +197,7 @@ func (s listener) parseAndHandle(notifyEvent *result.NotificationEvent) {
// get the event parser // get the event parser
keyEvent := scriptHashWithType{} keyEvent := scriptHashWithType{}
keyEvent.SetScriptHash(notifyEvent.Contract) keyEvent.SetScriptHash(notifyEvent.ScriptHash)
keyEvent.SetType(typEvent) keyEvent.SetType(typEvent)
s.mtx.RLock() s.mtx.RLock()

View file

@ -4,8 +4,8 @@ import (
"crypto/elliptic" "crypto/elliptic"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -23,7 +23,7 @@ func (b Bind) Keys() []*keys.PublicKey { return b.keys }
func (b Bind) User() util.Uint160 { return b.user } func (b Bind) User() util.Uint160 { return b.user }
func ParseBind(params []smartcontract.Parameter) (event.Event, error) { func ParseBind(params []stackitem.Item) (event.Event, error) {
var ( var (
ev Bind ev Bind
err error err error
@ -34,7 +34,7 @@ func ParseBind(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse user // parse user
user, err := client.BytesFromStackParameter(params[0]) user, err := client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get bind user") return nil, errors.Wrap(err, "could not get bind user")
} }
@ -45,14 +45,14 @@ func ParseBind(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse keys // parse keys
bindKeys, err := client.ArrayFromStackParameter(params[1]) bindKeys, err := client.ArrayFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get bind keys") return nil, errors.Wrap(err, "could not get bind keys")
} }
ev.keys = make([]*keys.PublicKey, 0, len(bindKeys)) ev.keys = make([]*keys.PublicKey, 0, len(bindKeys))
for i := range bindKeys { for i := range bindKeys {
rawKey, err := client.BytesFromStackParameter(bindKeys[i]) rawKey, err := client.BytesFromStackItem(bindKeys[i])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get bind public key") return nil, errors.Wrap(err, "could not get bind public key")
} }

View file

@ -6,8 +6,8 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/util/test" "github.com/nspcc-dev/neofs-node/pkg/util/test"
@ -25,8 +25,8 @@ func TestParseBind(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
} }
_, err := ParseBind(prms) _, err := ParseBind(prms)
@ -34,58 +34,38 @@ func TestParseBind(t *testing.T) {
}) })
t.Run("wrong first parameter", func(t *testing.T) { t.Run("wrong first parameter", func(t *testing.T) {
_, err := ParseBind([]smartcontract.Parameter{ _, err := ParseBind([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong second parameter", func(t *testing.T) { t.Run("wrong second parameter", func(t *testing.T) {
_, err := ParseBind([]smartcontract.Parameter{ _, err := ParseBind([]stackitem.Item{
{ stackitem.NewByteArray(user.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: user.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct", func(t *testing.T) { t.Run("correct", func(t *testing.T) {
ev, err := ParseBind([]smartcontract.Parameter{
{ ev, err := ParseBind([]stackitem.Item{
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(user.BytesBE()),
Value: user.BytesBE(), stackitem.NewArray([]stackitem.Item{
}, stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[0])),
{ stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[1])),
Type: smartcontract.ArrayType, stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[2])),
Value: []smartcontract.Parameter{ }),
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKeys[0]),
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKeys[1]),
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKeys[2]),
},
},
},
}) })
require.NoError(t, err) require.NoError(t, err)
expKeys := make([]*keys.PublicKey, len(publicKeys)) expKeys := make([]*keys.PublicKey, len(publicKeys))
for i := range publicKeys { for i := range publicKeys {
expKeys[i], err = keys.NewPublicKeyFromBytes(crypto.MarshalPublicKey(publicKeys[i]), elliptic.P256()) expKeys[i], err = keys.NewPublicKeyFromBytes(
crypto.MarshalPublicKey(publicKeys[i]), elliptic.P256())
require.NoError(t, err) require.NoError(t, err)
} }

View file

@ -1,8 +1,8 @@
package neofs package neofs
import ( import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -32,7 +32,7 @@ func (c Cheque) Amount() int64 { return c.amount }
func (c Cheque) LockAccount() util.Uint160 { return c.lock } func (c Cheque) LockAccount() util.Uint160 { return c.lock }
// ParseCheque from notification into cheque structure. // ParseCheque from notification into cheque structure.
func ParseCheque(params []smartcontract.Parameter) (event.Event, error) { func ParseCheque(params []stackitem.Item) (event.Event, error) {
var ( var (
ev Cheque ev Cheque
err error err error
@ -43,13 +43,13 @@ func ParseCheque(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse id // parse id
ev.id, err = client.BytesFromStackParameter(params[0]) ev.id, err = client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get cheque id") return nil, errors.Wrap(err, "could not get cheque id")
} }
// parse user // parse user
user, err := client.BytesFromStackParameter(params[1]) user, err := client.BytesFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get cheque user") return nil, errors.Wrap(err, "could not get cheque user")
} }
@ -60,13 +60,13 @@ func ParseCheque(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse amount // parse amount
ev.amount, err = client.IntFromStackParameter(params[2]) ev.amount, err = client.IntFromStackItem(params[2])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get cheque amount") return nil, errors.Wrap(err, "could not get cheque amount")
} }
// parse lock account // parse lock account
lock, err := client.BytesFromStackParameter(params[3]) lock, err := client.BytesFromStackItem(params[3])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get cheque lock account") return nil, errors.Wrap(err, "could not get cheque lock account")
} }

View file

@ -1,10 +1,11 @@
package neofs package neofs
import ( import (
"math/big"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -19,9 +20,9 @@ func TestParseCheque(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
{}, stackitem.NewMap(),
} }
_, err := ParseCheque(prms) _, err := ParseCheque(prms)
@ -29,87 +30,49 @@ func TestParseCheque(t *testing.T) {
}) })
t.Run("wrong id parameter", func(t *testing.T) { t.Run("wrong id parameter", func(t *testing.T) {
_, err := ParseCheque([]smartcontract.Parameter{ _, err := ParseCheque([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong user parameter", func(t *testing.T) { t.Run("wrong user parameter", func(t *testing.T) {
_, err := ParseCheque([]smartcontract.Parameter{ _, err := ParseCheque([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: id,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong amount parameter", func(t *testing.T) { t.Run("wrong amount parameter", func(t *testing.T) {
_, err := ParseCheque([]smartcontract.Parameter{ _, err := ParseCheque([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(user.BytesBE()),
Value: id, stackitem.NewMap(),
},
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong lock parameter", func(t *testing.T) { t.Run("wrong lock parameter", func(t *testing.T) {
_, err := ParseCheque([]smartcontract.Parameter{ _, err := ParseCheque([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(user.BytesBE()),
Value: id, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
}, stackitem.NewMap(),
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseCheque([]smartcontract.Parameter{ ev, err := ParseCheque([]stackitem.Item{
{ stackitem.NewByteArray(id),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(user.BytesBE()),
Value: id, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
}, stackitem.NewByteArray(lock.BytesBE()),
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.ByteArrayType,
Value: lock.BytesBE(),
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -1,7 +1,7 @@
package neofs package neofs
import ( 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/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -19,7 +19,7 @@ func (u Config) Key() []byte { return u.key }
func (u Config) Value() []byte { return u.value } func (u Config) Value() []byte { return u.value }
func ParseConfig(params []smartcontract.Parameter) (event.Event, error) { func ParseConfig(params []stackitem.Item) (event.Event, error) {
var ( var (
ev Config ev Config
err error err error
@ -30,13 +30,13 @@ func ParseConfig(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse key // parse key
ev.key, err = client.BytesFromStackParameter(params[0]) ev.key, err = client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get config key") return nil, errors.Wrap(err, "could not get config key")
} }
// parse value // parse value
ev.value, err = client.BytesFromStackParameter(params[1]) ev.value, err = client.BytesFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get config value") return nil, errors.Wrap(err, "could not get config value")
} }

View file

@ -3,7 +3,7 @@ package neofs
import ( import (
"testing" "testing"
"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/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -15,8 +15,8 @@ func TestParseConfig(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
} }
_, err := ParseConfig(prms) _, err := ParseConfig(prms)
@ -24,39 +24,26 @@ func TestParseConfig(t *testing.T) {
}) })
t.Run("wrong first parameter", func(t *testing.T) { t.Run("wrong first parameter", func(t *testing.T) {
_, err := ParseConfig([]smartcontract.Parameter{ _, err := ParseConfig([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong second parameter", func(t *testing.T) { t.Run("wrong second parameter", func(t *testing.T) {
_, err := ParseConfig([]smartcontract.Parameter{ _, err := ParseConfig([]stackitem.Item{
{ stackitem.NewByteArray(key),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: key,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct", func(t *testing.T) { t.Run("correct", func(t *testing.T) {
ev, err := ParseConfig([]smartcontract.Parameter{ ev, err := ParseConfig([]stackitem.Item{
{ stackitem.NewByteArray(key),
Type: smartcontract.ByteArrayType, stackitem.NewByteArray(value),
Value: key,
},
{
Type: smartcontract.ByteArrayType,
Value: value,
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -1,8 +1,8 @@
package neofs package neofs
import ( import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -32,7 +32,7 @@ func (d Deposit) To() util.Uint160 { return d.to }
func (d Deposit) Amount() int64 { return d.amount } func (d Deposit) Amount() int64 { return d.amount }
// ParseDeposit notification into deposit structure. // ParseDeposit notification into deposit structure.
func ParseDeposit(params []smartcontract.Parameter) (event.Event, error) { func ParseDeposit(params []stackitem.Item) (event.Event, error) {
var ev Deposit var ev Deposit
if ln := len(params); ln != 4 { if ln := len(params); ln != 4 {
@ -40,7 +40,7 @@ func ParseDeposit(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse from // parse from
from, err := client.BytesFromStackParameter(params[0]) from, err := client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get deposit sender") return nil, errors.Wrap(err, "could not get deposit sender")
} }
@ -51,13 +51,13 @@ func ParseDeposit(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse amount // parse amount
ev.amount, err = client.IntFromStackParameter(params[1]) ev.amount, err = client.IntFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get deposit amount") return nil, errors.Wrap(err, "could not get deposit amount")
} }
// parse to // parse to
to, err := client.BytesFromStackParameter(params[2]) to, err := client.BytesFromStackItem(params[2])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get deposit receiver") return nil, errors.Wrap(err, "could not get deposit receiver")
} }
@ -68,7 +68,7 @@ func ParseDeposit(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse id // parse id
ev.id, err = client.BytesFromStackParameter(params[3]) ev.id, err = client.BytesFromStackItem(params[3])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get deposit id") return nil, errors.Wrap(err, "could not get deposit id")
} }

View file

@ -1,10 +1,11 @@
package neofs package neofs
import ( import (
"math/big"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -19,9 +20,9 @@ func TestParseDeposit(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
{}, stackitem.NewMap(),
} }
_, err := ParseDeposit(prms) _, err := ParseDeposit(prms)
@ -29,87 +30,49 @@ func TestParseDeposit(t *testing.T) {
}) })
t.Run("wrong from parameter", func(t *testing.T) { t.Run("wrong from parameter", func(t *testing.T) {
_, err := ParseDeposit([]smartcontract.Parameter{ _, err := ParseDeposit([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong amount parameter", func(t *testing.T) { t.Run("wrong amount parameter", func(t *testing.T) {
_, err := ParseDeposit([]smartcontract.Parameter{ _, err := ParseDeposit([]stackitem.Item{
{ stackitem.NewByteArray(from.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: from.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong to parameter", func(t *testing.T) { t.Run("wrong to parameter", func(t *testing.T) {
_, err := ParseDeposit([]smartcontract.Parameter{ _, err := ParseDeposit([]stackitem.Item{
{ stackitem.NewByteArray(from.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
Value: from.BytesBE(), stackitem.NewMap(),
},
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong id parameter", func(t *testing.T) { t.Run("wrong id parameter", func(t *testing.T) {
_, err := ParseDeposit([]smartcontract.Parameter{ _, err := ParseDeposit([]stackitem.Item{
{ stackitem.NewByteArray(from.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
Value: from.BytesBE(), stackitem.NewByteArray(to.BytesBE()),
}, stackitem.NewMap(),
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.ByteArrayType,
Value: to.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseDeposit([]smartcontract.Parameter{ ev, err := ParseDeposit([]stackitem.Item{
{ stackitem.NewByteArray(from.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
Value: from.BytesBE(), stackitem.NewByteArray(to.BytesBE()),
}, stackitem.NewByteArray(id),
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.ByteArrayType,
Value: to.BytesBE(),
},
{
Type: smartcontract.ByteArrayType,
Value: id,
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -4,7 +4,7 @@ import (
"crypto/elliptic" "crypto/elliptic"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"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/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -19,7 +19,7 @@ func (UpdateInnerRing) MorphEvent() {}
func (u UpdateInnerRing) Keys() []*keys.PublicKey { return u.keys } func (u UpdateInnerRing) Keys() []*keys.PublicKey { return u.keys }
func ParseUpdateInnerRing(params []smartcontract.Parameter) (event.Event, error) { func ParseUpdateInnerRing(params []stackitem.Item) (event.Event, error) {
var ( var (
ev UpdateInnerRing ev UpdateInnerRing
err error err error
@ -30,14 +30,14 @@ func ParseUpdateInnerRing(params []smartcontract.Parameter) (event.Event, error)
} }
// parse keys // parse keys
irKeys, err := client.ArrayFromStackParameter(params[0]) irKeys, err := client.ArrayFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get updated inner ring keys") return nil, errors.Wrap(err, "could not get updated inner ring keys")
} }
ev.keys = make([]*keys.PublicKey, 0, len(irKeys)) ev.keys = make([]*keys.PublicKey, 0, len(irKeys))
for i := range irKeys { for i := range irKeys {
rawKey, err := client.BytesFromStackParameter(irKeys[i]) rawKey, err := client.BytesFromStackItem(irKeys[i])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get updated inner ring public key") return nil, errors.Wrap(err, "could not get updated inner ring public key")
} }

View file

@ -6,7 +6,7 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-crypto/test" "github.com/nspcc-dev/neofs-crypto/test"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
@ -23,9 +23,9 @@ func TestParseUpdateInnerRing(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
{}, stackitem.NewMap(),
} }
_, err := ParseUpdateInnerRing(prms) _, err := ParseUpdateInnerRing(prms)
@ -33,40 +33,27 @@ func TestParseUpdateInnerRing(t *testing.T) {
}) })
t.Run("wrong first parameter", func(t *testing.T) { t.Run("wrong first parameter", func(t *testing.T) {
_, err := ParseUpdateInnerRing([]smartcontract.Parameter{ _, err := ParseUpdateInnerRing([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ByteArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct", func(t *testing.T) { t.Run("correct", func(t *testing.T) {
ev, err := ParseUpdateInnerRing([]smartcontract.Parameter{ ev, err := ParseUpdateInnerRing([]stackitem.Item{
{ stackitem.NewArray([]stackitem.Item{
Type: smartcontract.ArrayType, stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[0])),
Value: []smartcontract.Parameter{ stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[1])),
{ stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[2])),
Type: smartcontract.ByteArrayType, }),
Value: crypto.MarshalPublicKey(publicKeys[0]),
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKeys[1]),
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKeys[2]),
},
},
},
}) })
require.NoError(t, err) require.NoError(t, err)
expKeys := make([]*keys.PublicKey, len(publicKeys)) expKeys := make([]*keys.PublicKey, len(publicKeys))
for i := range publicKeys { for i := range publicKeys {
expKeys[i], err = keys.NewPublicKeyFromBytes(crypto.MarshalPublicKey(publicKeys[i]), elliptic.P256()) expKeys[i], err = keys.NewPublicKeyFromBytes(
crypto.MarshalPublicKey(publicKeys[i]), elliptic.P256())
require.NoError(t, err) require.NoError(t, err)
} }

View file

@ -4,8 +4,8 @@ import (
"crypto/elliptic" "crypto/elliptic"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -23,7 +23,7 @@ func (u Unbind) Keys() []*keys.PublicKey { return u.keys }
func (u Unbind) User() util.Uint160 { return u.user } func (u Unbind) User() util.Uint160 { return u.user }
func ParseUnbind(params []smartcontract.Parameter) (event.Event, error) { func ParseUnbind(params []stackitem.Item) (event.Event, error) {
var ( var (
ev Unbind ev Unbind
err error err error
@ -34,7 +34,7 @@ func ParseUnbind(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse user // parse user
user, err := client.BytesFromStackParameter(params[0]) user, err := client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get bind user") return nil, errors.Wrap(err, "could not get bind user")
} }
@ -45,14 +45,14 @@ func ParseUnbind(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse keys // parse keys
unbindKeys, err := client.ArrayFromStackParameter(params[1]) unbindKeys, err := client.ArrayFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get unbind keys") return nil, errors.Wrap(err, "could not get unbind keys")
} }
ev.keys = make([]*keys.PublicKey, 0, len(unbindKeys)) ev.keys = make([]*keys.PublicKey, 0, len(unbindKeys))
for i := range unbindKeys { for i := range unbindKeys {
rawKey, err := client.BytesFromStackParameter(unbindKeys[i]) rawKey, err := client.BytesFromStackItem(unbindKeys[i])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get unbind public key") return nil, errors.Wrap(err, "could not get unbind public key")
} }

View file

@ -6,8 +6,8 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/util/test" "github.com/nspcc-dev/neofs-node/pkg/util/test"
@ -25,8 +25,8 @@ func TestParseUnbind(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
} }
_, err := ParseUnbind(prms) _, err := ParseUnbind(prms)
@ -34,58 +34,37 @@ func TestParseUnbind(t *testing.T) {
}) })
t.Run("wrong first parameter", func(t *testing.T) { t.Run("wrong first parameter", func(t *testing.T) {
_, err := ParseUnbind([]smartcontract.Parameter{ _, err := ParseUnbind([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong second parameter", func(t *testing.T) { t.Run("wrong second parameter", func(t *testing.T) {
_, err := ParseUnbind([]smartcontract.Parameter{ _, err := ParseUnbind([]stackitem.Item{
{ stackitem.NewByteArray(user.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: user.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct", func(t *testing.T) { t.Run("correct", func(t *testing.T) {
ev, err := ParseUnbind([]smartcontract.Parameter{ ev, err := ParseUnbind([]stackitem.Item{
{ stackitem.NewByteArray(user.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewArray([]stackitem.Item{
Value: user.BytesBE(), stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[0])),
}, stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[1])),
{ stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[2])),
Type: smartcontract.ArrayType, }),
Value: []smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKeys[0]),
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKeys[1]),
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKeys[2]),
},
},
},
}) })
require.NoError(t, err) require.NoError(t, err)
expKeys := make([]*keys.PublicKey, len(publicKeys)) expKeys := make([]*keys.PublicKey, len(publicKeys))
for i := range publicKeys { for i := range publicKeys {
expKeys[i], err = keys.NewPublicKeyFromBytes(crypto.MarshalPublicKey(publicKeys[i]), elliptic.P256()) expKeys[i], err = keys.NewPublicKeyFromBytes(
crypto.MarshalPublicKey(publicKeys[i]), elliptic.P256())
require.NoError(t, err) require.NoError(t, err)
} }

View file

@ -1,8 +1,8 @@
package neofs package neofs
import ( import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -28,7 +28,7 @@ func (w Withdraw) User() util.Uint160 { return w.user }
func (w Withdraw) Amount() int64 { return w.amount } func (w Withdraw) Amount() int64 { return w.amount }
// ParseWithdraw notification into withdraw structure. // ParseWithdraw notification into withdraw structure.
func ParseWithdraw(params []smartcontract.Parameter) (event.Event, error) { func ParseWithdraw(params []stackitem.Item) (event.Event, error) {
var ev Withdraw var ev Withdraw
if ln := len(params); ln != 3 { if ln := len(params); ln != 3 {
@ -36,7 +36,7 @@ func ParseWithdraw(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse user // parse user
user, err := client.BytesFromStackParameter(params[0]) user, err := client.BytesFromStackItem(params[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get withdraw user") return nil, errors.Wrap(err, "could not get withdraw user")
} }
@ -47,13 +47,13 @@ func ParseWithdraw(params []smartcontract.Parameter) (event.Event, error) {
} }
// parse amount // parse amount
ev.amount, err = client.IntFromStackParameter(params[1]) ev.amount, err = client.IntFromStackItem(params[1])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get withdraw amount") return nil, errors.Wrap(err, "could not get withdraw amount")
} }
// parse id // parse id
ev.id, err = client.BytesFromStackParameter(params[2]) ev.id, err = client.BytesFromStackItem(params[2])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get withdraw id") return nil, errors.Wrap(err, "could not get withdraw id")
} }

View file

@ -1,10 +1,11 @@
package neofs package neofs
import ( import (
"math/big"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -18,9 +19,9 @@ func TestParseWithdraw(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
{}, stackitem.NewMap(),
} }
_, err := ParseWithdraw(prms) _, err := ParseWithdraw(prms)
@ -28,61 +29,37 @@ func TestParseWithdraw(t *testing.T) {
}) })
t.Run("wrong user parameter", func(t *testing.T) { t.Run("wrong user parameter", func(t *testing.T) {
_, err := ParseWithdraw([]smartcontract.Parameter{ _, err := ParseWithdraw([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong amount parameter", func(t *testing.T) { t.Run("wrong amount parameter", func(t *testing.T) {
_, err := ParseWithdraw([]smartcontract.Parameter{ _, err := ParseWithdraw([]stackitem.Item{
{ stackitem.NewByteArray(user.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewMap(),
Value: user.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong id parameter", func(t *testing.T) { t.Run("wrong id parameter", func(t *testing.T) {
_, err := ParseWithdraw([]smartcontract.Parameter{ _, err := ParseWithdraw([]stackitem.Item{
{ stackitem.NewByteArray(user.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
Value: user.BytesBE(), stackitem.NewMap(),
},
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseWithdraw([]smartcontract.Parameter{ ev, err := ParseWithdraw([]stackitem.Item{
{ stackitem.NewByteArray(user.BytesBE()),
Type: smartcontract.ByteArrayType, stackitem.NewBigInteger(new(big.Int).SetInt64(amount)),
Value: user.BytesBE(), stackitem.NewByteArray(id),
},
{
Type: smartcontract.IntegerType,
Value: amount,
},
{
Type: smartcontract.ByteArrayType,
Value: id,
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -1,7 +1,7 @@
package netmap package netmap
import ( 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/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -18,7 +18,7 @@ func (s AddPeer) Node() []byte {
return s.node return s.node
} }
func ParseAddPeer(prms []smartcontract.Parameter) (event.Event, error) { func ParseAddPeer(prms []stackitem.Item) (event.Event, error) {
var ( var (
ev AddPeer ev AddPeer
err error err error
@ -28,7 +28,7 @@ func ParseAddPeer(prms []smartcontract.Parameter) (event.Event, error) {
return nil, event.WrongNumberOfParameters(1, ln) return nil, event.WrongNumberOfParameters(1, ln)
} }
ev.node, err = client.BytesFromStackParameter(prms[0]) ev.node, err = client.BytesFromStackItem(prms[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get integer epoch number") return nil, errors.Wrap(err, "could not get integer epoch number")
} }

View file

@ -3,16 +3,16 @@ package netmap
import ( import (
"testing" "testing"
"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/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestParseAddPeer(t *testing.T) { func TestParseAddPeer(t *testing.T) {
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
{}, stackitem.NewMap(),
} }
_, err := ParseAddPeer(prms) _, err := ParseAddPeer(prms)
@ -20,10 +20,8 @@ func TestParseAddPeer(t *testing.T) {
}) })
t.Run("wrong first parameter type", func(t *testing.T) { t.Run("wrong first parameter type", func(t *testing.T) {
_, err := ParseAddPeer([]smartcontract.Parameter{ _, err := ParseAddPeer([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ByteArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
@ -32,11 +30,8 @@ func TestParseAddPeer(t *testing.T) {
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
info := []byte{1, 2, 3} info := []byte{1, 2, 3}
ev, err := ParseAddPeer([]smartcontract.Parameter{ ev, err := ParseAddPeer([]stackitem.Item{
{ stackitem.NewByteArray(info),
Type: smartcontract.ByteArrayType,
Value: info,
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -1,7 +1,7 @@
package netmap package netmap
import ( 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/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -23,12 +23,12 @@ func (s NewEpoch) EpochNumber() uint64 {
// ParseNewEpoch is a parser of new epoch notification event. // ParseNewEpoch is a parser of new epoch notification event.
// //
// Result is type of NewEpoch. // Result is type of NewEpoch.
func ParseNewEpoch(prms []smartcontract.Parameter) (event.Event, error) { func ParseNewEpoch(prms []stackitem.Item) (event.Event, error) {
if ln := len(prms); ln != 1 { if ln := len(prms); ln != 1 {
return nil, event.WrongNumberOfParameters(1, ln) return nil, event.WrongNumberOfParameters(1, ln)
} }
prmEpochNum, err := client.IntFromStackParameter(prms[0]) prmEpochNum, err := client.IntFromStackItem(prms[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get integer epoch number") return nil, errors.Wrap(err, "could not get integer epoch number")
} }

View file

@ -1,18 +1,19 @@
package netmap package netmap
import ( import (
"math/big"
"testing" "testing"
"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/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestParseNewEpoch(t *testing.T) { func TestParseNewEpoch(t *testing.T) {
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
{}, stackitem.NewMap(),
} }
_, err := ParseNewEpoch(prms) _, err := ParseNewEpoch(prms)
@ -20,10 +21,8 @@ func TestParseNewEpoch(t *testing.T) {
}) })
t.Run("wrong first parameter type", func(t *testing.T) { t.Run("wrong first parameter type", func(t *testing.T) {
_, err := ParseNewEpoch([]smartcontract.Parameter{ _, err := ParseNewEpoch([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ByteArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
@ -32,11 +31,8 @@ func TestParseNewEpoch(t *testing.T) {
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
epochNum := uint64(100) epochNum := uint64(100)
ev, err := ParseNewEpoch([]smartcontract.Parameter{ ev, err := ParseNewEpoch([]stackitem.Item{
{ stackitem.NewBigInteger(new(big.Int).SetUint64(epochNum)),
Type: smartcontract.IntegerType,
Value: int64(epochNum),
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -4,7 +4,7 @@ import (
"crypto/elliptic" "crypto/elliptic"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"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/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -26,7 +26,7 @@ func (s UpdatePeer) PublicKey() *keys.PublicKey {
return s.publicKey return s.publicKey
} }
func ParseUpdatePeer(prms []smartcontract.Parameter) (event.Event, error) { func ParseUpdatePeer(prms []stackitem.Item) (event.Event, error) {
var ( var (
ev UpdatePeer ev UpdatePeer
err error err error
@ -36,16 +36,8 @@ func ParseUpdatePeer(prms []smartcontract.Parameter) (event.Event, error) {
return nil, event.WrongNumberOfParameters(2, ln) return nil, event.WrongNumberOfParameters(2, ln)
} }
// parse node status
st, err := client.IntFromStackParameter(prms[0])
if err != nil {
return nil, errors.Wrap(err, "could not get node status")
}
ev.status = uint32(st)
// parse public key // parse public key
key, err := client.BytesFromStackParameter(prms[1]) key, err := client.BytesFromStackItem(prms[0])
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get public key") return nil, errors.Wrap(err, "could not get public key")
} }
@ -55,5 +47,13 @@ func ParseUpdatePeer(prms []smartcontract.Parameter) (event.Event, error) {
return nil, errors.Wrap(err, "could not parse public key") return nil, errors.Wrap(err, "could not parse public key")
} }
// parse node status
st, err := client.IntFromStackItem(prms[1])
if err != nil {
return nil, errors.Wrap(err, "could not get node status")
}
ev.status = uint32(st)
return ev, nil return ev, nil
} }

View file

@ -2,10 +2,11 @@ package netmap
import ( import (
"crypto/elliptic" "crypto/elliptic"
"math/big"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-crypto/test" "github.com/nspcc-dev/neofs-crypto/test"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
@ -19,8 +20,8 @@ func TestParseUpdatePeer(t *testing.T) {
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
prms := []smartcontract.Parameter{ prms := []stackitem.Item{
{}, stackitem.NewMap(),
} }
_, err := ParseUpdatePeer(prms) _, err := ParseUpdatePeer(prms)
@ -28,39 +29,26 @@ func TestParseUpdatePeer(t *testing.T) {
}) })
t.Run("wrong first parameter type", func(t *testing.T) { t.Run("wrong first parameter type", func(t *testing.T) {
_, err := ParseUpdatePeer([]smartcontract.Parameter{ _, err := ParseUpdatePeer([]stackitem.Item{
{ stackitem.NewMap(),
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("wrong second parameter type", func(t *testing.T) { t.Run("wrong second parameter type", func(t *testing.T) {
_, err := ParseUpdatePeer([]smartcontract.Parameter{ _, err := ParseUpdatePeer([]stackitem.Item{
{ stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
Type: smartcontract.IntegerType, stackitem.NewMap(),
Value: state,
},
{
Type: smartcontract.ArrayType,
},
}) })
require.Error(t, err) require.Error(t, err)
}) })
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseUpdatePeer([]smartcontract.Parameter{ ev, err := ParseUpdatePeer([]stackitem.Item{
{ stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
Type: smartcontract.IntegerType, stackitem.NewBigInteger(new(big.Int).SetInt64(state)),
Value: state,
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKey),
},
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -1,13 +1,13 @@
package event package event
import ( import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// Parser is a function that constructs Event // Parser is a function that constructs Event
// from the StackItem list. // from the StackItem list.
type Parser func([]smartcontract.Parameter) (Event, error) type Parser func([]stackitem.Item) (Event, error)
// ParserInfo is a structure that groups // ParserInfo is a structure that groups
// the parameters of particular contract // the parameters of particular contract

View file

@ -6,9 +6,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/rpc/client"
"github.com/nspcc-dev/neo-go/pkg/rpc/response" "github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -16,7 +16,7 @@ import (
type ( type (
// Subscriber is an interface of the NotificationEvent listener. // Subscriber is an interface of the NotificationEvent listener.
Subscriber interface { Subscriber interface {
SubscribeForNotification(...util.Uint160) (<-chan *result.NotificationEvent, error) SubscribeForNotification(...util.Uint160) (<-chan *state.NotificationEvent, error)
UnsubscribeForNotification() UnsubscribeForNotification()
Close() Close()
} }
@ -26,7 +26,7 @@ type (
log *zap.Logger log *zap.Logger
client *client.WSClient client *client.WSClient
notify chan *result.NotificationEvent notify chan *state.NotificationEvent
notifyIDs map[util.Uint160]string notifyIDs map[util.Uint160]string
} }
@ -44,7 +44,7 @@ var (
errNilLogger = errors.New("chain/subscriber: logger was not provided to the constructor") errNilLogger = errors.New("chain/subscriber: logger was not provided to the constructor")
) )
func (s *subscriber) SubscribeForNotification(contracts ...util.Uint160) (<-chan *result.NotificationEvent, error) { func (s *subscriber) SubscribeForNotification(contracts ...util.Uint160) (<-chan *state.NotificationEvent, error) {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
@ -114,7 +114,7 @@ func (s *subscriber) routeNotifications(ctx context.Context) {
switch notification.Type { switch notification.Type {
case response.NotificationEventID: case response.NotificationEventID:
notification, ok := notification.Value.(*result.NotificationEvent) notification, ok := notification.Value.(*state.NotificationEvent)
if !ok { if !ok {
s.log.Error("can't cast notify event to the notify struct") s.log.Error("can't cast notify event to the notify struct")
continue continue
@ -150,7 +150,7 @@ func New(ctx context.Context, p *Params) (Subscriber, error) {
RWMutex: new(sync.RWMutex), RWMutex: new(sync.RWMutex),
log: p.Log, log: p.Log,
client: wsClient, client: wsClient,
notify: make(chan *result.NotificationEvent), notify: make(chan *state.NotificationEvent),
notifyIDs: make(map[util.Uint160]string), notifyIDs: make(map[util.Uint160]string),
} }