forked from TrueCloudLab/frostfs-node
[#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:
parent
60cc3b3e16
commit
05b45270c8
5 changed files with 11 additions and 75 deletions
2
go.mod
2
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-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/hrw v1.0.9
|
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-api-go v1.25.1-0.20210402125759-771f395d9d4e
|
||||||
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
BIN
go.sum
Binary file not shown.
|
@ -2,10 +2,9 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/elliptic"
|
|
||||||
"time"
|
"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/core/transaction"
|
||||||
"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/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
|
@ -35,8 +34,6 @@ type Client struct {
|
||||||
|
|
||||||
gas util.Uint160 // native gas script-hash
|
gas util.Uint160 // native gas script-hash
|
||||||
|
|
||||||
neo util.Uint160 // native neo script-hash
|
|
||||||
|
|
||||||
designate util.Uint160 // native designate script-hash
|
designate util.Uint160 // native designate script-hash
|
||||||
|
|
||||||
waitInterval time.Duration
|
waitInterval time.Duration
|
||||||
|
@ -51,11 +48,6 @@ var ErrNilClient = errors.New("client is nil")
|
||||||
// HaltState returned if TestInvoke function processed without panic.
|
// HaltState returned if TestInvoke function processed without panic.
|
||||||
const HaltState = "HALT"
|
const HaltState = "HALT"
|
||||||
|
|
||||||
const (
|
|
||||||
committeeList = "getCommittee"
|
|
||||||
designateList = "getDesignatedByRole"
|
|
||||||
)
|
|
||||||
|
|
||||||
var errEmptyInvocationScript = errors.New("got empty invocation script from neo node")
|
var errEmptyInvocationScript = errors.New("got empty invocation script from neo node")
|
||||||
|
|
||||||
var errScriptDecode = errors.New("could not decode 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.
|
// Committee returns keys of chain committee from neo native contract.
|
||||||
func (c *Client) Committee() (keys.PublicKeys, error) {
|
func (c *Client) Committee() (keys.PublicKeys, error) {
|
||||||
items, err := c.TestInvoke(c.neo, committeeList)
|
return c.client.GetCommittee()
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeoFSAlphabetList returns keys that stored in NeoFS Alphabet role. Main chain
|
// NeoFSAlphabetList returns keys that stored in NeoFS Alphabet role. Main chain
|
||||||
// stores alphabet node keys of inner ring there, however side chain stores both
|
// stores alphabet node keys of inner ring there, however side chain stores both
|
||||||
// alphabet and non alphabet node keys of inner ring.
|
// alphabet and non alphabet node keys of inner ring.
|
||||||
func (c *Client) NeoFSAlphabetList() (keys.PublicKeys, error) {
|
func (c *Client) NeoFSAlphabetList() (keys.PublicKeys, error) {
|
||||||
list, err := c.roleList(native.RoleNeoFSAlphabet)
|
list, err := c.roleList(noderoles.NeoFSAlphabet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "can't get alphabet nodes role list")
|
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
|
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()
|
height, err := c.client.GetBlockCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "can't get chain height")
|
return nil, errors.Wrap(err, "can't get chain height")
|
||||||
}
|
}
|
||||||
|
|
||||||
items, err := c.TestInvoke(c.designate, designateList, r, int64(height))
|
return c.client.GetDesignatedByRole(r, 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func toStackParameter(value interface{}) (sc.Parameter, error) {
|
func toStackParameter(value interface{}) (sc.Parameter, error) {
|
||||||
|
@ -277,7 +249,7 @@ func toStackParameter(value interface{}) (sc.Parameter, error) {
|
||||||
case util.Uint160:
|
case util.Uint160:
|
||||||
result.Type = sc.ByteArrayType
|
result.Type = sc.ByteArrayType
|
||||||
result.Value = v.BytesBE()
|
result.Value = v.BytesBE()
|
||||||
case native.Role:
|
case noderoles.Role:
|
||||||
result.Type = sc.IntegerType
|
result.Type = sc.IntegerType
|
||||||
result.Value = int64(v)
|
result.Value = int64(v)
|
||||||
case keys.PublicKeys:
|
case keys.PublicKeys:
|
||||||
|
@ -294,34 +266,6 @@ func toStackParameter(value interface{}) (sc.Parameter, error) {
|
||||||
return result, nil
|
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
|
// MagicNumber returns the magic number of the network
|
||||||
// to which the underlying RPC node client is connected.
|
// to which the underlying RPC node client is connected.
|
||||||
func (c *Client) MagicNumber() uint64 {
|
func (c *Client) MagicNumber() uint64 {
|
||||||
|
|
|
@ -100,11 +100,6 @@ func New(key *ecdsa.PrivateKey, endpoint string, opts ...Option) (*Client, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
neo, err := cli.GetNativeContractHash(nativenames.Neo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
designate, err := cli.GetNativeContractHash(nativenames.Designation)
|
designate, err := cli.GetNativeContractHash(nativenames.Designation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -115,7 +110,6 @@ func New(key *ecdsa.PrivateKey, endpoint string, opts ...Option) (*Client, error
|
||||||
client: cli,
|
client: cli,
|
||||||
acc: account,
|
acc: account,
|
||||||
gas: gas,
|
gas: gas,
|
||||||
neo: neo,
|
|
||||||
designate: designate,
|
designate: designate,
|
||||||
waitInterval: cfg.waitInterval,
|
waitInterval: cfg.waitInterval,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
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/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/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
@ -50,7 +50,6 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNotaryNotEnabled = errors.New("notary support was not enabled on this client")
|
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")
|
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,
|
return c.notaryInvokeAsCommittee(c.designate,
|
||||||
setDesignateMethod,
|
setDesignateMethod,
|
||||||
native.RoleP2PNotary,
|
noderoles.P2PNotary,
|
||||||
list,
|
list,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -174,7 +173,7 @@ func (c *Client) UpdateNeoFSAlphabetList(list keys.PublicKeys) error {
|
||||||
|
|
||||||
return c.notaryInvokeAsCommittee(c.designate,
|
return c.notaryInvokeAsCommittee(c.designate,
|
||||||
setDesignateMethod,
|
setDesignateMethod,
|
||||||
native.RoleNeoFSAlphabet,
|
noderoles.NeoFSAlphabet,
|
||||||
list,
|
list,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -253,7 +252,6 @@ func (c *Client) notaryInvoke(committee bool, contract util.Uint160, method stri
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Signers: cosigners,
|
Signers: cosigners,
|
||||||
Network: c.client.GetNetwork(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate notary fee
|
// calculate notary fee
|
||||||
|
@ -366,7 +364,7 @@ func (c *Client) notaryWitnesses(multiaddr *wallet.Account, tx *transaction.Tran
|
||||||
w = append(w, transaction.Witness{
|
w = append(w, transaction.Witness{
|
||||||
InvocationScript: append(
|
InvocationScript: append(
|
||||||
[]byte{byte(opcode.PUSHDATA1), 64},
|
[]byte{byte(opcode.PUSHDATA1), 64},
|
||||||
multiaddr.PrivateKey().Sign(tx.GetSignedPart())...,
|
multiaddr.PrivateKey().SignHashable(uint32(c.client.GetNetwork()), tx)...,
|
||||||
),
|
),
|
||||||
VerificationScript: multiaddr.GetVerificationScript(),
|
VerificationScript: multiaddr.GetVerificationScript(),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue