2020-07-24 13:54:03 +00:00
|
|
|
package client
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
import (
|
2021-02-25 16:50:10 +00:00
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2021-04-09 20:10:59 +00:00
|
|
|
"fmt"
|
2021-02-25 16:50:10 +00:00
|
|
|
"time"
|
|
|
|
|
2021-08-26 07:59:02 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
2021-04-08 14:40:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
2020-07-10 14:17:51 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2021-03-09 14:45:35 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-12-11 08:33:27 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
2020-07-10 14:17:51 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
|
|
|
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
2021-04-27 11:07:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
2020-07-10 14:17:51 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2021-04-27 11:07:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
2020-08-27 11:57:13 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-07-10 14:17:51 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
2020-07-24 13:54:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2020-07-10 14:17:51 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-08-26 07:59:02 +00:00
|
|
|
// Client is a wrapper over multiple neo-go clients
|
|
|
|
// that provides smart-contract invocation interface.
|
|
|
|
//
|
|
|
|
// Each operation accesses all nodes in turn until the first success,
|
|
|
|
// and returns the error of the very first client on failure.
|
2020-07-24 13:54:03 +00:00
|
|
|
//
|
|
|
|
// Working client must be created via constructor New.
|
|
|
|
// Using the Client that has been created with new(Client)
|
|
|
|
// expression (or just declaring a Client variable) is unsafe
|
|
|
|
// and can lead to panic.
|
|
|
|
type Client struct {
|
2021-08-26 07:59:02 +00:00
|
|
|
// two mutual exclusive modes, exactly one must be non-nil
|
|
|
|
|
|
|
|
*singleClient // works with single neo-go client
|
|
|
|
|
|
|
|
*multiClient // creates and caches single clients
|
|
|
|
}
|
|
|
|
|
|
|
|
type singleClient struct {
|
2020-07-24 13:54:03 +00:00
|
|
|
logger *logger.Logger // logging component
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
client *client.Client // neo-go client
|
|
|
|
|
|
|
|
acc *wallet.Account // neo account
|
|
|
|
|
2021-02-25 16:50:10 +00:00
|
|
|
waitInterval time.Duration
|
|
|
|
|
2021-08-05 14:17:54 +00:00
|
|
|
signer *transaction.Signer
|
|
|
|
|
2021-02-20 10:22:59 +00:00
|
|
|
notary *notary
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2021-09-21 14:30:45 +00:00
|
|
|
func blankSingleClient(cli *client.Client, w *wallet.Account, cfg *cfg) *singleClient {
|
|
|
|
return &singleClient{
|
|
|
|
logger: cfg.logger,
|
|
|
|
client: cli,
|
|
|
|
acc: w,
|
|
|
|
waitInterval: cfg.waitInterval,
|
|
|
|
signer: cfg.signer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
// ErrNilClient is returned by functions that expect
|
2020-07-24 13:54:03 +00:00
|
|
|
// a non-nil Client pointer, but received nil.
|
|
|
|
var ErrNilClient = errors.New("client is nil")
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
// HaltState returned if TestInvoke function processed without panic.
|
|
|
|
const HaltState = "HALT"
|
|
|
|
|
2021-06-15 13:47:57 +00:00
|
|
|
type notHaltStateError struct {
|
2021-04-09 20:10:59 +00:00
|
|
|
state, exception string
|
|
|
|
}
|
|
|
|
|
2021-06-15 13:47:57 +00:00
|
|
|
func (e *notHaltStateError) Error() string {
|
2021-04-09 20:10:59 +00:00
|
|
|
return fmt.Sprintf(
|
|
|
|
"chain/client: contract execution finished with state %s; exception: %s",
|
|
|
|
e.state,
|
|
|
|
e.exception,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
var errEmptyInvocationScript = errors.New("got empty invocation script from neo node")
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
var errScriptDecode = errors.New("could not decode invocation script from neo node")
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2021-08-31 10:16:25 +00:00
|
|
|
// implementation of error interface for NeoFS-specific errors.
|
|
|
|
type neofsError struct {
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e neofsError) Error() string {
|
|
|
|
return fmt.Sprintf("neofs error: %v", e.err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// wraps NeoFS-specific error into neofsError. Arg must not be nil.
|
|
|
|
func wrapNeoFSError(err error) error {
|
|
|
|
return neofsError{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
// unwraps NeoFS-specific error if err is type of neofsError. Otherwise, returns nil.
|
|
|
|
func unwrapNeoFSError(err error) error {
|
|
|
|
if e := new(neofsError); errors.As(err, e) {
|
|
|
|
return e.err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
// Invoke invokes contract method by sending transaction into blockchain.
|
|
|
|
// Supported args types: int64, string, util.Uint160, []byte and bool.
|
2020-12-11 08:33:27 +00:00
|
|
|
func (c *Client) Invoke(contract util.Uint160, fee fixedn.Fixed8, method string, args ...interface{}) error {
|
2021-08-26 07:59:02 +00:00
|
|
|
if c.multiClient != nil {
|
|
|
|
return c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
return c.Invoke(contract, fee, method, args...)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
params := make([]sc.Parameter, 0, len(args))
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
for i := range args {
|
|
|
|
param, err := toStackParameter(args[i])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
params = append(params, param)
|
|
|
|
}
|
|
|
|
|
2020-08-27 11:57:13 +00:00
|
|
|
cosigner := []transaction.Signer{
|
2020-07-10 14:17:51 +00:00
|
|
|
{
|
2021-08-05 14:17:54 +00:00
|
|
|
Account: c.acc.PrivateKey().PublicKey().GetScriptHash(),
|
|
|
|
Scopes: c.signer.Scopes,
|
|
|
|
AllowedContracts: c.signer.AllowedContracts,
|
|
|
|
AllowedGroups: c.signer.AllowedGroups,
|
2020-07-10 14:17:51 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-16 15:39:33 +00:00
|
|
|
cosignerAcc := []client.SignerAccount{
|
|
|
|
{
|
|
|
|
Signer: cosigner[0],
|
|
|
|
Account: c.acc,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
resp, err := c.client.InvokeFunction(contract, method, params, cosigner)
|
2020-07-10 14:17:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-15 13:26:33 +00:00
|
|
|
if resp.State != HaltState {
|
2021-08-31 10:16:25 +00:00
|
|
|
return wrapNeoFSError(¬HaltStateError{state: resp.State, exception: resp.FaultException})
|
2021-06-15 13:26:33 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
if len(resp.Script) == 0 {
|
2021-08-31 10:16:25 +00:00
|
|
|
return wrapNeoFSError(errEmptyInvocationScript)
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
script := resp.Script
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
sysFee := resp.GasConsumed + int64(fee) // consumed gas + extra fee
|
|
|
|
|
2021-03-16 15:39:33 +00:00
|
|
|
txHash, err := c.client.SignAndPushInvocationTx(script, c.acc, sysFee, 0, cosignerAcc)
|
2020-07-10 14:17:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
c.logger.Debug("neo client invoke",
|
2020-07-10 14:17:51 +00:00
|
|
|
zap.String("method", method),
|
2020-12-04 16:36:41 +00:00
|
|
|
zap.Stringer("tx_hash", txHash.Reverse()))
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestInvoke invokes contract method locally in neo-go node. This method should
|
|
|
|
// be used to read data from smart-contract.
|
2021-08-26 07:59:02 +00:00
|
|
|
func (c *Client) TestInvoke(contract util.Uint160, method string, args ...interface{}) (res []stackitem.Item, err error) {
|
|
|
|
if c.multiClient != nil {
|
|
|
|
return res, c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
res, err = c.TestInvoke(contract, method, args...)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
var params = make([]sc.Parameter, 0, len(args))
|
|
|
|
|
|
|
|
for i := range args {
|
|
|
|
p, err := toStackParameter(args[i])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
params = append(params, p)
|
|
|
|
}
|
|
|
|
|
2020-08-27 11:57:13 +00:00
|
|
|
cosigner := []transaction.Signer{
|
2020-07-10 14:17:51 +00:00
|
|
|
{
|
|
|
|
Account: c.acc.PrivateKey().PublicKey().GetScriptHash(),
|
|
|
|
Scopes: transaction.Global,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
val, err := c.client.InvokeFunction(contract, method, params, cosigner)
|
2020-07-10 14:17:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if val.State != HaltState {
|
2021-08-31 10:16:25 +00:00
|
|
|
return nil, wrapNeoFSError(¬HaltStateError{state: val.State, exception: val.FaultException})
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return val.Stack, nil
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// TransferGas to the receiver from local wallet
|
2020-12-11 08:33:27 +00:00
|
|
|
func (c *Client) TransferGas(receiver util.Uint160, amount fixedn.Fixed8) error {
|
2021-08-26 07:59:02 +00:00
|
|
|
if c.multiClient != nil {
|
|
|
|
return c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
return c.TransferGas(receiver, amount)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-02 06:57:19 +00:00
|
|
|
gas, err := c.client.GetNativeContractHash(nativenames.Gas)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
txHash, err := c.client.TransferNEP17(c.acc, receiver, gas, int64(amount), 0, nil, nil)
|
2020-07-10 14:17:51 +00:00
|
|
|
if err != nil {
|
2020-07-24 13:54:03 +00:00
|
|
|
return err
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
c.logger.Debug("native gas transfer invoke",
|
|
|
|
zap.String("to", receiver.StringLE()),
|
2021-04-02 11:27:26 +00:00
|
|
|
zap.Stringer("tx_hash", txHash.Reverse()))
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
return nil
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 16:50:10 +00:00
|
|
|
// Wait function blocks routing execution until there
|
|
|
|
// are `n` new blocks in the chain.
|
2021-08-26 07:59:02 +00:00
|
|
|
//
|
|
|
|
// Returns only connection errors.
|
|
|
|
func (c *Client) Wait(ctx context.Context, n uint32) error {
|
|
|
|
if c.multiClient != nil {
|
|
|
|
return c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
return c.Wait(ctx, n)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-25 16:50:10 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
height, newHeight uint32
|
|
|
|
)
|
|
|
|
|
|
|
|
height, err = c.client.GetBlockCount()
|
|
|
|
if err != nil {
|
|
|
|
c.logger.Error("can't get blockchain height",
|
|
|
|
zap.String("error", err.Error()))
|
2021-08-26 07:59:02 +00:00
|
|
|
return nil
|
2021-02-25 16:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2021-08-26 07:59:02 +00:00
|
|
|
return nil
|
2021-02-25 16:50:10 +00:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
newHeight, err = c.client.GetBlockCount()
|
|
|
|
if err != nil {
|
|
|
|
c.logger.Error("can't get blockchain height",
|
|
|
|
zap.String("error", err.Error()))
|
2021-08-26 07:59:02 +00:00
|
|
|
return nil
|
2021-02-25 16:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if newHeight >= height+n {
|
2021-08-26 07:59:02 +00:00
|
|
|
return nil
|
2021-02-25 16:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(c.waitInterval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GasBalance returns GAS amount in the client's wallet.
|
2021-08-26 07:59:02 +00:00
|
|
|
func (c *Client) GasBalance() (res int64, err error) {
|
|
|
|
if c.multiClient != nil {
|
|
|
|
return res, c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
res, err = c.GasBalance()
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-02 06:57:19 +00:00
|
|
|
gas, err := c.client.GetNativeContractHash(nativenames.Gas)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.client.NEP17BalanceOf(gas, c.acc.PrivateKey().GetScriptHash())
|
2021-02-25 16:50:10 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 14:45:35 +00:00
|
|
|
// Committee returns keys of chain committee from neo native contract.
|
2021-08-26 07:59:02 +00:00
|
|
|
func (c *Client) Committee() (res keys.PublicKeys, err error) {
|
|
|
|
if c.multiClient != nil {
|
|
|
|
return res, c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
res, err = c.Committee()
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:40:49 +00:00
|
|
|
return c.client.GetCommittee()
|
2021-03-09 14:45:35 +00:00
|
|
|
}
|
|
|
|
|
2021-04-27 11:07:06 +00:00
|
|
|
// TxHalt returns true if transaction has been successfully executed and persisted.
|
2021-08-26 07:59:02 +00:00
|
|
|
func (c *Client) TxHalt(h util.Uint256) (res bool, err error) {
|
|
|
|
if c.multiClient != nil {
|
|
|
|
return res, c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
res, err = c.TxHalt(h)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-27 11:07:06 +00:00
|
|
|
trig := trigger.Application
|
|
|
|
aer, err := c.client.GetApplicationLog(h, &trig)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return len(aer.Executions) > 0 && aer.Executions[0].VMState.HasFlag(vm.HaltState), nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:03:23 +00:00
|
|
|
// 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.
|
2021-08-26 07:59:02 +00:00
|
|
|
func (c *Client) NeoFSAlphabetList() (res keys.PublicKeys, err error) {
|
|
|
|
if c.multiClient != nil {
|
|
|
|
return res, c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
res, err = c.NeoFSAlphabetList()
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:40:49 +00:00
|
|
|
list, err := c.roleList(noderoles.NeoFSAlphabet)
|
2021-03-23 10:03:23 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("can't get alphabet nodes role list: %w", err)
|
2021-03-23 10:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return list, nil
|
|
|
|
}
|
|
|
|
|
2021-05-18 07:40:21 +00:00
|
|
|
// GetDesignateHash returns hash of the native `RoleManagement` contract.
|
2021-08-26 07:59:02 +00:00
|
|
|
func (c *Client) GetDesignateHash() (res util.Uint160, err error) {
|
|
|
|
if c.multiClient != nil {
|
|
|
|
return res, c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
res, err = c.GetDesignateHash()
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.client.GetNativeContractHash(nativenames.Designation)
|
2021-05-18 07:40:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 14:40:49 +00:00
|
|
|
func (c *Client) roleList(r noderoles.Role) (keys.PublicKeys, error) {
|
2021-03-23 10:02:24 +00:00
|
|
|
height, err := c.client.GetBlockCount()
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("can't get chain height: %w", err)
|
2021-03-23 10:02:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 14:40:49 +00:00
|
|
|
return c.client.GetDesignatedByRole(r, height)
|
2021-03-23 10:02:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 10:16:25 +00:00
|
|
|
// tries to resolve sc.Parameter from the arg.
|
|
|
|
//
|
|
|
|
// Wraps any error to neofsError.
|
2020-07-10 14:17:51 +00:00
|
|
|
func toStackParameter(value interface{}) (sc.Parameter, error) {
|
|
|
|
var result = sc.Parameter{
|
|
|
|
Value: value,
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: add more types
|
2020-09-08 08:37:18 +00:00
|
|
|
switch v := value.(type) {
|
2020-07-10 14:17:51 +00:00
|
|
|
case []byte:
|
|
|
|
result.Type = sc.ByteArrayType
|
|
|
|
case int64: // TODO: add other numerical types
|
|
|
|
result.Type = sc.IntegerType
|
2020-09-08 08:37:18 +00:00
|
|
|
case [][]byte:
|
|
|
|
arr := make([]sc.Parameter, 0, len(v))
|
|
|
|
for i := range v {
|
|
|
|
elem, err := toStackParameter(v[i])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
arr = append(arr, elem)
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Type = sc.ArrayType
|
|
|
|
result.Value = arr
|
2020-10-19 09:22:46 +00:00
|
|
|
case string:
|
|
|
|
result.Type = sc.StringType
|
2021-02-25 16:53:30 +00:00
|
|
|
case util.Uint160:
|
|
|
|
result.Type = sc.ByteArrayType
|
|
|
|
result.Value = v.BytesBE()
|
2021-04-08 14:40:49 +00:00
|
|
|
case noderoles.Role:
|
2021-03-09 14:47:13 +00:00
|
|
|
result.Type = sc.IntegerType
|
|
|
|
result.Value = int64(v)
|
2021-03-23 10:06:00 +00:00
|
|
|
case keys.PublicKeys:
|
|
|
|
arr := make([][]byte, 0, len(v))
|
|
|
|
for i := range v {
|
|
|
|
arr = append(arr, v[i].Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
return toStackParameter(arr)
|
2021-05-25 09:24:03 +00:00
|
|
|
case bool:
|
|
|
|
// FIXME: there are some problems with BoolType in neo-go,
|
|
|
|
// so we use compatible type
|
|
|
|
result.Type = sc.IntegerType
|
|
|
|
|
|
|
|
if v {
|
|
|
|
result.Value = int64(1)
|
|
|
|
} else {
|
|
|
|
result.Value = int64(0)
|
|
|
|
}
|
2020-07-10 14:17:51 +00:00
|
|
|
default:
|
2021-08-31 10:16:25 +00:00
|
|
|
return result, wrapNeoFSError(fmt.Errorf("chain/client: unsupported parameter %v", value))
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
2021-02-19 07:54:26 +00:00
|
|
|
|
|
|
|
// MagicNumber returns the magic number of the network
|
|
|
|
// to which the underlying RPC node client is connected.
|
2021-08-26 07:59:02 +00:00
|
|
|
//
|
|
|
|
// Returns 0 in case of connection problems.
|
2021-08-26 08:17:31 +00:00
|
|
|
func (c *Client) MagicNumber() (res uint64, err error) {
|
2021-08-26 07:59:02 +00:00
|
|
|
if c.multiClient != nil {
|
2021-08-26 08:17:31 +00:00
|
|
|
return res, c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
res, err = c.MagicNumber()
|
|
|
|
return err
|
2021-08-26 07:59:02 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-26 08:17:31 +00:00
|
|
|
return uint64(c.client.GetNetwork()), nil
|
2021-02-19 07:54:26 +00:00
|
|
|
}
|
2021-07-21 15:12:19 +00:00
|
|
|
|
|
|
|
// BlockCount returns block count of the network
|
|
|
|
// to which the underlying RPC node client is connected.
|
2021-08-26 07:59:02 +00:00
|
|
|
func (c *Client) BlockCount() (res uint32, err error) {
|
|
|
|
if c.multiClient != nil {
|
|
|
|
return res, c.multiClient.iterateClients(func(c *Client) error {
|
|
|
|
res, err = c.BlockCount()
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:12:19 +00:00
|
|
|
return c.client.GetBlockCount()
|
|
|
|
}
|