From 05b45270c8ea6ca5ab407c4fd872c958b5e4917a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 8 Apr 2021 17:40:49 +0300 Subject: [PATCH] [#468] Update neo-go to v0.94.1 New neo-go version provides: - new type for roles in `RoleManagement` contract, - methods to get keys from `RoleManagement` contract, - new way to sign notary transaction. Signed-off-by: Alex Vanin --- go.mod | 2 +- go.sum | Bin 59867 -> 59619 bytes pkg/morph/client/client.go | 68 +++----------------------------- pkg/morph/client/constructor.go | 6 --- pkg/morph/client/notary.go | 10 ++--- 5 files changed, 11 insertions(+), 75 deletions(-) diff --git a/go.mod b/go.mod index 7be2a9521..944ca72ff 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( 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/hrw v1.0.9 - github.com/nspcc-dev/neo-go v0.94.0 + github.com/nspcc-dev/neo-go v0.94.1 github.com/nspcc-dev/neofs-api-go v1.25.1-0.20210402125759-771f395d9d4e github.com/nspcc-dev/neofs-crypto v0.3.0 github.com/nspcc-dev/tzhash v1.4.0 diff --git a/go.sum b/go.sum index a2f93c73d3f63988489d41998e9cdc8d13039580..59f1cd4649becb0191e79d54d71c9645c9dee611 100644 GIT binary patch delta 93 zcmV-j0HXif(*xtt1F-W6lSK-;vsDYeB$NCy3$t!8(K#Y zT3ngqnGMt18G*i9+ diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index d1d9fea04..6587d5dec 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -2,10 +2,9 @@ package client import ( "context" - "crypto/elliptic" "time" - "github.com/nspcc-dev/neo-go/pkg/core/native" + "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" @@ -35,8 +34,6 @@ type Client struct { gas util.Uint160 // native gas script-hash - neo util.Uint160 // native neo script-hash - designate util.Uint160 // native designate script-hash waitInterval time.Duration @@ -51,11 +48,6 @@ var ErrNilClient = errors.New("client is nil") // HaltState returned if TestInvoke function processed without panic. const HaltState = "HALT" -const ( - committeeList = "getCommittee" - designateList = "getDesignatedByRole" -) - var errEmptyInvocationScript = errors.New("got empty invocation script from neo node") var errScriptDecode = errors.New("could not decode invocation script from neo node") @@ -204,24 +196,14 @@ func (c *Client) GasBalance() (int64, error) { // Committee returns keys of chain committee from neo native contract. func (c *Client) Committee() (keys.PublicKeys, error) { - items, err := c.TestInvoke(c.neo, committeeList) - if err != nil { - return nil, err - } - - roleKeys, err := keysFromStack(items) - if err != nil { - return nil, errors.Wrap(err, "can't get committee keys") - } - - return roleKeys, nil + return c.client.GetCommittee() } // NeoFSAlphabetList returns keys that stored in NeoFS Alphabet role. Main chain // stores alphabet node keys of inner ring there, however side chain stores both // alphabet and non alphabet node keys of inner ring. func (c *Client) NeoFSAlphabetList() (keys.PublicKeys, error) { - list, err := c.roleList(native.RoleNeoFSAlphabet) + list, err := c.roleList(noderoles.NeoFSAlphabet) if err != nil { return nil, errors.Wrap(err, "can't get alphabet nodes role list") } @@ -229,23 +211,13 @@ func (c *Client) NeoFSAlphabetList() (keys.PublicKeys, error) { return list, nil } -func (c *Client) roleList(r native.Role) (keys.PublicKeys, error) { +func (c *Client) roleList(r noderoles.Role) (keys.PublicKeys, error) { height, err := c.client.GetBlockCount() if err != nil { return nil, errors.Wrap(err, "can't get chain height") } - items, err := c.TestInvoke(c.designate, designateList, r, int64(height)) - if err != nil { - return nil, err - } - - roleKeys, err := keysFromStack(items) - if err != nil { - return nil, errors.Wrap(err, "can't get role keys") - } - - return roleKeys, nil + return c.client.GetDesignatedByRole(r, height) } func toStackParameter(value interface{}) (sc.Parameter, error) { @@ -277,7 +249,7 @@ func toStackParameter(value interface{}) (sc.Parameter, error) { case util.Uint160: result.Type = sc.ByteArrayType result.Value = v.BytesBE() - case native.Role: + case noderoles.Role: result.Type = sc.IntegerType result.Value = int64(v) case keys.PublicKeys: @@ -294,34 +266,6 @@ func toStackParameter(value interface{}) (sc.Parameter, error) { return result, nil } -func keysFromStack(data []stackitem.Item) (keys.PublicKeys, error) { - if len(data) == 0 { - return nil, nil - } - - arr, err := ArrayFromStackItem(data[0]) - if err != nil { - return nil, errors.Wrap(err, "non array element on stack") - } - - res := make([]*keys.PublicKey, 0, len(arr)) - for i := range arr { - rawKey, err := BytesFromStackItem(arr[i]) - if err != nil { - return nil, errors.Wrap(err, "key is not slice of bytes") - } - - key, err := keys.NewPublicKeyFromBytes(rawKey, elliptic.P256()) - if err != nil { - return nil, errors.Wrap(err, "can't parse key") - } - - res = append(res, key) - } - - return res, nil -} - // MagicNumber returns the magic number of the network // to which the underlying RPC node client is connected. func (c *Client) MagicNumber() uint64 { diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 573d81a96..10915a219 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -100,11 +100,6 @@ func New(key *ecdsa.PrivateKey, endpoint string, opts ...Option) (*Client, error return nil, err } - neo, err := cli.GetNativeContractHash(nativenames.Neo) - if err != nil { - return nil, err - } - designate, err := cli.GetNativeContractHash(nativenames.Designation) if err != nil { return nil, err @@ -115,7 +110,6 @@ func New(key *ecdsa.PrivateKey, endpoint string, opts ...Option) (*Client, error client: cli, acc: account, gas: gas, - neo: neo, designate: designate, waitInterval: cfg.waitInterval, }, nil diff --git a/pkg/morph/client/notary.go b/pkg/morph/client/notary.go index 72b25029e..b55f8cae0 100644 --- a/pkg/morph/client/notary.go +++ b/pkg/morph/client/notary.go @@ -1,8 +1,8 @@ package client import ( - "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" + "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -50,7 +50,6 @@ const ( var ( errNotaryNotEnabled = errors.New("notary support was not enabled on this client") - errInvalidIR = errors.New("invalid inner ring list from netmap contract") errUnexpectedItems = errors.New("invalid number of NEO VM arguments on stack") ) @@ -159,7 +158,7 @@ func (c *Client) UpdateNotaryList(list keys.PublicKeys) error { return c.notaryInvokeAsCommittee(c.designate, setDesignateMethod, - native.RoleP2PNotary, + noderoles.P2PNotary, list, ) } @@ -174,7 +173,7 @@ func (c *Client) UpdateNeoFSAlphabetList(list keys.PublicKeys) error { return c.notaryInvokeAsCommittee(c.designate, setDesignateMethod, - native.RoleNeoFSAlphabet, + noderoles.NeoFSAlphabet, list, ) } @@ -253,7 +252,6 @@ func (c *Client) notaryInvoke(committee bool, contract util.Uint160, method stri }, }, Signers: cosigners, - Network: c.client.GetNetwork(), } // calculate notary fee @@ -366,7 +364,7 @@ func (c *Client) notaryWitnesses(multiaddr *wallet.Account, tx *transaction.Tran w = append(w, transaction.Witness{ InvocationScript: append( []byte{byte(opcode.PUSHDATA1), 64}, - multiaddr.PrivateKey().Sign(tx.GetSignedPart())..., + multiaddr.PrivateKey().SignHashable(uint32(c.client.GetNetwork()), tx)..., ), VerificationScript: multiaddr.GetVerificationScript(), })