Documentation ¶
Index ¶
- Variables
- func AccountConfig(numValidators, numExternal int) *env.AccountsConfig
- func BuildConfig(accounts *env.AccountsConfig) (*genesis.Config, *ethconfig.Config, error)
- func GenerateGenesis(accounts *env.AccountsConfig, gc *genesis.Config, contractsBuildPath string) (*core.Genesis, error)
- func ValueTransferTransaction(client *ethclient.Client, senderKey *ecdsa.PrivateKey, ...) (*types.Transaction, error)
- func ValueTransferTransactionWithDynamicFee(client *ethclient.Client, senderKey *ecdsa.PrivateKey, ...) (*types.Transaction, error)
- type Account
- func (a *Account) SendCelo(ctx context.Context, recipient common.Address, value int64, node *Node) (*types.Transaction, error)
- func (a *Account) SendCeloTracked(ctx context.Context, recipient common.Address, value int64, node *Node) (*types.Transaction, error)
- func (a *Account) SendCeloWithDynamicFee(ctx context.Context, recipient common.Address, value int64, gasFeeCap *big.Int, ...) (*types.Transaction, error)
- type BalanceWatcher
- type Balances
- type MarshalableECDSAPrivateKey
- type MarshalableNodeConfig
- type MarshalableP2PConfig
- type Network
- type Node
- func (n *Node) AddPeers(nodes ...*Node)
- func (n *Node) AwaitTransactions(ctx context.Context, txs ...*types.Transaction) error
- func (n *Node) Close() error
- func (n *Node) GossipEnodeCertificatge() error
- func (n *Node) ProcessedTxBlock(tx *types.Transaction) *types.Block
- func (n *Node) Start() error
- func (n *Node) TxFee(ctx context.Context, tx *types.Transaction) (*big.Int, error)
- type Token
- 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 ¶
var ( BaseEthConfig = ð.Config{ SyncMode: downloader.FullSync, MinSyncPeers: 1, DatabaseCache: 256, DatabaseHandles: 256, TxPool: core.DefaultTxPoolConfig, RPCEthCompatibility: true, Istanbul: istanbul.Config{ Validator: true, AnnounceQueryEnodeGossipPeriod: 60, RequestTimeout: 200, TimeoutBackoffFactor: 200, MinResendRoundChangeTimeout: 200, MaxResendRoundChangeTimeout: 10000, Epoch: 20, ProposerPolicy: istanbul.ShuffledRoundRobin, DefaultLookbackWindow: 3, BlockPeriod: 0, }, } )
var (
ErrTrackerAlreadyStopped = errors.New("attempted to stop already stopped tracker")
)
Functions ¶
func AccountConfig ¶
func AccountConfig(numValidators, numExternal 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 GenerateGenesis ¶
func GenerateGenesis(accounts *env.AccountsConfig, gc *genesis.Config, contractsBuildPath string) (*core.Genesis, error)
GenerateGenesis checks that the contractsBuildPath exists and if so proceeds to generate the genesis.
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.
func ValueTransferTransactionWithDynamicFee ¶
func ValueTransferTransactionWithDynamicFee( client *ethclient.Client, senderKey *ecdsa.PrivateKey, sender, recipient common.Address, nonce uint64, value *big.Int, gasFeeCap *big.Int, gasTipCap *big.Int, signer types.Signer, ) (*types.Transaction, error)
ValueTransferTransactionWithDynamicFee builds a signed value transfer transaction from the sender to the recipient with the given value, nonce, gasFeeCap and gasTipCap.
Types ¶
type Account ¶
type Account struct { Address common.Address Key *ecdsa.PrivateKey ChainConfig *params.ChainConfig Nonce *uint64 }
func Accounts ¶
func Accounts(accts []env.Account, chainConfig *params.ChainConfig) []*Account
Accounts converts a slice of env.Account objects to Account objects.
func NewAccount ¶
func NewAccount(key *ecdsa.PrivateKey, address common.Address, chainConfig *params.ChainConfig) *Account
func (*Account) SendCelo ¶
func (a *Account) SendCelo(ctx context.Context, recipient common.Address, value int64, node *Node) (*types.Transaction, error)
SendCelo submits a value transfer transaction via the provided Node to send celo to the recipient. The submitted transaction is returned.
func (*Account) SendCeloTracked ¶
func (a *Account) SendCeloTracked(ctx context.Context, recipient common.Address, value int64, node *Node) (*types.Transaction, error)
SendCeloTracked functions like SendCelo but also waits for the transaction to be processed by the sending node.
func (*Account) SendCeloWithDynamicFee ¶
func (a *Account) SendCeloWithDynamicFee(ctx context.Context, recipient common.Address, value int64, gasFeeCap *big.Int, gasTipCap *big.Int, node *Node) (*types.Transaction, error)
SendCelo submits a value transfer transaction via the provided Node to send celo to the recipient. The submitted transaction is returned.
type BalanceWatcher ¶
type BalanceWatcher struct {
// contains filtered or unexported fields
}
BalanceWatcher is a helper to watch balance changes over addresses.
func NewBalanceWatcher ¶
func NewBalanceWatcher(client *ethclient.Client, addresses []common.Address) *BalanceWatcher
NewBalanceWatcher creates a BalanceWatcher, records initial balances of the accounts.
func (*BalanceWatcher) Current ¶
func (w *BalanceWatcher) Current(address common.Address) *big.Int
Current returns current balance of given address.
func (*BalanceWatcher) Delta ¶
func (w *BalanceWatcher) Delta(address common.Address) *big.Int
Delta returns difference between current and initial balance of given address for given token.
func (*BalanceWatcher) Initial ¶
func (w *BalanceWatcher) Initial(address common.Address) *big.Int
Initial returns initial balance of given address, or nil if address is not found.
func (*BalanceWatcher) Update ¶
func (w *BalanceWatcher) Update()
Update updates current balances in the BalanceWatcher
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 ¶
func NewNetwork(accounts *env.AccountsConfig, gc *genesis.Config, ec *eth.Config) (Network, func(), error)
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. A shutdown function is also returned which will shutdown and clean up the network when called. In the case that an error is returned the shutdown function will be nil and so no attempt should be made to call it.
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 Enode *enode.Node Eth *eth.Ethereum EthConfig *eth.Config WsClient *ethclient.Client Key *ecdsa.PrivateKey Address 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 *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) 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. It is assumed that this is only called after calling Start otherwise it will panic.
func (*Node) GossipEnodeCertificatge ¶
GossipEnodeCertificatge gossips this nodes enode certificates to the rest of the network.
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.
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.