cpclient

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: GPL-3.0 Imports: 15 Imported by: 32

Documentation

Overview

Package cpchain provides a client for the Cpchain RPC API.

Index

Constants

View Source
const (
	Committee = iota
	Candidate
	Civilian
)

node status

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockGenerationInfo

type BlockGenerationInfo struct {
	ProposerIndex uint64
	View          uint64
	Term          uint64
	Proposer      common.Address
	BlockNumber   uint64 // high
	TermLen       int
	Proposers     []common.Address
}

type BlockNumber

type BlockNumber struct {
	Number string
}

type Client

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

Client defines typed wrappers for the Ethereum RPC API.

func Dial

func Dial(rawurl string) (*Client, error)

Dial connects a client to the given URL.

func DialContext

func DialContext(ctx context.Context, rawurl string) (*Client, error)

func NewClient

func NewClient(c *rpc.Client) *Client

NewClient creates a client that uses the given RPC client.

func (*Client) BalanceAt

func (c *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

func (c *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)

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

func (c *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

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 (c *Client) CallContract(ctx context.Context, msg cpchain.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) Campaign

func (c *Client) Campaign(ctx context.Context, terms uint64) error

func (*Client) ChainConfig

func (c *Client) ChainConfig() (*configs.ChainConfig, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) CodeAt

func (c *Client) CodeAt(ctx context.Context, account common.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

func (c *Client) EstimateGas(ctx context.Context, msg cpchain.CallMsg) (uint64, error)

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

func (c *Client) FilterLogs(ctx context.Context, q cpchain.FilterQuery) ([]types.Log, error)

FilterLogs executes a filter query.

func (*Client) GetBlockGenerationInfo

func (c *Client) GetBlockGenerationInfo(ctx context.Context) (BlockGenerationInfo, error)

func (*Client) GetBlockNumber

func (c *Client) GetBlockNumber() *big.Int

func (*Client) GetBlockReward

func (c *Client) GetBlockReward(ctx context.Context, blockNumber *big.Int) *big.Int

GetBlockReward returns the mining reward for the block number

func (*Client) GetCommitteeNumber

func (c *Client) GetCommitteeNumber(ctx context.Context) (int, error)

func (*Client) GetCurrentTerm

func (c *Client) GetCurrentTerm(ctx context.Context) (uint64, error)

func (*Client) GetCurrentView

func (c *Client) GetCurrentView(ctx context.Context) (uint64, error)

func (*Client) GetProposerByBlock

func (c *Client) GetProposerByBlock(ctx context.Context, blockNumber *big.Int) (common.Address, error)

get the proposer specified by block

func (*Client) GetProposersByBlockNumber

func (c *Client) GetProposersByBlockNumber(ctx context.Context, blockNumber *big.Int) ([]common.Address, error)

get the proposers of the term specified by block

func (*Client) GetRNodes

func (c *Client) GetRNodes(ctx context.Context) ([]RNodes, error)

func (*Client) GetValidatorsByBlockNumber

func (c *Client) GetValidatorsByBlockNumber(ctx context.Context, blockNumber *big.Int) ([]common.Address, error)

get the validators specified by block

func (*Client) HeaderByHash

func (c *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)

HeaderByHash returns the block header with the given hash.

func (*Client) HeaderByNumber

func (c *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*Client) NetworkID

func (c *Client) NetworkID(ctx context.Context) (*big.Int, error)

NetworkID returns the network ID (also known as the chain ID) for this chain.

func (*Client) NonceAt

func (c *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

func (c *Client) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)

PendingBalanceAt returns the wei balance of the given account in the pending state.

func (*Client) PendingCallContract

func (c *Client) PendingCallContract(ctx context.Context, msg cpchain.CallMsg) ([]byte, error)

PendingCallContract executes a message call transaction using the EVM. The state seen by the contract call is the pending state.

func (*Client) PendingCodeAt

func (c *Client) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

PendingCodeAt returns the contract code of the given account in the pending state.

func (*Client) PendingNonceAt

func (c *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

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

func (c *Client) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)

PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.

func (*Client) PendingTransactionCount

func (c *Client) PendingTransactionCount(ctx context.Context) (uint, error)

PendingTransactionCount returns the total number of transactions in the pending state.

func (*Client) SendTransaction

func (c *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error

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) StorageAt

func (c *Client) StorageAt(ctx context.Context, account common.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 (c *Client) SubscribeFilterLogs(ctx context.Context, q cpchain.FilterQuery, ch chan<- types.Log) (cpchain.Subscription, error)

SubscribeFilterLogs subscribes to the results of a streaming filter query.

func (*Client) SubscribeNewHead

func (c *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (cpchain.Subscription, error)

SubscribeNewHead subscribes to notifications about the current blockchain head on the given channel.

func (*Client) SuggestGasPrice

func (c *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.

func (*Client) SupportPrivateTx

func (c *Client) SupportPrivateTx(ctx context.Context) (bool, error)

func (*Client) SyncProgress

func (c *Client) SyncProgress(ctx context.Context) (*cpchain.SyncProgress, error)

SyncProgress retrieves the current progress of the sync algorithm. If there's no sync currently running, it returns nil.

func (*Client) TransactionByHash

func (c *Client) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)

TransactionByHash returns the transaction with the given hash.

func (*Client) TransactionCount

func (c *Client) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)

TransactionCount returns the total number of transactions in the given block.

func (*Client) TransactionInBlock

func (c *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)

TransactionInBlock returns a single transaction at index in the given block.

func (*Client) TransactionReceipt

func (c *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

TransactionReceipt returns the receipt of a transaction by transaction hash. Note that the receipt is not available for pending transactions.

func (*Client) TransactionSender

func (c *Client) TransactionSender(ctx context.Context, tx *types.Transaction, block common.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 RNodes

type RNodes struct {
	Address common.Address // RNodes address
	Rpt     int64
	Status  int
}

Jump to

Keyboard shortcuts

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