client

package
v0.0.0-...-fd964dd Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package client provides functionality for interacting with the Tron node RESTful APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallContractInput

type CallContractInput struct {
	Address   address.Address
	Function  abi.Function
	Arguments []interface{}
	FeeLimit  uint64
	CallValue uint64
	Result    interface{}
}

type Client

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

func New

func New(host string) *Client

New creates a new client for the provided host.

func (*Client) BroadcastTransaction

func (c *Client) BroadcastTransaction(tx *tron.Transaction) error

BroadcastTransaction broadcasts a signed transaction to the network.

func (*Client) CallContract

func (c *Client) CallContract(acc account.Account, input CallContractInput) (*TransactionInfo, error)

CallContract calls a function of a contract. If the function is immutable (either 'pure' or 'view') then the constant function is triggered and the returned encoded ABI value is unmarshaled to CallContractInput.Result. Immutable functions will return nil transaction info because there is no transaction that is committed to the blockchain. Mutable function calls will be broadcasted and the function will wait until the call has been completed. The returned ABI value is also unmarshaled to CallContractInput.Result. Mutable functions will return transaction info if they are successfully processed.

func (*Client) DeployContract

func (c *Client) DeployContract(acc account.Account, input DeployContractInput) (*TransactionInfo, error)

DeployContract deploys a contract. The owner of the deployed contract will be the account that this function was called with.

func (*Client) GetBlockByHeight

func (c *Client) GetBlockByHeight(n uint64) (*tron.Block, error)

GetBlockByHeight returns the block at the specified height.

func (*Client) GetBlockById

func (c *Client) GetBlockById(id string) (*tron.Block, error)

GetBlockById returns the block for the specified id.

func (*Client) GetBlockRange

func (c *Client) GetBlockRange(start, end uint64) ([]tron.Block, error)

GetBlockRange returns the blocks within a height range, end exclusive.

func (*Client) GetLatestBlock

func (c *Client) GetLatestBlock() (tron.Block, error)

GetLatestBlock returns the latest block synced to the node.

func (*Client) GetLatestBlocks

func (c *Client) GetLatestBlocks(n int) ([]tron.Block, error)

GetLatestBlocks returns the last n blocks synced to the node.

func (*Client) TransactionById

func (c *Client) TransactionById(id string) (*tron.Transaction, error)

TransactionById returns the transaction for the provided id.

func (*Client) TransactionInfoById

func (c *Client) TransactionInfoById(id string) (*TransactionInfo, error)

TransactionInfoById returns the information about a processed transaction. If the transaction does not exist or has not yet been processed then the returned information will be nil even though an error will not be returned.

func (*Client) Transfer

func (c *Client) Transfer(src account.Account, dest address.Address, amount uint64) (*TransactionInfo, error)

Transfer transfers a balance of Tron from a source account to a destination address.

type DeployContractInput

type DeployContractInput struct {
	ABI               abi.ABI
	Arguments         []interface{}
	Bytecode          []byte
	Name              string
	FeeLimit          uint64
	CallValue         uint64
	Owner             address.Address
	OriginEnergyLimit uint64
}

type TransactionInfo

type TransactionInfo struct {
	Id              string             `json:"id"`
	Fee             uint64             `json:"fee"`
	BlockNumber     uint64             `json:"blockNumber"`
	BlockTimestamp  uint64             `json:"blockTimestamp"`
	ContractResult  []string           `json:"contractResult"`
	ContractAddress address.Address    `json:"contract_address"`
	Receipt         TransactionReceipt `json:"receipt"`
	Log             *json.RawMessage   `json:"log"`
}

TransactionInfo contains information about a processed transaction.

func (TransactionInfo) Error

func (t TransactionInfo) Error() error

type TransactionReceipt

type TransactionReceipt struct {
	EnergyFee        uint64            `json:"energy_fee"`
	EnergyUsageTotal uint64            `json:"energy_usage_total"`
	NetFee           uint64            `json:"net_fee"`
	NetUsage         uint64            `json:"net_usage"`
	Result           TransactionResult `json:"result"`
}

type TransactionResult

type TransactionResult string

TransactionResult is an enumeration which described what happened when processing a transaction. This is not to be confused with the result of executing a contract which will be an ABI encoded payload.

const (
	TxResultSuccess             TransactionResult = "SUCCESS"
	TxResultRevert              TransactionResult = "REVERT"
	TxResultBadJump             TransactionResult = "BAD_JUST_DESTINATION"
	TxResultOutOfMemory         TransactionResult = "OUT_OF_MEMORY"
	TxResultPrecompiledContract TransactionResult = "PRECOMPILED_CONTRACT"
	TxResultStackTooSmall       TransactionResult = "STACK_TOO_SMALL"
	TxResultStackTooLarge       TransactionResult = "STACK_TOO_LARGE"
	TxResultIllegalOp           TransactionResult = "ILLEGAL_OPERATION"
	TxResultStackOverflow       TransactionResult = "STACK_OVERFLOW"
	TxResultOutOfEnergy         TransactionResult = "OUT_OF_ENERGY"
	TxOutOfTime                 TransactionResult = "OUT_OF_TIME"
	TxResultJVMStackOverflow    TransactionResult = "JVM_STACK_OVER_FLOW"
	TxResultUnknown             TransactionResult = "UNKNOWN"
	TxResultTransferFailed      TransactionResult = "TRANSFER_FAILED"
)

Jump to

Keyboard shortcuts

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