Documentation

Index

Constants

View Source
const (
	StringT paramType
	NumberT
	ArrayT
	FuncParamT
)

    These are parameter types accepted by RPC server.

    View Source
    const (
    	// JSONRPCVersion is the only JSON-RPC protocol version supported.
    	JSONRPCVersion = "2.0"
    )

    Variables

    This section is empty.

    Functions

    func AddInputsAndUnspentsToTx

    func AddInputsAndUnspentsToTx(tx *transaction.Transaction, addr string, assetID util.Uint256, amount util.Fixed8, balancer BalanceGetter) error

      AddInputsAndUnspentsToTx adds inputs needed to transaction and one output with change.

      func CreateDeploymentScript

      func CreateDeploymentScript(avm []byte, contract *ContractDetails) ([]byte, error)

        CreateDeploymentScript returns a script that deploys given smart contract with its metadata.

        func CreateFunctionInvocationScript

        func CreateFunctionInvocationScript(contract util.Uint160, params Params) ([]byte, error)

          CreateFunctionInvocationScript creates a script to invoke given contract with given parameters.

          func CreateInvocationScript

          func CreateInvocationScript(contract util.Uint160, funcParams []Param) ([]byte, error)

            CreateInvocationScript creates a script to invoke given contract with given parameters. It differs from CreateFunctionInvocationScript in that it expects one array of FuncParams and expands it onto the stack as independent elements.

            func CreateRawContractTransaction

            func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transaction, error)

              CreateRawContractTransaction returns contract-type Transaction built from specified parameters.

              func GetInvocationScript

              func GetInvocationScript(tx *transaction.Transaction, wif *keys.WIF) ([]byte, error)

                GetInvocationScript returns NEO VM script containing transaction signature.

                func SignTx

                func SignTx(tx *transaction.Transaction, wif *keys.WIF) error

                  SignTx signs given transaction in-place using given key.

                  Types

                  type BalanceGetter

                  type BalanceGetter interface {
                  	// 		parameters
                  	// address: 	base58-encoded address assets would be transferred from
                  	// assetID: 	asset identifier
                  	// amount: 		an asset amount to spend
                  	// 		return values
                  	// inputs: 		UTXO's for the preparing transaction
                  	// total: 		summarized asset amount from all the `inputs`
                  	// error: 		error would be considered in the caller function
                  	CalculateInputs(address string, assetID util.Uint256, amount util.Fixed8) (inputs []transaction.Input, total util.Fixed8, err error)
                  }

                    BalanceGetter is an interface supporting CalculateInputs() method.

                    type ContractDetails

                    type ContractDetails struct {
                    	Author               string
                    	Email                string
                    	Version              string
                    	ProjectName          string `yaml:"name"`
                    	Description          string
                    	HasStorage           bool
                    	HasDynamicInvocation bool
                    	IsPayable            bool
                    	ReturnType           StackParamType
                    	Parameters           []StackParamType
                    }

                      ContractDetails contains contract metadata.

                      type ContractTxParams

                      type ContractTxParams struct {
                      	AssetID util.Uint256
                      	Address string
                      	Value   util.Fixed8
                      	WIF     keys.WIF // a WIF to send the transaction
                      	// since there are many ways to provide unspents,
                      	// transaction composer stays agnostic to that how
                      	// unspents was got;
                      	Balancer BalanceGetter
                      }

                        ContractTxParams contains parameters for tx to transfer assets. It includes (*Client).TransferAsset call params and utility data.

                        type FuncParam

                        type FuncParam struct {
                        	Type  StackParamType `json:"type"`
                        	Value Param          `json:"value"`
                        }

                          FuncParam represents a function argument parameter used in the invokefunction RPC method.

                          type In

                          type In struct {
                          	JSONRPC   string          `json:"jsonrpc"`
                          	Method    string          `json:"method"`
                          	RawParams json.RawMessage `json:"params,omitempty"`
                          	RawID     json.RawMessage `json:"id,omitempty"`
                          }

                            In represents a standard JSON-RPC 2.0 request: http://www.jsonrpc.org/specification#request_object. It's used in server to represent incoming queries.

                            func NewIn

                            func NewIn() *In

                              NewIn creates a new Request struct.

                              func (*In) DecodeData

                              func (r *In) DecodeData(data io.ReadCloser) error

                                DecodeData decodes the given reader into the the request struct.

                                func (*In) Params

                                func (r *In) Params() (*Params, error)

                                  Params takes a slice of any type and attempts to bind the params to it.

                                  type Param

                                  type Param struct {
                                  	Type  paramType
                                  	Value interface{}
                                  }

                                    Param represents a param either passed to the server or to send to a server using the client.

                                    func (Param) GetArray

                                    func (p Param) GetArray() ([]Param, error)

                                      GetArray returns a slice of Params stored in the parameter.

                                      func (Param) GetBytesHex

                                      func (p Param) GetBytesHex() ([]byte, error)

                                        GetBytesHex returns []byte value of the parameter if it is a hex-encoded string.

                                        func (Param) GetFuncParam

                                        func (p Param) GetFuncParam() (FuncParam, error)

                                          GetFuncParam returns current parameter as a function call parameter.

                                          func (Param) GetInt

                                          func (p Param) GetInt() (int, error)

                                            GetInt returns int value of te parameter.

                                            func (Param) GetString

                                            func (p Param) GetString() (string, error)

                                              GetString returns string value of the parameter.

                                              func (Param) GetUint160FromAddress

                                              func (p Param) GetUint160FromAddress() (util.Uint160, error)

                                                GetUint160FromAddress returns Uint160 value of the parameter that was supplied as an address.

                                                func (Param) GetUint160FromHex

                                                func (p Param) GetUint160FromHex() (util.Uint160, error)

                                                  GetUint160FromHex returns Uint160 value of the parameter encoded in hex.

                                                  func (Param) GetUint256

                                                  func (p Param) GetUint256() (util.Uint256, error)

                                                    GetUint256 returns Uint256 value of the parameter.

                                                    func (Param) String

                                                    func (p Param) String() string

                                                    func (*Param) UnmarshalJSON

                                                    func (p *Param) UnmarshalJSON(data []byte) error

                                                      UnmarshalJSON implements json.Unmarshaler interface.

                                                      type Params

                                                      type Params []Param

                                                        Params represents the JSON-RPC params.

                                                        func (Params) Value

                                                        func (p Params) Value(index int) (*Param, bool)

                                                          Value returns the param struct for the given index if it exists.

                                                          func (Params) ValueWithType

                                                          func (p Params) ValueWithType(index int, valType paramType) (*Param, bool)

                                                            ValueWithType returns the param struct at the given index if it exists and matches the given type.

                                                            type Raw

                                                            type Raw struct {
                                                            	JSONRPC   string        `json:"jsonrpc"`
                                                            	Method    string        `json:"method"`
                                                            	RawParams []interface{} `json:"params"`
                                                            	ID        int           `json:"id"`
                                                            }

                                                              Raw represents JSON-RPC request.

                                                              type RawParams

                                                              type RawParams struct {
                                                              	Values []interface{}
                                                              }

                                                                RawParams is just a slice of abstract values, used to represent parameters passed from client to server.

                                                                func NewRawParams

                                                                func NewRawParams(vals ...interface{}) RawParams

                                                                  NewRawParams creates RawParams from its parameters.

                                                                  type StackParam

                                                                  type StackParam struct {
                                                                  	Type  StackParamType `json:"type"`
                                                                  	Value interface{}    `json:"value"`
                                                                  }

                                                                    StackParam represent a stack parameter.

                                                                    func (StackParam) TryParse

                                                                    func (p StackParam) TryParse(dest interface{}) error

                                                                      TryParse converts one StackParam into something more appropriate.

                                                                      func (*StackParam) UnmarshalJSON

                                                                      func (p *StackParam) UnmarshalJSON(data []byte) (err error)

                                                                        UnmarshalJSON implements Unmarshaler interface.

                                                                        type StackParamType

                                                                        type StackParamType int

                                                                          StackParamType represents different types of stack values.

                                                                          const (
                                                                          	Unknown          StackParamType = -1
                                                                          	Signature        StackParamType = 0x00
                                                                          	Boolean          StackParamType = 0x01
                                                                          	Integer          StackParamType = 0x02
                                                                          	Hash160          StackParamType = 0x03
                                                                          	Hash256          StackParamType = 0x04
                                                                          	ByteArray        StackParamType = 0x05
                                                                          	PublicKey        StackParamType = 0x06
                                                                          	String           StackParamType = 0x07
                                                                          	Array            StackParamType = 0x10
                                                                          	InteropInterface StackParamType = 0xf0
                                                                          	Void             StackParamType = 0xff
                                                                          )

                                                                            All possible StackParamType values are listed here.

                                                                            func StackParamTypeFromString

                                                                            func StackParamTypeFromString(s string) (StackParamType, error)

                                                                              StackParamTypeFromString converts string into the StackParamType.

                                                                              func (*StackParamType) MarshalJSON

                                                                              func (t *StackParamType) MarshalJSON() ([]byte, error)

                                                                                MarshalJSON implements the json.Marshaler interface.

                                                                                func (*StackParamType) MarshalYAML

                                                                                func (t *StackParamType) MarshalYAML() (interface{}, error)

                                                                                  MarshalYAML implements the YAML Marshaler interface.

                                                                                  func (StackParamType) String

                                                                                  func (t StackParamType) String() string

                                                                                    String implements the stringer interface.

                                                                                    func (*StackParamType) UnmarshalJSON

                                                                                    func (t *StackParamType) UnmarshalJSON(data []byte) (err error)

                                                                                      UnmarshalJSON sets StackParamType from JSON-encoded data.

                                                                                      func (*StackParamType) UnmarshalYAML

                                                                                      func (t *StackParamType) UnmarshalYAML(unmarshal func(interface{}) error) error

                                                                                        UnmarshalYAML implements the YAML Unmarshaler interface.

                                                                                        type StackParams

                                                                                        type StackParams []StackParam

                                                                                          StackParams is an array of StackParam (TODO: drop it?).

                                                                                          func (StackParams) TryParseArray

                                                                                          func (p StackParams) TryParseArray(vals ...interface{}) error

                                                                                            TryParseArray converts an array of StackParam into an array of more appropriate things.