ethrpc

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// parity
	ParitySubscribe           = "parity_subscribe"
	ParityPendingTransactions = "parity_pendingTransactions"

	// geth
	GETHTxPoolContent = "txpool_content"

	// net
	NetPeerCount = "net_peerCount"

	// web3
	WEB3ClientVersion = "web3_clientVersion"

	// eth
	ETHBlockNumber                      = "eth_blockNumber"
	ETHCall                             = "eth_call"
	ETHGetBalance                       = "eth_getBalance"
	ETHGetBlockByNumber                 = "eth_getBlockByNumber"
	ETHGetBlockTransactionCountByNumber = "eth_getBlockTransactionCountByNumber"
	ETHGetCode                          = "eth_getCode"
	ETHGetFilterChanges                 = "eth_getFilterChanges"
	ETHGetTransactionByHash             = "eth_getTransactionByHash"
	ETHGetTransactionReceipt            = "eth_getTransactionReceipt"
	ETHGetUncleByBlockHashAndIndex      = "eth_getUncleByBlockHashAndIndex"
	ETHGetUncleByBlockNumberAndIndex    = "eth_getUncleByBlockNumberAndIndex"
	ETHPendingTransactionFilter         = "eth_newPendingTransactionFilter"
	ETHSubscribe                        = "eth_subscribe"

	// trace
	TraceBlock                   = "trace_block"
	TraceReplayBlockTransactions = "trace_replayBlockTransactions"

	// eth pubsub
	ETHNewHeads               = "newHeads"
	ETHNewPendingTransactions = "newPendingTransactions"

	// consts
	ClientGETH   = "geth"
	ClientParity = "parity"
)

json rpc methods

View Source
const (
	// functions
	NameFunction         = "0x06fdde03"
	ApproveFunction      = "0x095ea7b3" // mandatory
	TotalSupplyFunction  = "0x18160ddd" // mandatory
	TransferFromFunction = "0x23b872dd" // mandatory
	DecimalsFunction     = "0x313ce567"
	IssueTokensFunction  = "0x475a9fa9"
	BalanceOfFunction    = "0x70a08231" // mandatory
	SymbolFunction       = "0x95d89b41"
	TransferFunction     = "0xa9059cbb" // mandatory
	AllowanceFunction    = "0xdd62ed3e" // mandatory

	// events
	TransferEvent = "0xddf252ad" // mandatory
	ApprovalEvent = "0x8c5be1e5" // mandatory
)

ERC20 signatures

View Source
const (
	// DefaultCallGas is the default gas to use for eth_calls
	DefaultCallGas = "0xffffff"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ETH

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

ETH server interaction

func New

func New(provider provider.Interface) (*ETH, error)

New create a new ethereum server json rpc interface

func NewWithDefaults

func NewWithDefaults(url string) (*ETH, error)

NewWithDefaults selects the proper provider based on protocol

func (*ETH) CallContractFunction

func (e *ETH) CallContractFunction(function string, address string, gas string) (string, error)

CallContractFunction calls a contract's function and returns the result as string

func (*ETH) CallContractFunctionBigInt

func (e *ETH) CallContractFunctionBigInt(function string, address string) (*big.Int, error)

CallContractFunctionBigInt calls a contract's function and returns a decoded int64

func (*ETH) CallContractFunctionInt64

func (e *ETH) CallContractFunctionInt64(function string, address string) (int64, error)

CallContractFunctionInt64 calls a contract's function and returns a decoded int64

func (*ETH) GetBalanceAtBlock

func (e *ETH) GetBalanceAtBlock(address, blockNumber string) (*big.Int, error)

GetBalanceAtBlock returns the balance of an address at a given blockNumber as a big.Int

func (*ETH) GetBlockByNumber

func (e *ETH) GetBlockByNumber(number string) (b types.Block, err error)

GetBlockByNumber gets specified block with full transaction array

func (*ETH) GetBlockNumber

func (e *ETH) GetBlockNumber() (int64, error)

GetBlockNumber returns the number of most recent block.

func (*ETH) GetBlockTransactionCountByNumber

func (e *ETH) GetBlockTransactionCountByNumber(number string) (count string, err error)

GetBlockTransactionCountByNumber https://wiki.parity.io/JSONRPC-eth-module.html#eth_getblocktransactioncountbynumber

func (*ETH) GetClient

func (e *ETH) GetClient() (string, error)

GetClient gets current eth client version string

func (*ETH) GetCode

func (e *ETH) GetCode(a string) ([]byte, error)

GetCode returns the bytecode of a contract

func (*ETH) GetContractName

func (e *ETH) GetContractName(address string) (string, error)

GetContractName calls a contract's name function

func (*ETH) GetContractSymbol

func (e *ETH) GetContractSymbol(address string) (string, error)

GetContractSymbol calls a contract's name function

func (*ETH) GetContractTotalSupply

func (e *ETH) GetContractTotalSupply(address string) (*big.Int, error)

GetContractTotalSupply calls a contract's totalSupply function

func (*ETH) GetERC20Decimals

func (e *ETH) GetERC20Decimals(address string) (uint8, error)

GetERC20Decimals calls a contract's decimal function

func (*ETH) GetFilterChanges

func (e *ETH) GetFilterChanges(id string) (t []interface{}, err error)

GetFilterChanges gets filtered entities, since last poll or set filter

func (*ETH) GetLatestBlock

func (e *ETH) GetLatestBlock() (b types.Block, err error)

GetLatestBlock with or without full transactions array

func (*ETH) GetPeerCount

func (e *ETH) GetPeerCount() (peers int64, err error)

GetPeerCount gets current peer count

func (*ETH) GetPendingFilterChanges

func (e *ETH) GetPendingFilterChanges(id string) (t []string, err error)

GetPendingFilterChanges gets all pending transactions, filtered, since last poll or set filter

func (*ETH) GetPendingTransactions

func (e *ETH) GetPendingTransactions() ([]types.Transaction, error)

GetPendingTransactions gets full array of pending transactions

func (*ETH) GetRawBalanceAtBlock

func (e *ETH) GetRawBalanceAtBlock(address, blockNumber string) (string, error)

GetRawBalanceAtBlock returns the balance of an address at a given blockNumber as a hex string

func (*ETH) GetRawTokenBalanceAtBlock

func (e *ETH) GetRawTokenBalanceAtBlock(address, token, blockNumber string) (string, error)

GetRawTokenBalanceAtBlock returns the token balance of an address at a given blockNumber as a hex string

func (*ETH) GetTokenBalanceAtBlock

func (e *ETH) GetTokenBalanceAtBlock(address, token, blockNumber string) (*big.Int, error)

GetTokenBalanceAtBlock returns the token balance of an address at a given blockNumber as a big.Int

func (*ETH) GetTransactionByHash

func (e *ETH) GetTransactionByHash(hash string) (types.Transaction, error)

GetTransactionByHash gets a transaction by transaction hash

func (*ETH) GetTransactionReceipt

func (e *ETH) GetTransactionReceipt(hash string) (r types.Receipt, err error)

GetTransactionReceipt gets the transaction receipt ofr a specific transaction hash

func (*ETH) GetUncleByBlockHashAndIndex

func (e *ETH) GetUncleByBlockHashAndIndex(hash string, index string) (b types.Block, err error)

GetUncleByBlockHashAndIndex retrieves the index-nth uncle of the block with the hash blockHash

func (*ETH) GetUncleByBlockNumberAndIndex

func (e *ETH) GetUncleByBlockNumberAndIndex(blockNumber string, index string) (b types.Block, err error)

GetUncleByBlockNumberAndIndex retrieves the index-nth uncle of the block with the number blockNumber

func (*ETH) GetVersion

func (e *ETH) GetVersion() (ver string, err error)

GetVersion gets current eth client version string

func (*ETH) MakeRequest

func (e *ETH) MakeRequest(result interface{}, method string, params ...interface{}) error

MakeRequest to server

func (*ETH) MakeRequestRaw

func (e *ETH) MakeRequestRaw(method string, params ...interface{}) ([]byte, error)

MakeRequestRaw to server

func (*ETH) NewBlockNumberSubscription

func (e *ETH) NewBlockNumberSubscription() (r chan *int64, err error)

NewBlockNumberSubscription parity_subscribe to eth_blockNumber

func (*ETH) NewHeadsSubscription

func (e *ETH) NewHeadsSubscription() (r chan *types.BlockHeader, err error)

NewHeadsSubscription eth_subscribe to newHeads

func (*ETH) NewPendingTransactionsSubscription

func (e *ETH) NewPendingTransactionsSubscription() (r chan *string, err error)

NewPendingTransactionsSubscription eth_subscribe to newPendingTransactions

func (*ETH) SetPendingTransactionsFilter

func (e *ETH) SetPendingTransactionsFilter() (id string, err error)

SetPendingTransactionsFilter sets pending transaction filter for ETHGetFilterChanges

func (*ETH) Start

func (e *ETH) Start() error

Start connects to parity and starts listening for notifications

func (*ETH) Stop

func (e *ETH) Stop()

Stop closes the connection

func (*ETH) Subscribe

func (e *ETH) Subscribe(receiver chan *json.RawMessage, method string, event string, params ...interface{}) error

Subscribe to topic

func (*ETH) TraceBlock

func (e *ETH) TraceBlock(blockNumber string) ([]types.Trace, error)

Traces

func (*ETH) TraceReplayBlockTransactions

func (e *ETH) TraceReplayBlockTransactions(blockNumber string, traceTypes ...string) ([]types.TransactionReplay, error)

type ETHInterface

type ETHInterface interface {
	CallContractFunction(function string, address string, gas string) (string, error)
	CallContractFunctionBigInt(function string, address string) (*big.Int, error)
	CallContractFunctionInt64(function string, address string) (int64, error)
	GetBalanceAtBlock(address, blockNumber string) (*big.Int, error)
	GetBlockByNumber(number string) (b types.Block, err error)
	GetBlockNumber() (int64, error)
	GetBlockTransactionCountByNumber(number string) (count string, err error)
	GetClient() (string, error)
	GetCode(a string) ([]byte, error)
	GetContractName(address string) (string, error)
	GetContractSymbol(address string) (string, error)
	GetContractTotalSupply(address string) (*big.Int, error)
	GetERC20Decimals(address string) (uint8, error)
	GetFilterChanges(id string) (t []interface{}, err error)
	GetLatestBlock() (b types.Block, err error)
	GetPeerCount() (peers int64, err error)
	GetPendingFilterChanges(id string) (t []string, err error)
	GetPendingTransactions() ([]types.Transaction, error)
	GetRawBalanceAtBlock(address, blockNumber string) (string, error)
	GetRawTokenBalanceAtBlock(address, token, blockNumber string) (string, error)
	GetTokenBalanceAtBlock(address, token, blockNumber string) (*big.Int, error)
	GetTransactionByHash(hash string) (types.Transaction, error)
	GetTransactionReceipt(hash string) (r types.Receipt, err error)
	GetUncleByBlockHashAndIndex(hash string, index string) (b types.Block, err error)
	GetUncleByBlockNumberAndIndex(blockNumber string, index string) (b types.Block, err error)
	GetVersion() (ver string, err error)
	TraceBlock(blockNumber string) ([]types.Trace, error)
	TraceReplayBlockTransactions(blockNumber string, traceTypes ...string) ([]types.TransactionReplay, error)
	MakeRequest(result interface{}, method string, params ...interface{}) error
	NewBlockNumberSubscription() (r chan *int64, err error)
	NewHeadsSubscription() (r chan *types.BlockHeader, err error)
	NewPendingTransactionsSubscription() (r chan *string, err error)
	SetPendingTransactionsFilter() (id string, err error)
	Start() error
	Stop()
	Subscribe(receiver chan *json.RawMessage, method string, event string, params ...interface{}) error
}

ETHInterface defines the packages interface

Directories

Path Synopsis
httprpc
Inspired by https://github.com/vektah/dataloaden with some tweaks
Inspired by https://github.com/vektah/dataloaden with some tweaks

Jump to

Keyboard shortcuts

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