ethereum

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: GPL-3.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultClientRPCURL is the RPC URL used by default, to interact with the
	// ethereum node.
	DefaultClientRPCURL = "http://127.0.0.1:8545/"
)

Variables

This section is empty.

Functions

func Encode

func Encode(vals ...interface{}) []byte

Encode values into an Ethereum ABI compatible byte slice.

func NewAddressEncodeDecoder added in v0.2.1

func NewAddressEncodeDecoder() address.EncodeDecoder

NewAddressEncodeDecoder constructs a new AddressEncodeDecoder.

Types

type Address

type Address common.Address

An Address represents a public address on the Ethereum blockchain. It can be the address of an external account, or the address of a smart contract.

func NewAddressFromHex

func NewAddressFromHex(str string) (Address, error)

NewAddressFromHex returns an Address decoded from a hex string.

func (Address) Bytes

func (addr Address) Bytes() pack.Bytes

Bytes returns the address as a slice of 20 bytes.

func (Address) Marshal

func (addr Address) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal the address to binary.

func (Address) MarshalJSON

func (addr Address) MarshalJSON() ([]byte, error)

MarshalJSON implements JSON marshaling by encoding the address as a hex string.

func (Address) SizeHint

func (Address) SizeHint() int

SizeHint returns the number of bytes needed to represent this address in binary.

func (Address) String

func (addr Address) String() string

String returns the address as a human-readable hex string.

func (*Address) Unmarshal

func (addr *Address) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal the address from binary.

func (*Address) UnmarshalJSON

func (addr *Address) UnmarshalJSON(data []byte) error

UnmarshalJSON implements JSON unmarshaling by expected the data be a hex encoded string representation of an address.

type AddressDecoder

type AddressDecoder interface {
	DecodeAddress(address.Address) (address.RawAddress, error)
}

AddressDecoder implements the address.Decoder interface.

func NewAddressDecoder

func NewAddressDecoder() AddressDecoder

NewAddressDecoder constructs a new AddressDecoder.

type AddressEncodeDecoder added in v0.2.1

type AddressEncodeDecoder struct {
	AddressEncoder
	AddressDecoder
}

AddressEncodeDecoder implements the address.EncodeDecoder interface

type AddressEncoder

type AddressEncoder interface {
	EncodeAddress(address.RawAddress) (address.Address, error)
}

AddressEncoder implements the address.Encoder interface.

func NewAddressEncoder

func NewAddressEncoder() AddressEncoder

NewAddressEncoder constructs a new AddressEncoder.

type Client added in v0.3.14

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

Client holds the underlying RPC client instance.

func NewClient added in v0.3.14

func NewClient(rpcURL string) (*Client, error)

NewClient creates and returns a new JSON-RPC client to the Ethereum node

func (*Client) AccountBalance added in v0.3.14

func (client *Client) AccountBalance(ctx context.Context, addr address.Address) (pack.U256, error)

AccountBalance returns the account balancee for a given address.

func (*Client) AccountNonce added in v0.3.14

func (client *Client) AccountNonce(ctx context.Context, addr address.Address) (pack.U256, error)

AccountNonce returns the current nonce of the account. This is the nonce to be used while building a new transaction.

func (*Client) CallContract added in v0.3.14

func (client *Client) CallContract(ctx context.Context, program address.Address, calldata contract.CallData) (pack.Bytes, error)

CallContract implements the multichain Contract API.

func (*Client) LatestBlock added in v0.3.14

func (client *Client) LatestBlock(ctx context.Context) (pack.U64, error)

LatestBlock returns the block number at the current chain head.

func (*Client) SubmitTx added in v0.3.14

func (client *Client) SubmitTx(ctx context.Context, tx account.Tx) error

SubmitTx to the underlying blockchain network.

func (*Client) Tx added in v0.3.14

func (client *Client) Tx(ctx context.Context, txID pack.Bytes) (account.Tx, pack.U64, error)

Tx returns the transaction uniquely identified by the given transaction hash. It also returns the number of confirmations for the transaction.

type GasEstimator added in v0.3.14

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

A GasEstimator returns the gas price and the provide gas limit that is needed in order to confirm transactions with an estimated maximum delay of one block.

func NewGasEstimator added in v0.3.14

func NewGasEstimator(client *Client) *GasEstimator

NewGasEstimator returns a simple gas estimator that fetches the ideal gas price for a ethereum transaction to be included in a block with minimal delay.

func (*GasEstimator) EstimateGas added in v0.3.14

func (gasEstimator *GasEstimator) EstimateGas(ctx context.Context) (pack.U256, pack.U256, error)

EstimateGas returns an estimate of the current gas price and returns the gas limit provided. These numbers change with congestion. These estimates are often a little bit off, and this should be considered when using them.

type Payload

type Payload struct {
	ABI  pack.Bytes `json:"abi"`
	Fn   pack.Bytes `json:"fn"`
	Data pack.Bytes `json:"data"`
}

A Payload is an Ethereum encoded function call. It includes an ABI, the function being called from the ABI, and the data being passed to the function.

type Tx added in v0.3.14

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

Tx represents a ethereum transaction, encapsulating a payload/data and its signer.

func (Tx) From added in v0.3.14

func (tx Tx) From() address.Address

From returns the address that is sending the transaction. Generally, this is also the address that must sign the transaction.

func (Tx) Hash added in v0.3.14

func (tx Tx) Hash() pack.Bytes

Hash returns the hash that uniquely identifies the transaction. Generally, hashes are irreversible hash functions that consume the content of the transaction.

func (Tx) Nonce added in v0.3.14

func (tx Tx) Nonce() pack.U256

Nonce returns the nonce used to order the transaction with respect to all other transactions signed and submitted by the sender.

func (Tx) Payload added in v0.3.14

func (tx Tx) Payload() contract.CallData

Payload returns arbitrary data that is associated with the transaction. Generally, this payload is used to send notes between external accounts, or invoke business logic on a contract.

func (Tx) Serialize added in v0.3.14

func (tx Tx) Serialize() (pack.Bytes, error)

Serialize the transaction into bytes. Generally, this is the format in which the transaction will be submitted by the client.

func (Tx) Sighashes added in v0.3.14

func (tx Tx) Sighashes() ([]pack.Bytes32, error)

Sighashes returns the digests that must be signed before the transaction can be submitted by the client.

func (*Tx) Sign added in v0.3.14

func (tx *Tx) Sign(signatures []pack.Bytes65, pubkey pack.Bytes) error

Sign the transaction by injecting signatures for the required sighashes. The serialized public key used to sign the sighashes must also be specified.

func (Tx) To added in v0.3.14

func (tx Tx) To() address.Address

To returns the address that is receiving the transaction. This can be the address of an external account, controlled by a private key, or it can be the address of a contract.

func (Tx) Value added in v0.3.14

func (tx Tx) Value() pack.U256

Value being sent from the sender to the receiver.

type TxBuilder added in v0.3.14

type TxBuilder struct {
	ChainID *big.Int
}

TxBuilder represents a transaction builder that builds transactions to be broadcasted to the ethereum network. The TxBuilder is configured using a chain id.

func NewTxBuilder added in v0.3.14

func NewTxBuilder(chainID *big.Int) TxBuilder

NewTxBuilder creates a new transaction builder.

func (TxBuilder) BuildTx added in v0.3.14

func (txBuilder TxBuilder) BuildTx(ctx context.Context, from, to address.Address, value, nonce, gasLimit, gasPrice, gasCap pack.U256, payload pack.Bytes) (account.Tx, error)

BuildTx receives transaction fields and constructs a new transaction.

Jump to

Keyboard shortcuts

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