[#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>
remotes/KirillovDenis/release/v0.21.1
Alex Vanin 2020-10-26 17:46:15 +03:00 committed by Alex Vanin
parent 2bd827a478
commit 174efc9df3
35 changed files with 309 additions and 841 deletions

2
go.mod
View File

@ -12,7 +12,7 @@ require (
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-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-crypto v0.3.0
github.com/nspcc-dev/tzhash v1.4.0

11
go.sum
View File

@ -179,6 +179,8 @@ github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
@ -265,14 +267,14 @@ github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxx
github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ=
github.com/nspcc-dev/dbft v0.0.0-20200711144034-c526ccc6f570 h1:EHBwlOyd2m06C3dnxhpPokpYqlNg7u5ZX/uPBhjYuZ4=
github.com/nspcc-dev/dbft v0.0.0-20200711144034-c526ccc6f570/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E=
github.com/nspcc-dev/dbft v0.0.0-20200925163137-8f3b9ab3b720 h1:e/lFQUIPnWErf2yiHjp2HyPhf0nyo3lp4hMm8IlQX1U=
github.com/nspcc-dev/dbft v0.0.0-20200925163137-8f3b9ab3b720/go.mod h1:I5D0W3tu3epdt2RMCTxS//HDr4S+OHRqajouQTOAHI8=
github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y=
github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU=
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg=
github.com/nspcc-dev/neo-go v0.91.0/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc=
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78 h1:stIa+nBXK8uDY/JZaxIZzAUfkzfaotVw2FbnHxO4aZI=
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc=
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201028111149-ac38d13f04ff h1:TBybhFCjTdSgpw0zGLw7ucjA3gTTLZDfp4D2trcSyT4=
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201028111149-ac38d13f04ff/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8=
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b h1:gk5bZgpWOehaDVKI5vBDkcjXTpRkKqcvIb1h/vHnBH4=
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b/go.mod h1:9s7LNp2lMgf0caH2t0sam4+WT2SIauXozwP0AdBqnEo=
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201029071528-352e99d9b91a h1:+fYK6dnV+ty2p/PoVLTgN2OgOeyFgl/fFYfIPXdvJYI=
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201029071528-352e99d9b91a/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8=
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
@ -574,7 +576,6 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
gopkg.in/abiosoft/ishell.v2 v2.0.0/go.mod h1:sFp+cGtH6o4s1FtpVPTMcHq2yue+c4DGOVohJCPUzwY=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -1,8 +1,6 @@
package client
import (
"encoding/hex"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
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
}
script, err := hex.DecodeString(resp.Script)
if err != nil {
return errScriptDecode
}
script := resp.Script
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{
DialTimeout: cfg.dialTimeout,
Network: cfg.magic,
})
if err != nil {
return nil, err
}
err = cli.Init() // magic number is set there based on RPC node answer
if err != nil {
return nil, err
}
return &Client{
logger: cfg.logger,
client: cli,

View File

@ -1,10 +1,8 @@
package client
import (
"encoding/binary"
"math/big"
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/pkg/errors"
)
@ -15,124 +13,6 @@ import (
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.
func BoolFromStackItem(param stackitem.Item) (bool, error) {
switch param.Type() {

View File

@ -6,52 +6,11 @@ import (
"testing"
"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/stretchr/testify/require"
)
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))
stringByteItem = stackitem.NewByteArray([]byte("Hello World"))
@ -66,101 +25,6 @@ var (
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) {
t.Run("true assert", func(t *testing.T) {
val, err := BoolFromStackItem(trueBoolItem)

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import (
"crypto/elliptic"
"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/event"
"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 }
// ParsePut from notification into container event structure.
func ParsePut(params []smartcontract.Parameter) (event.Event, error) {
func ParsePut(params []stackitem.Item) (event.Event, error) {
var (
ev Put
err error
@ -41,19 +41,19 @@ func ParsePut(params []smartcontract.Parameter) (event.Event, error) {
}
// parse container
ev.rawContainer, err = client.BytesFromStackParameter(params[0])
ev.rawContainer, err = client.BytesFromStackItem(params[0])
if err != nil {
return nil, errors.Wrap(err, "could not get container")
}
// parse signature
ev.signature, err = client.BytesFromStackParameter(params[1])
ev.signature, err = client.BytesFromStackItem(params[1])
if err != nil {
return nil, errors.Wrap(err, "could not get signature")
}
// parse public key
key, err := client.BytesFromStackParameter(params[2])
key, err := client.BytesFromStackItem(params[2])
if err != nil {
return nil, errors.Wrap(err, "could not get public key")
}

View File

@ -5,7 +5,7 @@ import (
"testing"
"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"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"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) {
prms := []smartcontract.Parameter{
{},
{},
prms := []stackitem.Item{
stackitem.NewMap(),
stackitem.NewMap(),
}
_, err := ParsePut(prms)
@ -30,61 +30,37 @@ func TestParsePut(t *testing.T) {
})
t.Run("wrong container parameter", func(t *testing.T) {
_, err := ParsePut([]smartcontract.Parameter{
{
Type: smartcontract.ArrayType,
},
_, err := ParsePut([]stackitem.Item{
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("wrong signature parameter", func(t *testing.T) {
_, err := ParsePut([]smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
Value: containerData,
},
{
Type: smartcontract.ArrayType,
},
_, err := ParsePut([]stackitem.Item{
stackitem.NewByteArray(containerData),
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("wrong key parameter", func(t *testing.T) {
_, err := ParsePut([]smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
Value: containerData,
},
{
Type: smartcontract.ByteArrayType,
Value: signature,
},
{
Type: smartcontract.ArrayType,
},
_, err := ParsePut([]stackitem.Item{
stackitem.NewByteArray(containerData),
stackitem.NewByteArray(signature),
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("correct behavior", func(t *testing.T) {
ev, err := ParsePut([]smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
Value: containerData,
},
{
Type: smartcontract.ByteArrayType,
Value: signature,
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKey),
},
ev, err := ParsePut([]stackitem.Item{
stackitem.NewByteArray(containerData),
stackitem.NewByteArray(signature),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
})
require.NoError(t, err)

View File

@ -4,7 +4,7 @@ import (
"context"
"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/neofs-node/pkg/morph/client"
"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
}
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:
for {
select {
@ -170,13 +170,13 @@ loop:
}
}
func (s listener) parseAndHandle(notifyEvent *result.NotificationEvent) {
func (s listener) parseAndHandle(notifyEvent *state.NotificationEvent) {
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
arr, err := client.ArrayFromStackParameter(notifyEvent.Item)
arr, err := client.ArrayFromStackItem(notifyEvent.Item)
if err != nil {
log.Warn("stack item is not an array type",
zap.String("error", err.Error()),
@ -197,7 +197,7 @@ func (s listener) parseAndHandle(notifyEvent *result.NotificationEvent) {
// get the event parser
keyEvent := scriptHashWithType{}
keyEvent.SetScriptHash(notifyEvent.Contract)
keyEvent.SetScriptHash(notifyEvent.ScriptHash)
keyEvent.SetType(typEvent)
s.mtx.RLock()

View File

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

View File

@ -6,8 +6,8 @@ import (
"testing"
"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/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"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) {
prms := []smartcontract.Parameter{
{},
prms := []stackitem.Item{
stackitem.NewMap(),
}
_, err := ParseBind(prms)
@ -34,58 +34,38 @@ func TestParseBind(t *testing.T) {
})
t.Run("wrong first parameter", func(t *testing.T) {
_, err := ParseBind([]smartcontract.Parameter{
{
Type: smartcontract.ArrayType,
},
_, err := ParseBind([]stackitem.Item{
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("wrong second parameter", func(t *testing.T) {
_, err := ParseBind([]smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
_, err := ParseBind([]stackitem.Item{
stackitem.NewByteArray(user.BytesBE()),
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("correct", func(t *testing.T) {
ev, err := ParseBind([]smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
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]),
},
},
},
ev, err := ParseBind([]stackitem.Item{
stackitem.NewByteArray(user.BytesBE()),
stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[0])),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[1])),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[2])),
}),
})
require.NoError(t, err)
expKeys := make([]*keys.PublicKey, len(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)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import (
"testing"
"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"
"github.com/nspcc-dev/neofs-crypto/test"
"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) {
prms := []smartcontract.Parameter{
{},
{},
prms := []stackitem.Item{
stackitem.NewMap(),
stackitem.NewMap(),
}
_, err := ParseUpdateInnerRing(prms)
@ -33,40 +33,27 @@ func TestParseUpdateInnerRing(t *testing.T) {
})
t.Run("wrong first parameter", func(t *testing.T) {
_, err := ParseUpdateInnerRing([]smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
},
_, err := ParseUpdateInnerRing([]stackitem.Item{
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("correct", func(t *testing.T) {
ev, err := ParseUpdateInnerRing([]smartcontract.Parameter{
{
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]),
},
},
},
ev, err := ParseUpdateInnerRing([]stackitem.Item{
stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[0])),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[1])),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[2])),
}),
})
require.NoError(t, err)
expKeys := make([]*keys.PublicKey, len(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)
}

View File

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

View File

@ -6,8 +6,8 @@ import (
"testing"
"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/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"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) {
prms := []smartcontract.Parameter{
{},
prms := []stackitem.Item{
stackitem.NewMap(),
}
_, err := ParseUnbind(prms)
@ -34,58 +34,37 @@ func TestParseUnbind(t *testing.T) {
})
t.Run("wrong first parameter", func(t *testing.T) {
_, err := ParseUnbind([]smartcontract.Parameter{
{
Type: smartcontract.ArrayType,
},
_, err := ParseUnbind([]stackitem.Item{
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("wrong second parameter", func(t *testing.T) {
_, err := ParseUnbind([]smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
Type: smartcontract.ArrayType,
},
_, err := ParseUnbind([]stackitem.Item{
stackitem.NewByteArray(user.BytesBE()),
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("correct", func(t *testing.T) {
ev, err := ParseUnbind([]smartcontract.Parameter{
{
Type: smartcontract.ByteArrayType,
Value: user.BytesBE(),
},
{
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]),
},
},
},
ev, err := ParseUnbind([]stackitem.Item{
stackitem.NewByteArray(user.BytesBE()),
stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[0])),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[1])),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[2])),
}),
})
require.NoError(t, err)
expKeys := make([]*keys.PublicKey, len(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)
}

View File

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

View File

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

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

View File

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

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

View File

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

View File

@ -4,7 +4,7 @@ import (
"crypto/elliptic"
"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/event"
"github.com/pkg/errors"
@ -26,7 +26,7 @@ func (s UpdatePeer) PublicKey() *keys.PublicKey {
return s.publicKey
}
func ParseUpdatePeer(prms []smartcontract.Parameter) (event.Event, error) {
func ParseUpdatePeer(prms []stackitem.Item) (event.Event, error) {
var (
ev UpdatePeer
err error
@ -36,16 +36,8 @@ func ParseUpdatePeer(prms []smartcontract.Parameter) (event.Event, error) {
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
key, err := client.BytesFromStackParameter(prms[1])
key, err := client.BytesFromStackItem(prms[0])
if err != nil {
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")
}
// 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
}

View File

@ -2,10 +2,11 @@ package netmap
import (
"crypto/elliptic"
"math/big"
"testing"
"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"
"github.com/nspcc-dev/neofs-crypto/test"
"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) {
prms := []smartcontract.Parameter{
{},
prms := []stackitem.Item{
stackitem.NewMap(),
}
_, err := ParseUpdatePeer(prms)
@ -28,39 +29,26 @@ func TestParseUpdatePeer(t *testing.T) {
})
t.Run("wrong first parameter type", func(t *testing.T) {
_, err := ParseUpdatePeer([]smartcontract.Parameter{
{
Type: smartcontract.ArrayType,
},
_, err := ParseUpdatePeer([]stackitem.Item{
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("wrong second parameter type", func(t *testing.T) {
_, err := ParseUpdatePeer([]smartcontract.Parameter{
{
Type: smartcontract.IntegerType,
Value: state,
},
{
Type: smartcontract.ArrayType,
},
_, err := ParseUpdatePeer([]stackitem.Item{
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
stackitem.NewMap(),
})
require.Error(t, err)
})
t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseUpdatePeer([]smartcontract.Parameter{
{
Type: smartcontract.IntegerType,
Value: state,
},
{
Type: smartcontract.ByteArrayType,
Value: crypto.MarshalPublicKey(publicKey),
},
ev, err := ParseUpdatePeer([]stackitem.Item{
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
stackitem.NewBigInteger(new(big.Int).SetInt64(state)),
})
require.NoError(t, err)

View File

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

View File

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