web3

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: BSD-3-Clause, BSD-3-Clause Imports: 15 Imported by: 8

README

web3go (obsolete)

web3go is an Ethereum client library that implements Ethereum JSON RPC, just like [web3.js](https://githu b.com/ethereum/web3.js).

Gitter Go Report Card

Branch Test status
master Test Status codecov
develop Test Status codecov

Latest version

No stable version yet

Installation

go get github.com/DSiSc/web3go/...

Usage

TBD

License

The BSD 3-Clause License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChannelClosed = errors.New("Channel is closed")
)

Functions

This section is empty.

Types

type Eth

type Eth interface {
	ProtocolVersion() (string, error)
	Syncing() (common.SyncStatus, error)
	Coinbase() (common.Address, error)
	Mining() (bool, error)
	HashRate() (uint64, error)
	GasPrice() (*big.Int, error)
	Accounts() ([]common.Address, error)
	BlockNumber() (*big.Int, error)
	GetBalance(address common.Address, quantity string) (*big.Int, error)
	GetStorageAt(address common.Address, position uint64, quantity string) (uint64, error)
	GetTransactionCount(address common.Address, quantity string) (*big.Int, error)
	GetBlockTransactionCountByHash(hash common.Hash) (*big.Int, error)
	GetBlockTransactionCountByNumber(quantity string) (*big.Int, error)
	GetUncleCountByBlockHash(hash common.Hash) (*big.Int, error)
	GetUncleCountByBlockNumber(quantity string) (*big.Int, error)
	GetCode(address common.Address, quantity string) ([]byte, error)
	Sign(address common.Address, data []byte) ([]byte, error)
	SendTransaction(tx *common.TransactionRequest) (common.Hash, error)
	SendRawTransaction(tx []byte) (common.Hash, error)
	SendCrossRawTransaction(tx []byte, url string) (common.Hash, error)
	ReceiveCrossRawTransactionReq(tx []byte) (common.Hash, error)
	Call(tx *common.TransactionRequest, quantity string) ([]byte, error)
	EstimateGas(tx *common.TransactionRequest, quantity string) (*big.Int, error)
	GetBlockByHash(hash common.Hash, full bool) (*common.Block, error)
	GetBlockByNumber(quantity string, full bool) (*common.Block, error)
	GetTransactionByHash(hash common.Hash) (*common.Transaction, error)
	GetTransactionByBlockHashAndIndex(hash common.Hash, index uint64) (*common.Transaction, error)
	GetTransactionByBlockNumberAndIndex(quantity string, index uint64) (*common.Transaction, error)
	GetTransactionReceipt(hash common.Hash) (*common.TransactionReceipt, error)
	GetUncleByBlockHashAndIndex(hash common.Hash, index uint64) (*common.Block, error)
	GetUncleByBlockNumberAndIndex(quantity string, index uint64) (*common.Block, error)
	GetCompilers() ([]string, error)
	// GompileLLL
	// CompileSolidity
	// CompileSerpent
	NewFilter(option *FilterOption) (Filter, error)
	NewBlockFilter() (Filter, error)
	NewPendingTransactionFilter() (Filter, error)
	UninstallFilter(filter Filter) (bool, error)
	GetFilterChanges(filter Filter) ([]interface{}, error)
	GetFilterLogs(filter Filter) ([]interface{}, error)
	GetLogs(filter Filter) ([]interface{}, error)
	GetWork() (common.Hash, common.Hash, common.Hash, error)
	SubmitWork(nonce uint64, header common.Hash, mixDigest common.Hash) (bool, error)
}

Eth ...

type EthAPI

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

EthAPI ...

func (*EthAPI) Accounts

func (eth *EthAPI) Accounts() (addrs []common.Address, err error)

Accounts returns a list of addresses owned by client.

func (*EthAPI) BlockNumber

func (eth *EthAPI) BlockNumber() (result *big.Int, err error)

BlockNumber returns the number of most recent block.

func (*EthAPI) Call

func (eth *EthAPI) Call(tx *common.TransactionRequest, quantity string) ([]byte, error)

Call executes a new message call immediately without creating a transaction on the block chain.

func (*EthAPI) Coinbase

func (eth *EthAPI) Coinbase() (addr common.Address, err error)

Coinbase returns the client coinbase address.

func (*EthAPI) EstimateGas

func (eth *EthAPI) EstimateGas(tx *common.TransactionRequest, quantity string) (result *big.Int, err error)

EstimateGas makes a call or transaction, which won't be added to the blockchain and returns the used gas, which can be used for estimating the used gas.

func (*EthAPI) GasPrice

func (eth *EthAPI) GasPrice() (result *big.Int, err error)

GasPrice returns the current price per gas in wei.

func (*EthAPI) GetBalance

func (eth *EthAPI) GetBalance(address common.Address, quantity string) (result *big.Int, err error)

GetBalance returns the balance of the account of given address.

func (*EthAPI) GetBlockByHash

func (eth *EthAPI) GetBlockByHash(hash common.Hash, full bool) (*common.Block, error)

GetBlockByHash returns information about a block by hash.

func (*EthAPI) GetBlockByNumber

func (eth *EthAPI) GetBlockByNumber(quantity string, full bool) (*common.Block, error)

GetBlockByNumber returns information about a block by block number.

func (*EthAPI) GetBlockTransactionCountByHash

func (eth *EthAPI) GetBlockTransactionCountByHash(hash common.Hash) (result *big.Int, err error)

GetBlockTransactionCountByHash returns the number of transactions in a block from a block matching the given block hash.

func (*EthAPI) GetBlockTransactionCountByNumber

func (eth *EthAPI) GetBlockTransactionCountByNumber(quantity string) (result *big.Int, err error)

GetBlockTransactionCountByNumber returns the number of transactions in a block from a block matching the given block number.

func (*EthAPI) GetCode

func (eth *EthAPI) GetCode(address common.Address, quantity string) ([]byte, error)

GetCode returns code at a given address.

func (*EthAPI) GetCompilers

func (eth *EthAPI) GetCompilers() (result []string, err error)

GetCompilers returns a list of available compilers in the client.

func (*EthAPI) GetFilterChanges

func (eth *EthAPI) GetFilterChanges(filter Filter) (result []interface{}, err error)

GetFilterChanges polling method for a filter, which returns an array of logs which occurred since last poll.

func (*EthAPI) GetFilterLogs

func (eth *EthAPI) GetFilterLogs(filter Filter) (result []interface{}, err error)

GetFilterLogs returns an array of all logs matching filter with given id.

func (*EthAPI) GetLogs

func (eth *EthAPI) GetLogs(filter Filter) (result []interface{}, err error)

GetLogs returns an array of all logs matching a given filter object.

func (*EthAPI) GetStorageAt

func (eth *EthAPI) GetStorageAt(address common.Address, position uint64, quantity string) (uint64, error)

GetStorageAt returns the value from a storage position at a given address.

func (*EthAPI) GetTransactionByBlockHashAndIndex

func (eth *EthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, index uint64) (*common.Transaction, error)

GetTransactionByBlockHashAndIndex returns information about a transaction by block hash and transaction index position.

func (*EthAPI) GetTransactionByBlockNumberAndIndex

func (eth *EthAPI) GetTransactionByBlockNumberAndIndex(quantity string, index uint64) (*common.Transaction, error)

GetTransactionByBlockNumberAndIndex returns information about a transaction by block number and transaction index position.

func (*EthAPI) GetTransactionByHash

func (eth *EthAPI) GetTransactionByHash(hash common.Hash) (*common.Transaction, error)

GetTransactionByHash returns the information about a transaction requested by transaction hash.

func (*EthAPI) GetTransactionCount

func (eth *EthAPI) GetTransactionCount(address common.Address, quantity string) (result *big.Int, err error)

GetTransactionCount returns the number of transactions sent from an address.

func (*EthAPI) GetTransactionReceipt

func (eth *EthAPI) GetTransactionReceipt(hash common.Hash) (*common.TransactionReceipt, error)

GetTransactionReceipt Returns the receipt of a transaction by transaction hash.

func (*EthAPI) GetUncleByBlockHashAndIndex

func (eth *EthAPI) GetUncleByBlockHashAndIndex(hash common.Hash, index uint64) (*common.Block, error)

GetUncleByBlockHashAndIndex returns information about a uncle of a block by hash and uncle index position.

func (*EthAPI) GetUncleByBlockNumberAndIndex

func (eth *EthAPI) GetUncleByBlockNumberAndIndex(quantity string, index uint64) (*common.Block, error)

GetUncleByBlockNumberAndIndex returns information about a uncle of a block by number and uncle index position.

func (*EthAPI) GetUncleCountByBlockHash

func (eth *EthAPI) GetUncleCountByBlockHash(hash common.Hash) (result *big.Int, err error)

GetUncleCountByBlockHash returns the number of uncles in a block from a block matching the given block hash.

func (*EthAPI) GetUncleCountByBlockNumber

func (eth *EthAPI) GetUncleCountByBlockNumber(quantity string) (result *big.Int, err error)

GetUncleCountByBlockNumber returns the number of uncles in a block from a block matching the given block number.

func (*EthAPI) GetWork

func (eth *EthAPI) GetWork() (header, seed, boundary common.Hash, err error)

GetWork returns the hash of the current block, the seedHash, and the boundary condition to be met ("target").

func (*EthAPI) HashRate

func (eth *EthAPI) HashRate() (uint64, error)

HashRate returns the number of hashes per second that the node is mining with.

func (*EthAPI) Mining

func (eth *EthAPI) Mining() (bool, error)

Mining returns true if client is actively mining new blocks.

func (*EthAPI) NewBlockFilter

func (eth *EthAPI) NewBlockFilter() (Filter, error)

NewBlockFilter creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call eth_getFilterChanges.

func (*EthAPI) NewFilter

func (eth *EthAPI) NewFilter(option *FilterOption) (Filter, error)

NewFilter creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call eth_getFilterChanges.

func (*EthAPI) NewPendingTransactionFilter

func (eth *EthAPI) NewPendingTransactionFilter() (Filter, error)

NewPendingTransactionFilter creates a filter in the node, to notify when new pending transactions arrive. To check if the state has changed, call eth_getFilterChanges.

func (*EthAPI) ProtocolVersion

func (eth *EthAPI) ProtocolVersion() (string, error)

ProtocolVersion returns the current ethereum protocol version.

func (*EthAPI) ReceiveCrossRawTransactionReq added in v1.1.0

func (eth *EthAPI) ReceiveCrossRawTransactionReq(tx []byte) (common.Hash, error)

ReceiveCrossRawTransaction creates new message call transaction or a contract creation for signed transactions. Must call sendCrossRawTransaction before this

func (*EthAPI) SendCrossRawTransaction added in v1.1.0

func (eth *EthAPI) SendCrossRawTransaction(tx []byte, url string) (common.Hash, error)

SendCrossRawTransaction creates new message call transaction or a contract creation for signed transactions.

func (*EthAPI) SendRawTransaction

func (eth *EthAPI) SendRawTransaction(tx []byte) (hash common.Hash, err error)

SendRawTransaction creates new message call transaction or a contract creation for signed transactions.

func (*EthAPI) SendTransaction

func (eth *EthAPI) SendTransaction(tx *common.TransactionRequest) (hash common.Hash, err error)

SendTransaction creates new message call transaction or a contract creation, if the data field contains code.

func (*EthAPI) Sign

func (eth *EthAPI) Sign(address common.Address, data []byte) ([]byte, error)

Sign signs data with a given address.

func (*EthAPI) SubmitWork

func (eth *EthAPI) SubmitWork(nonce uint64, header, mixDigest common.Hash) (bool, error)

SubmitWork is used for submitting a proof-of-work solution.

func (*EthAPI) Syncing

func (eth *EthAPI) Syncing() (common.SyncStatus, error)

Syncing returns true with an object with data about the sync status or false with nil.

func (*EthAPI) UninstallFilter

func (eth *EthAPI) UninstallFilter(filter Filter) (bool, error)

UninstallFilter uninstalls a filter with given id. Should always be called when watch is no longer needed. Additonally Filters timeout when they aren't requested with eth_getFilterChanges for a period of time.

type Filter

type Filter interface {
	Watch() WatchChannel
	ID() uint64
}

Filter ...

type FilterOption

type FilterOption struct {
	FromBlock string        `json:"fromBlock,omitempty"`
	ToBlock   string        `json:"toBlock,omitempty"`
	Address   interface{}   `json:"address,omitempty"`
	Topics    common.Topics `json:"topics,omitempty"`
}

FilterOption ...

func (*FilterOption) String

func (opt *FilterOption) String() string

type FilterType

type FilterType int
const (
	TypeNormal FilterType = iota
	TypeBlockFilter
	TypeTransactionFilter
)

type Net

type Net interface {
	Version() (string, error)
	PeerCount() (uint64, error)
	Listening() (bool, error)
}

Net ...

type NetAPI

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

NetAPI ...

func (*NetAPI) Listening

func (net *NetAPI) Listening() (bool, error)

Listening returns true if client is actively listening for network connections.

func (*NetAPI) PeerCount

func (net *NetAPI) PeerCount() (uint64, error)

PeerCount returns number of peers currenly connected to the client.

func (*NetAPI) Version

func (net *NetAPI) Version() (string, error)

Version returns the current network protocol version.

type WatchChannel

type WatchChannel interface {
	Next() (interface{}, error)
	Close()
}

WatchChannel ...

type Web3

type Web3 struct {
	Eth Eth
	Net Net
	// contains filtered or unexported fields
}

Web3 Standard interface See https://github.com/ethereum/wiki/wiki/JavaScript-API#web3js-api-reference

func NewWeb3

func NewWeb3(provider provider.Provider) *Web3

NewWeb3 creates a new web3 object.

func (*Web3) CurrentProvider

func (web3 *Web3) CurrentProvider() provider.Provider

CurrentProvider returns the current provider.

func (*Web3) FromASCII

func (web3 *Web3) FromASCII(textString string, padding int) string

FromASCII converts any ASCII string to a HEX string.

func (*Web3) FromDecimal

func (web3 *Web3) FromDecimal(value interface{}) string

FromDecimal converts value to it"s hex representation.

func (*Web3) FromWei

func (web3 *Web3) FromWei(number string, unit string) string

FromWei takes a number of wei and converts it to any other ether unit.

Possible units are:

SI Short   SI Full        Effigy       Other

- kwei femtoether babbage - mwei picoether lovelace - gwei nanoether shannon nano - -- microether szabo micro - -- microether szabo micro - -- milliether finney milli - ether -- -- - kether -- grand - mether - gether - tether

func (*Web3) IsAddress

func (web3 *Web3) IsAddress(address string) bool

IsAddress checks if the given string is an address.

func (*Web3) IsConnected

func (web3 *Web3) IsConnected() bool

IsConnected checks if a connection to a node exists.

func (*Web3) Reset

func (web3 *Web3) Reset(keepSyncing bool)

Reset state of web3. Resets everything except manager. Uninstalls all filters. Stops polling. If keepSyncing is true, it will uninstall all filters, but will keep the web3.eth.IsSyncing() polls.

func (*Web3) SetProvider

func (web3 *Web3) SetProvider(provider provider.Provider)

SetProvider sets provider.

func (*Web3) Sha3

func (web3 *Web3) Sha3(data string, options interface{}) string

Sha3 returns Keccak-256 (not the standardized SHA3-256) of the given data.

func (*Web3) ToASCII

func (web3 *Web3) ToASCII(hexString string) string

ToASCII converts a HEX string into a ASCII string.

func (*Web3) ToBigNumber

func (web3 *Web3) ToBigNumber(value interface{}) (result *big.Rat)

ToBigNumber takes an input and transforms it into an *big.Rat.

func (*Web3) ToDecimal

func (web3 *Web3) ToDecimal(value interface{}) string

ToDecimal converts value to it"s decimal representation in string.

func (*Web3) ToHex

func (web3 *Web3) ToHex(value interface{}) string

ToHex converts any value into HEX.

func (*Web3) ToWei

func (web3 *Web3) ToWei(number interface{}, unit string) string

ToWei takes a number of a unit and converts it to wei.

Possible units are:

SI Short   SI Full        Effigy       Other

- kwei femtoether babbage - mwei picoether lovelace - gwei nanoether shannon nano - -- microether szabo micro - -- microether szabo micro - -- milliether finney milli - ether -- -- - kether -- grand - mether - gether - tether

Directories

Path Synopsis
example
Package rlp implements the RLP serialization format.
Package rlp implements the RLP serialization format.

Jump to

Keyboard shortcuts

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