Documentation
¶
Overview ¶
Package common contains various helper functions.
Package etaiclient provides a client for the Ethereum RPC API.
Index ¶
- Constants
- func Bytes2Hex(d []byte) string
- func CopyBytes(b []byte) (copiedBytes []byte)
- func FromHex(s string) []byte
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func IsHexAddress(s string) bool
- func LeftPadBytes(slice []byte, l int) []byte
- func RightPadBytes(slice []byte, l int) []byte
- func ToHex(b []byte) stringdeprecated
- func ToHexArray(b [][]byte) []string
- type Address
- func (a Address) Bytes() []byte
- func (a Address) Format(s fmt.State, c rune)
- func (a Address) Hash() Hash
- func (a Address) Hex() string
- func (a Address) ImplementsGraphQLType(name string) bool
- func (a Address) MarshalText() ([]byte, error)
- func (a *Address) Scan(src interface{}) error
- func (a *Address) SetBytes(b []byte)
- func (a Address) String() string
- func (a *Address) UnmarshalGraphQL(input interface{}) error
- func (a *Address) UnmarshalJSON(input []byte) error
- func (a *Address) UnmarshalText(input []byte) error
- func (a Address) Value() (driver.Value, error)
- type Client
- func (ec *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
- func (ec *Client) BlockByHash(ctx context.Context, hash Hash) (*types.Block, error)
- func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
- func (ec *Client) CallContract(ctx context.Context, msg taichain.CallMsg, blockNumber *big.Int) ([]byte, error)
- func (ec *Client) ChainID(ctx context.Context) (*big.Int, error)
- func (ec *Client) Close()
- func (ec *Client) CodeAt(ctx context.Context, account Address, blockNumber *big.Int) ([]byte, error)
- func (ec *Client) Coinbase(ctx context.Context) (string, error)
- func (ec *Client) EstimateGas(ctx context.Context, msg taichain.CallMsg) (uint64, error)
- func (ec *Client) FilterLogs(ctx context.Context, q taichain.FilterQuery) ([]types.Log, error)
- func (ec *Client) FruitByHash(ctx context.Context, hash Hash, fullSigns bool) (*rpcFruit, error)
- func (ec *Client) FruitByNumber(ctx context.Context, number *big.Int, fullSigns bool) (*rpcFruit, error)
- func (ec *Client) FruitCount(ctx context.Context, blockHash Hash) (uint, error)
- func (ec *Client) FruitInBlockByHash(ctx context.Context, snailBlockHash Hash, index uint, fullSigns bool) (*rpcFruit, error)
- func (ec *Client) FruitInBlockByNumber(ctx context.Context, snailBlockNumber *big.Int, index uint, fullSigns bool) (*rpcFruit, error)
- func (ec *Client) GetBalanceAtBlockNumber(ctx context.Context, account Address, blockNumber *big.Int) (*big.Int, error)
- func (ec *Client) GetNonceAtBlockNumber(ctx context.Context, account Address, blockNumber *big.Int) (uint64, error)
- func (ec *Client) GetProtocolVersion(ctx context.Context) (string, error)
- func (ec *Client) HeaderByHash(ctx context.Context, hash Hash) (*types.Header, error)
- func (ec *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
- func (ec *Client) IsMining(ctx context.Context) (bool, error)
- func (ec *Client) ListAccounts(ctx context.Context) ([]common.Address, error)
- func (ec *Client) NetworkID(ctx context.Context) (*big.Int, error)
- func (ec *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
- func (ec *Client) PendingBalanceAt(ctx context.Context, account Address) (*big.Int, error)
- func (ec *Client) PendingCallContract(ctx context.Context, msg taichain.CallMsg) ([]byte, error)
- func (ec *Client) PendingCodeAt(ctx context.Context, account Address) ([]byte, error)
- func (ec *Client) PendingFruitCount(ctx context.Context) (uint, error)
- func (ec *Client) PendingNonceAt(ctx context.Context, account Address) (uint64, error)
- func (ec *Client) PendingStorageAt(ctx context.Context, account Address, key Hash) ([]byte, error)
- func (ec *Client) PendingTransactionCount(ctx context.Context) (uint, error)
- func (ec *Client) SendPayTransaction(ctx context.Context, tx *types.Transaction) error
- func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (ec *Client) SnailBlockByHash(ctx context.Context, hash Hash) (*rpcSnailBlock, error)
- func (ec *Client) SnailBlockByNumber(ctx context.Context, number *big.Int) (*rpcSnailBlock, error)
- func (ec *Client) SnailHeaderByHash(ctx context.Context, hash Hash) (*rpcSnailHeader, error)
- func (ec *Client) SnailHeaderByNumber(ctx context.Context, number *big.Int) (*rpcSnailHeader, error)
- func (ec *Client) StorageAt(ctx context.Context, account Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
- func (ec *Client) SubscribeFilterLogs(ctx context.Context, q taichain.FilterQuery, ch chan<- types.Log) (taichain.Subscription, error)
- func (ec *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (taichain.Subscription, error)
- func (ec *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error)
- func (ec *Client) SyncProgress(ctx context.Context) (*taichain.SyncProgress, error)
- func (ec *Client) TransactionByHash(ctx context.Context, hash Hash) (tx *types.Transaction, isPending bool, err error)
- func (ec *Client) TransactionCount(ctx context.Context, blockHash Hash) (uint, error)
- func (ec *Client) TransactionInBlock(ctx context.Context, blockHash Hash, index uint) (*types.Transaction, error)
- func (ec *Client) TransactionReceipt(ctx context.Context, txHash Hash) (*types.Receipt, error)
- func (ec *Client) TransactionSender(ctx context.Context, tx *types.Transaction, block Hash, index uint) (common.Address, error)
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Bytes() []byte
- func (h Hash) Format(s fmt.State, c rune)
- func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Hash) Hex() string
- func (_ Hash) ImplementsGraphQLType(name string) bool
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) Scan(src interface{}) error
- func (h *Hash) SetBytes(b []byte)
- func (h Hash) String() string
- func (h Hash) TerminalString() string
- func (h *Hash) UnmarshalGraphQL(input interface{}) error
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (h *Hash) UnmarshalText(input []byte) error
- func (h Hash) Value() (driver.Value, error)
- type MixedcaseAddress
- func (ma *MixedcaseAddress) Address() Address
- func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error)
- func (ma *MixedcaseAddress) Original() string
- func (ma *MixedcaseAddress) String() string
- func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error
- func (ma *MixedcaseAddress) ValidChecksum() bool
- type UnprefixedAddress
- type UnprefixedHash
Constants ¶
const ( // HashLength is the expected length of the hash HashLength = 32 // AddressLength is the expected length of the address AddressLength = 20 )
Lengths of hashes and addresses in bytes.
Variables ¶
This section is empty.
Functions ¶
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func Hex2BytesFixed ¶
Hex2BytesFixed returns bytes of a specified fixed length flen.
func IsHexAddress ¶
IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.
func LeftPadBytes ¶
LeftPadBytes zero-pads slice to the left up to length l.
func RightPadBytes ¶
RightPadBytes zero-pads slice to the right up to length l.
func ToHexArray ¶
ToHexArray creates a array of hex-string based on []byte
Types ¶
type Address ¶
type Address [AddressLength]byte
Address represents the 20 byte address of an Ethereum account.
func BigToAddress ¶
BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.
func BytesToAddress ¶
BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.
func HexToAddress ¶
HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.
func (Address) Format ¶
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (Address) ImplementsGraphQLType ¶
ImplementsGraphQLType returns true if Hash implements the specified GraphQL type.
func (Address) MarshalText ¶
MarshalText returns the hex representation of a.
func (*Address) SetBytes ¶
SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.
func (*Address) UnmarshalGraphQL ¶
UnmarshalGraphQL unmarshals the provided GraphQL query data.
func (*Address) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Address) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines typed wrappers for the Ethereum RPC API.
func (*Client) BalanceAt ¶
func (ec *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
BalanceAt returns the wei balance of the given account. The block number can be nil, in which case the balance is taken from the latest known block.
func (*Client) BlockByHash ¶
BlockByHash returns the given full block.
Note that loading full blocks requires two requests. Use HeaderByHash if you don't need all transactions or uncle headers.
func (*Client) BlockByNumber ¶
BlockByNumber returns a block from the current canonical chain. If number is nil, the latest known block is returned.
Note that loading full blocks requires two requests. Use HeaderByNumber if you don't need all transactions or uncle headers.
func (*Client) CallContract ¶
func (ec *Client) CallContract(ctx context.Context, msg taichain.CallMsg, blockNumber *big.Int) ([]byte, error)
CallContract executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.
blockNumber selects the block height at which the call runs. It can be nil, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available.
func (*Client) ChainID ¶
SnailBlockchain Access ChainId retrieves the current chain ID for transaction replay protection.
func (*Client) CodeAt ¶
func (ec *Client) CodeAt(ctx context.Context, account Address, blockNumber *big.Int) ([]byte, error)
CodeAt returns the contract code of the given account. The block number can be nil, in which case the code is taken from the latest known block.
func (*Client) EstimateGas ¶
EstimateGas tries to estimate the gas needed to execute a specific transaction based on the current pending state of the backend blockchain. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.
func (*Client) FilterLogs ¶
FilterLogs executes a filter query.
func (*Client) FruitByHash ¶
FruitByHash returns the given fruit.
Note that loading full blocks requires three requests.
func (*Client) FruitByNumber ¶
func (ec *Client) FruitByNumber(ctx context.Context, number *big.Int, fullSigns bool) (*rpcFruit, error)
FruitByNumber returns a block from the current canonical chain. If number is nil, the latest known fruit is returned.
Note that loading full blocks requires three requests.
func (*Client) FruitCount ¶
FruitCount returns the total number of fruits in the given block.
func (*Client) FruitInBlockByHash ¶
func (ec *Client) FruitInBlockByHash(ctx context.Context, snailBlockHash Hash, index uint, fullSigns bool) (*rpcFruit, error)
FruitInBlockByHash returns a single fruit at index in the given block.
func (*Client) FruitInBlockByNumber ¶
func (ec *Client) FruitInBlockByNumber(ctx context.Context, snailBlockNumber *big.Int, index uint, fullSigns bool) (*rpcFruit, error)
FruitInBlockByNumber returns a single fruit at index in the given block.
func (*Client) GetBalanceAtBlockNumber ¶
func (ec *Client) GetBalanceAtBlockNumber(ctx context.Context, account Address, blockNumber *big.Int) (*big.Int, error)
GetBalanceAtBlockNumber returns the wei balance of the given account. The block number can be nil, in which case the balance is taken from the latest known block.
func (*Client) GetNonceAtBlockNumber ¶
func (ec *Client) GetNonceAtBlockNumber(ctx context.Context, account Address, blockNumber *big.Int) (uint64, error)
GetNonceAtBlockNumber returns the account nonce of the given account. The block number can be nil, in which case the nonce is taken from the latest known block.
func (*Client) GetProtocolVersion ¶
tai_protocolVersion
func (*Client) HeaderByHash ¶
HeaderByHash returns the block header with the given hash.
func (*Client) HeaderByNumber ¶
HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.
func (*Client) ListAccounts ¶
personal_listAccounts
func (*Client) NetworkID ¶
NetworkID returns the network ID (also known as the chain ID) for this chain.
func (*Client) NonceAt ¶
func (ec *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
NonceAt returns the account nonce of the given account. The block number can be nil, in which case the nonce is taken from the latest known block.
func (*Client) PendingBalanceAt ¶
PendingBalanceAt returns the wei balance of the given account in the pending state.
func (*Client) PendingCallContract ¶
PendingCallContract executes a message call transaction using the EVM. The state seen by the contract call is the pending state.
func (*Client) PendingCodeAt ¶
PendingCodeAt returns the contract code of the given account in the pending state.
func (*Client) PendingFruitCount ¶
PendingFruitCount returns the total number of fruits in the pending state.
func (*Client) PendingNonceAt ¶
PendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.
func (*Client) PendingStorageAt ¶
PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.
func (*Client) PendingTransactionCount ¶
PendingTransactionCount returns the total number of transactions in the pending state.
func (*Client) SendPayTransaction ¶
SendPayTransaction injects a signed transaction(both sender and payer) into the pending pool for execution.
If the transaction was a contract creation use the TransactionReceipt method to get the contract address after the transaction has been mined.
func (*Client) SendTransaction ¶
SendTransaction injects a signed transaction into the pending pool for execution.
If the transaction was a contract creation use the TransactionReceipt method to get the contract address after the transaction has been mined.
func (*Client) SnailBlockByHash ¶
SnailBlockByHash returns the given full block.
Note that loading full blocks requires two requests.
func (*Client) SnailBlockByNumber ¶
SnailBlockByNumber returns a block from the current canonical chain. If number is nil, the latest known block is returned.
Note that loading full blocks requires two requests.
func (*Client) SnailHeaderByHash ¶
SnailHeaderByHash returns the block header with the given hash.
func (*Client) SnailHeaderByNumber ¶
func (ec *Client) SnailHeaderByNumber(ctx context.Context, number *big.Int) (*rpcSnailHeader, error)
SnailHeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.
func (*Client) StorageAt ¶
func (ec *Client) StorageAt(ctx context.Context, account Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
StorageAt returns the value of key in the contract storage of the given account. The block number can be nil, in which case the value is taken from the latest known block.
func (*Client) SubscribeFilterLogs ¶
func (ec *Client) SubscribeFilterLogs(ctx context.Context, q taichain.FilterQuery, ch chan<- types.Log) (taichain.Subscription, error)
SubscribeFilterLogs subscribes to the results of a streaming filter query.
func (*Client) SubscribeNewHead ¶
func (ec *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (taichain.Subscription, error)
SubscribeNewHead subscribes to notifications about the current blockchain head on the given channel.
func (*Client) SuggestGasPrice ¶
SuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.
func (*Client) SyncProgress ¶
SyncProgress retrieves the current progress of the sync algorithm. If there's no sync currently running, it returns nil.
func (*Client) TransactionByHash ¶
func (ec *Client) TransactionByHash(ctx context.Context, hash Hash) (tx *types.Transaction, isPending bool, err error)
TransactionByHash returns the transaction with the given hash.
func (*Client) TransactionCount ¶
TransactionCount returns the total number of transactions in the given block.
func (*Client) TransactionInBlock ¶
func (ec *Client) TransactionInBlock(ctx context.Context, blockHash Hash, index uint) (*types.Transaction, error)
TransactionInBlock returns a single transaction at index in the given block.
func (*Client) TransactionReceipt ¶
TransactionReceipt returns the receipt of a transaction by transaction hash. Note that the receipt is not available for pending transactions.
func (*Client) TransactionSender ¶
func (ec *Client) TransactionSender(ctx context.Context, tx *types.Transaction, block Hash, index uint) (common.Address, error)
TransactionSender returns the sender address of the given transaction. The transaction must be known to the remote node and included in the blockchain at the given block and index. The sender is the one derived by the protocol at the time of inclusion.
There is a fast-path for transactions retrieved by TransactionByHash and TransactionInBlock. Getting their sender address can be done without an RPC interaction.
type Hash ¶
type Hash [HashLength]byte
Hash represents the 32 byte Keccak256 hash of arbitrary data.
func BigToHash ¶
BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexToHash ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func (Hash) Format ¶
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (Hash) ImplementsGraphQLType ¶
ImplementsGraphQLType returns true if Hash implements the specified GraphQL type.
func (Hash) MarshalText ¶
MarshalText returns the hex representation of h.
func (*Hash) SetBytes ¶
SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.
func (Hash) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Hash) TerminalString ¶
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Hash) UnmarshalGraphQL ¶
UnmarshalGraphQL unmarshals the provided GraphQL query data.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type MixedcaseAddress ¶
type MixedcaseAddress struct {
// contains filtered or unexported fields
}
MixedcaseAddress retains the original string, which may or may not be correctly checksummed
func NewMixedcaseAddress ¶
func NewMixedcaseAddress(addr Address) MixedcaseAddress
NewMixedcaseAddress constructor (mainly for testing)
func NewMixedcaseAddressFromString ¶
func NewMixedcaseAddressFromString(hexaddr string) (*MixedcaseAddress, error)
NewMixedcaseAddressFromString is mainly meant for unit-testing
func (*MixedcaseAddress) Address ¶
func (ma *MixedcaseAddress) Address() Address
Address returns the address
func (*MixedcaseAddress) MarshalJSON ¶
func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error)
MarshalJSON marshals the original value
func (*MixedcaseAddress) Original ¶
func (ma *MixedcaseAddress) Original() string
Original returns the mixed-case input string
func (*MixedcaseAddress) String ¶
func (ma *MixedcaseAddress) String() string
String implements fmt.Stringer
func (*MixedcaseAddress) UnmarshalJSON ¶
func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error
UnmarshalJSON parses MixedcaseAddress
func (*MixedcaseAddress) ValidChecksum ¶
func (ma *MixedcaseAddress) ValidChecksum() bool
ValidChecksum returns true if the address has valid checksum
type UnprefixedAddress ¶
type UnprefixedAddress Address
UnprefixedAddress allows marshaling an Address without 0x prefix.
func (UnprefixedAddress) MarshalText ¶
func (a UnprefixedAddress) MarshalText() ([]byte, error)
MarshalText encodes the address as hex.
func (*UnprefixedAddress) UnmarshalText ¶
func (a *UnprefixedAddress) UnmarshalText(input []byte) error
UnmarshalText decodes the address from hex. The 0x prefix is optional.
type UnprefixedHash ¶
type UnprefixedHash Hash
UnprefixedHash allows marshaling a Hash without 0x prefix.
func (UnprefixedHash) MarshalText ¶
func (h UnprefixedHash) MarshalText() ([]byte, error)
MarshalText encodes the hash as hex.
func (*UnprefixedHash) UnmarshalText ¶
func (h *UnprefixedHash) UnmarshalText(input []byte) error
UnmarshalText decodes the hash from hex. The 0x prefix is optional.