[#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 <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-08 17:40:49 +03:00 committed by Alex Vanin
parent 60cc3b3e16
commit 05b45270c8
5 changed files with 11 additions and 75 deletions

2
go.mod
View file

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

BIN
go.sum

Binary file not shown.

View file

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

View file

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

View file

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