Documentation ¶
Index ¶
- func Accounts(numValidators int) *env.AccountsConfig
- func BuildConfig(accounts *env.AccountsConfig) (*genesis.Config, *eth.Config, error)
- func ValueTransferTransaction(client *ethclient.Client, senderKey *ecdsa.PrivateKey, ...) (*types.Transaction, error)
- type MarshalableECDSAPrivateKey
- type MarshalableNodeConfig
- type MarshalableP2PConfig
- type Network
- type Node
- func (n *Node) AwaitSentTransactions(ctx context.Context) error
- func (n *Node) AwaitTransactions(ctx context.Context, txs ...*types.Transaction) error
- func (n *Node) Close() error
- func (n *Node) ProcessedTxBlock(tx *types.Transaction) *types.Block
- func (n *Node) SendCelo(ctx context.Context, recipient common.Address, value int64) (*types.Transaction, error)
- func (n *Node) SendCeloTracked(ctx context.Context, recipient common.Address, value int64) (*types.Transaction, error)
- func (n *Node) Start() error
- func (n *Node) TxFee(ctx context.Context, tx *types.Transaction) (*big.Int, error)
- type Tracker
- func (tr *Tracker) AwaitBlock(ctx context.Context, num uint64) error
- func (tr *Tracker) AwaitTransactions(ctx context.Context, hashes []common.Hash) error
- func (tr *Tracker) GetProcessedBlock(num uint64) *types.Block
- func (tr *Tracker) GetProcessedBlockForTx(hash common.Hash) *types.Block
- func (tr *Tracker) GetProcessedTx(hash common.Hash) *types.Transaction
- func (tr *Tracker) StartTracking(client *ethclient.Client) error
- func (tr *Tracker) StopTracking() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accounts ¶
func Accounts(numValidators int) *env.AccountsConfig
func BuildConfig ¶
BuildConfig generates genesis and eth config instances, that can be modified before passing to NewNetwork or NewNode.
NOTE: Do not edit the Istanbul field of the returned genesis config it will be overwritten with the corresponding config from the Istanbul field of the returned eth config.
func ValueTransferTransaction ¶
func ValueTransferTransaction( client *ethclient.Client, senderKey *ecdsa.PrivateKey, sender, recipient common.Address, nonce uint64, value *big.Int, signer types.Signer, ) (*types.Transaction, error)
ValueTransferTransaction builds a signed value transfer transaction from the sender to the recipient with the given value and nonce, it uses the client to suggest a gas price and to estimate the gas.
Types ¶
type MarshalableECDSAPrivateKey ¶
type MarshalableECDSAPrivateKey ecdsa.PrivateKey
func (*MarshalableECDSAPrivateKey) MarshalJSON ¶
func (k *MarshalableECDSAPrivateKey) MarshalJSON() ([]byte, error)
func (*MarshalableECDSAPrivateKey) UnmarshalJSON ¶
func (k *MarshalableECDSAPrivateKey) UnmarshalJSON(b []byte) error
type MarshalableNodeConfig ¶
type MarshalableNodeConfig struct { node.Config P2P MarshalableP2PConfig }
type MarshalableP2PConfig ¶
type MarshalableP2PConfig struct { p2p.Config PrivateKey *MarshalableECDSAPrivateKey }
type Network ¶
type Network []*Node
Network represents a network of nodes and provides functionality to easily create, start and stop a collection of nodes.
func NewNetwork ¶
NewNetwork generates a network of nodes that are running and mining. For each provided validator account a corresponding node is created and each node is also assigned a developer account, there must be at least as many developer accounts provided as validator accounts. If there is an error it will be returned immediately, meaning that some nodes may be running and others not.
func (Network) AwaitBlock ¶
AwaitBlock ensures that the entire network has processed a block with the given num.
func (Network) AwaitTransactions ¶
AwaitTransactions ensures that the entire network has processed the provided transactions.
type Node ¶
type Node struct { *node.Node Config *node.Config P2PListenAddr string Eth *eth.Ethereum EthConfig *eth.Config WsClient *ethclient.Client Nonce uint64 Key *ecdsa.PrivateKey Address common.Address DevKey *ecdsa.PrivateKey DevAddress common.Address Tracker *Tracker // The transactions that this node has sent. SentTxs []*types.Transaction }
Node provides an enhanced interface to node.Node with useful additions, the *node.Node is embedded so that its api is available through Node.
func NewNode ¶
func NewNode( validatorAccount, devAccount *env.Account, nc *node.Config, ec *eth.Config, genesis *core.Genesis, ) (*Node, error)
NewNode creates a new running node with the provided config.
func (*Node) AwaitSentTransactions ¶
AwaitSentTransactions awaits all the transactions that this node has sent via SendCelo.
func (*Node) AwaitTransactions ¶
AwaitTransactions awaits all the provided transactions.
func (*Node) Close ¶
Close shuts down the node and releases all resources and removes the datadir unless an error is returned, in which case there is no guarantee that all resources are released.
func (*Node) ProcessedTxBlock ¶
func (n *Node) ProcessedTxBlock(tx *types.Transaction) *types.Block
ProcessedTxBlock returns the block that the given transaction was processed in, nil will be retuned if the transaction has not been processed by this node.
func (*Node) SendCelo ¶
func (n *Node) SendCelo(ctx context.Context, recipient common.Address, value int64) (*types.Transaction, error)
SendCelo submits a value transfer transaction to the network to send celo to the recipient. The submitted transaction is returned.
func (*Node) SendCeloTracked ¶
func (n *Node) SendCeloTracked(ctx context.Context, recipient common.Address, value int64) (*types.Transaction, error)
SendCeloTracked functions like SendCelo but also waits for the transaction to be processed.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker tracks processed blocks and transactions through a subscription with an ethclient. It provides the ability to check whether blocks or transactions have been processed and to wait till those blocks or transactions have been processed.
func (*Tracker) AwaitBlock ¶
AwaitBlock waits for a block with the given num to be processed, it will return the ctx.Err() if ctx expires before a block with that number has been processed or ErrStopped if StopTracking is called before a block with that number is processed.
func (*Tracker) AwaitTransactions ¶
AwaitTransactions waits for the transactions listed in hashes to be processed, it will return the ctx.Err() if ctx expires before all the transactions in hashes were processed or ErrStopped if StopTracking is called before all the transactions in hashes were processed.
func (*Tracker) GetProcessedBlock ¶
GetProcessedBlock returns processed block with the given num or nil if the tracker has not seen a processed block with that num.
func (*Tracker) GetProcessedBlockForTx ¶
GetProcessedBlockForTx returns the block that a transaction with the given hash was processed in or nil if the tracker has not seen a processed transaction with the given hash.
func (*Tracker) GetProcessedTx ¶
func (tr *Tracker) GetProcessedTx(hash common.Hash) *types.Transaction
GetProcessedTx returns the processed transaction with the given hash or nil if the tracker has not seen a processed transaction with the given hash.
func (*Tracker) StartTracking ¶
StartTracking subscribes to new head events on the client and starts processing the events in a goroutine.
func (*Tracker) StopTracking ¶
StopTracking shuts down all the goroutines in the tracker.