client

package
v0.22.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2021 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const HaltState = "HALT"

HaltState returned if TestInvoke function processed without panic.

Variables

View Source
var ErrNilClient = errors.New("client is nil")

ErrNilClient is returned by functions that expect a non-nil Client pointer, but received nil.

View Source
var ErrNilStaticClient = errors.New("static client is nil")

ErrNilStaticClient is returned by functions that expect a non-nil StaticClient pointer, but received nil.

Functions

func ArrayFromStackItem added in v0.12.0

func ArrayFromStackItem(param stackitem.Item) ([]stackitem.Item, error)

ArrayFromStackItem returns the slice contract parameters from passed parameter.

If passed parameter carries boolean false value, (nil, nil) returns.

func BigIntFromStackItem added in v0.12.0

func BigIntFromStackItem(param stackitem.Item) (*big.Int, error)

BigIntFromStackItem receives numerical value from the value of a smart contract parameter.

func BoolFromStackItem added in v0.12.0

func BoolFromStackItem(param stackitem.Item) (bool, error)

BoolFromStackItem receives boolean value from the value of a smart contract parameter.

func BytesFromStackItem added in v0.12.0

func BytesFromStackItem(param stackitem.Item) ([]byte, error)

BytesFromStackItem receives binary value from the value of a smart contract parameter.

func IntFromStackItem added in v0.12.0

func IntFromStackItem(param stackitem.Item) (int64, error)

IntFromStackItem receives numerical value from the value of a smart contract parameter.

func StringFromStackItem added in v0.12.0

func StringFromStackItem(param stackitem.Item) (string, error)

StringFromStackItem receives string value from the value of a smart contract parameter.

Types

type AlphabetKeys added in v0.19.0

type AlphabetKeys func() (keys.PublicKeys, error)

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a neo-go wrapper that provides smart-contract invocation interface.

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.

func New

func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)

New creates, initializes and returns the Client instance.

If private key is nil, it panics.

Other values are set according to provided options, or by default:

  • client context: Background;
  • dial timeout: 5s;
  • blockchain network type: netmode.PrivNet;
  • logger: zap.L().

If desired option satisfies the default value, it can be omitted. If multiple options of the same config value are supplied, the option with the highest index in the arguments will be used.

func (*Client) Committee added in v0.18.0

func (c *Client) Committee() (keys.PublicKeys, error)

Committee returns keys of chain committee from neo native contract.

func (*Client) DepositNotary added in v0.17.0

func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (util.Uint256, error)

DepositNotary calls notary deposit method. Deposit is required to operate with notary contract. It used by notary contract in to produce fallback tx if main tx failed to create. Deposit isn't last forever, so it should be called periodically. Notary support should be enabled in client to use this function.

This function must be invoked with notary enabled otherwise it throws panic.

func (*Client) GasBalance added in v0.17.0

func (c *Client) GasBalance() (int64, error)

GasBalance returns GAS amount in the client's wallet.

func (*Client) GetDesignateHash added in v0.21.0

func (c *Client) GetDesignateHash() util.Uint160

GetDesignateHash returns hash of the native `RoleManagement` contract.

func (*Client) GetNotaryDeposit added in v0.17.0

func (c *Client) GetNotaryDeposit() (int64, error)

GetNotaryDeposit returns deposit of client's account in notary contract. Notary support should be enabled in client to use this function.

This function must be invoked with notary enabled otherwise it throws panic.

func (*Client) Invoke

func (c *Client) Invoke(contract util.Uint160, fee fixedn.Fixed8, method string, args ...interface{}) error

Invoke invokes contract method by sending transaction into blockchain. Supported args types: int64, string, util.Uint160, []byte and bool.

func (*Client) MagicNumber added in v0.16.0

func (c *Client) MagicNumber() uint64

MagicNumber returns the magic number of the network to which the underlying RPC node client is connected.

func (*Client) NeoFSAlphabetList added in v0.18.0

func (c *Client) NeoFSAlphabetList() (keys.PublicKeys, error)

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 (*Client) NotaryEnabled added in v0.19.0

func (c *Client) NotaryEnabled() bool

NotaryEnabled returns true if notary support was enabled in this instance of client by providing notary options on client creation. Otherwise returns false.

func (*Client) NotaryInvoke added in v0.17.0

func (c *Client) NotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, method string, args ...interface{}) error

NotaryInvoke invokes contract method by sending tx to notary contract in blockchain. Fallback tx is a `RET`. If Notary support is not enabled it fallbacks to a simple `Invoke()`.

This function must be invoked with notary enabled otherwise it throws panic.

func (*Client) TestInvoke

func (c *Client) TestInvoke(contract util.Uint160, method string, args ...interface{}) ([]stackitem.Item, error)

TestInvoke invokes contract method locally in neo-go node. This method should be used to read data from smart-contract.

func (*Client) TransferGas

func (c *Client) TransferGas(receiver util.Uint160, amount fixedn.Fixed8) error

TransferGas to the receiver from local wallet

func (*Client) TxHalt added in v0.19.0

func (c *Client) TxHalt(h util.Uint256) (bool, error)

TxHalt returns true if transaction has been successfully executed and persisted.

func (*Client) UpdateNeoFSAlphabetList added in v0.18.0

func (c *Client) UpdateNeoFSAlphabetList(list keys.PublicKeys) error

UpdateNeoFSAlphabetList updates list of alphabet nodes in designate contract. As for side chain list should contain all inner ring nodes. Requires committee multi signature.

This function must be invoked with notary enabled otherwise it throws panic.

func (*Client) UpdateNotaryList added in v0.18.0

func (c *Client) UpdateNotaryList(list keys.PublicKeys) error

UpdateNotaryList updates list of notary nodes in designate contract. Requires committee multi signature.

This function must be invoked with notary enabled otherwise it throws panic.

func (*Client) Wait added in v0.17.0

func (c *Client) Wait(ctx context.Context, n uint32)

Wait function blocks routing execution until there are `n` new blocks in the chain.

type NotaryOption added in v0.17.0

type NotaryOption func(*notaryCfg)

func WithAlphabetSource added in v0.19.0

func WithAlphabetSource(t AlphabetKeys) NotaryOption

WithAlphabetSource returns a notary support option for client that specifies function to return list of alphabet node keys. By default notary subsystem uses committee as a source. This is valid for side chain but notary in main chain should override it.

func WithFallbackTime added in v0.17.0

func WithFallbackTime(t uint32) NotaryOption

WithFallbackTime returns a notary support option for client that specifies amount of blocks before fallbackTx will be sent. Should be less than TxValidTime.

func WithProxyContract added in v0.22.0

func WithProxyContract(h util.Uint160) NotaryOption

WithProxyContract sets proxy contract hash.

func WithRoundTime added in v0.17.0

func WithRoundTime(t uint32) NotaryOption

WithRoundTime returns a notary support option for client that specifies extra blocks to synchronize side chain height diff of inner ring nodes.

func WithTxValidTime added in v0.17.0

func WithTxValidTime(t uint32) NotaryOption

WithTxValidTime returns a notary support option for client that specifies minimum amount of blocks when mainTx will be valid.

type Option

type Option func(*cfg)

Option is a client configuration change function.

func WithContext

func WithContext(ctx context.Context) Option

WithContext returns a client constructor option that specifies the neo-go client context.

Ignores nil value.

If option not provided, context.Background() is used.

func WithDialTimeout

func WithDialTimeout(dur time.Duration) Option

WithDialTimeout returns a client constructor option that specifies neo-go client dial timeout duration.

Ignores non-positive value.

If option not provided, 5s timeout is used.

func WithLogger

func WithLogger(logger *logger.Logger) Option

WithLogger returns a client constructor option that specifies the component for writing log messages.

Ignores nil value.

If option not provided, zap.L() is used.

func WithNotaryOptions added in v0.22.0

func WithNotaryOptions(opts ...NotaryOption) Option

WithNotaryOptions enables notary support and sets notary options for the client.

type StaticClient

type StaticClient struct {
	// contains filtered or unexported fields
}

StaticClient is a wrapper over Neo:Morph client that invokes single smart contract methods with fixed fee.

Working static client must be created via constructor NewStatic. Using the StaticClient that has been created with new(StaticClient) expression (or just declaring a StaticClient variable) is unsafe and can lead to panic.

func NewStatic

func NewStatic(client *Client, scriptHash util.Uint160, fee fixedn.Fixed8, opts ...StaticClientOption) (*StaticClient, error)

NewStatic creates, initializes and returns the StaticClient instance.

If provided Client instance is nil, ErrNilClient is returned.

func (StaticClient) Invoke

func (s StaticClient) Invoke(method string, args ...interface{}) error

Invoke calls Invoke method of Client with static internal script hash and fee. Supported args types are the same as in Client.

If TryNotary is provided, calls NotaryInvoke on Client.

func (StaticClient) TestInvoke

func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackitem.Item, error)

TestInvoke calls TestInvoke method of Client with static internal script hash.

type StaticClientOption added in v0.21.0

type StaticClientOption func(*staticOpts)

StaticClientOption allows to set an optional parameter of StaticClient.

func TryNotary added in v0.21.0

func TryNotary() StaticClientOption

TryNotary returns option to enable notary invocation tries.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL