Documentation ¶
Index ¶
- Variables
- func SaveToCSV(path string, data interface{}) error
- type BatchResult
- type CreateTx
- type Option
- func SetBatchSize(batchSize uint64) Option
- func SetConcurrent(concurrent bool) Option
- func SetGasFeeCap(gasFeeCap *big.Int) Option
- func SetGasLimit(gasLimit uint64) Option
- func SetGasTipCap(gasTipCap *big.Int) Option
- func SetNonce(nonce int64) Option
- func SetPrivKey(privKey *ecdsa.PrivateKey) Option
- type Payload
- type Pool
- type Queue
- type Result
- type SendMode
- type Stat
- type Transactor
- type TransactorOpts
- type TxGenerator
- func (tg *TxGenerator) BatchGenTxs(sender *ecdsa.PrivateKey, senderNonce *big.Int) ([]*Payload, error)
- func (tg *TxGenerator) GenTx(sender *ecdsa.PrivateKey, senderNonce *big.Int) (*Payload, error)
- func (tg *TxGenerator) RandomBatchGenTxs() ([]*Payload, error)
- func (tg *TxGenerator) RandomGenTx() (*Payload, error)
- func (tg *TxGenerator) Run() ([]*Payload, bool, error)
- type Verifier
Constants ¶
This section is empty.
Variables ¶
var ErrExit = errors.New("exit")
ErrExit is an error that indicates the generator should exit.
Functions ¶
func SaveToCSV ¶
SaveToCSV saves the given data to a CSV file at the specified path.
The function takes two parameters: - path: a string representing the directory path where the CSV file will be saved. - data: an interface{} representing the data that will be saved to the CSV file.
The function returns an error if any error occurs during the file operations.
Types ¶
type BatchResult ¶
type BatchResult struct {
// contains filtered or unexported fields
}
BatchResult represents the result of a batch of transactions.
type CreateTx ¶
type CreateTx func(opts *bind.TransactOpts) (*types.Transaction, error)
CreateTx is a function type that can create or send transactions.
type Option ¶
type Option func(*TxGenerator) *TxGenerator
Option is a function type that can be used to configure the TxGenerator.
func SetBatchSize ¶
SetBatchSize sets the batch size for the TxGenerator.
It takes a batchSize parameter of type uint64 and returns an Option.
func SetConcurrent ¶
SetConcurrent returns an Option function that sets the concurrent flag of a TxGenerator object.
Parameters:
concurrent - a boolean value indicating whether the TxGenerator should be executed concurrently.
Returns:
An Option function that sets the concurrent flag and returns the modified TxGenerator object.
func SetGasFeeCap ¶
SetGasFeeCap sets the gas fee cap for the TxGenerator.
Parameters: - gasFeeCap: A pointer to a big.Int representing the gas fee cap.
Returns: - An Option function that sets the gas fee cap for the TxGenerator.
func SetGasLimit ¶
SetGasLimit sets the gas limit option for the TxGenerator.
func SetGasTipCap ¶
SetGasTipCap sets the gas tip cap option for the TxGenerator.
gasTipCap: A pointer to a big.Int representing the gas tip cap. Returns: An Option function that sets the gas tip cap for the TxGenerator.
func SetNonce ¶
SetNonce sets the nonce value for the TxGenerator.
Parameter: - nonce: the nonce value to set.
Return: - *TxGenerator: the updated TxGenerator.
func SetPrivKey ¶
func SetPrivKey(privKey *ecdsa.PrivateKey) Option
SetPrivKey sets the private key for the TxGenerator.
privKey: the private key string. Returns: the TxGenerator with the updated private key.
type Payload ¶
type Payload struct { Tx *types.Transaction `csv:"-"` RawTx string `csv:"raw_tx"` ChainID string `csv:"chain_id"` }
Payload is a struct that contains the raw transaction and the chain ID.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a pool of goroutines that can be used to execute tasks.
func NewPool ¶
NewPool creates a new pool with the specified size.
Parameters: - size: an integer representing the size of the pool.
Returns: - a pointer to a Pool object.
func (*Pool) Close ¶
func (p *Pool) Close()
Close stops the goroutines in the Pool and waits for them to finish.
No parameters. No return types.
func (*Pool) Finish ¶
func (p *Pool) Finish()
Finish waits until all goroutines have finished.
No parameters. No return types.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue is a wrapper of github.com/eapache/queue/v2.Queue
func NewQueue ¶
NewQueue creates a new Queue instance.
This function does not take any parameters. It returns a pointer to a Queue[T] object.
func (*Queue[T]) Add ¶
func (q *Queue[T]) Add(v T)
Add adds the given value to the queue.
It takes a single parameter: - v: the value to be added to the queue.
func (*Queue[T]) Iterate ¶
Iterate iterates over the elements of the queue and applies a function to each element.
f: The function to apply to each element of the queue. It takes an element as a parameter and returns a boolean value.
If the function returns true, the element will be removed from the queue. If the function returns false, the element will not be removed from the queue.
func (*Queue[T]) IterateParallel ¶
IterateParallel iterates over the elements in the queue in parallel and applies a function to each element.
The function `f` is applied to each element in the queue. If the function returns `true`, the element is removed from the queue. The function does not guarantee the order in which the elements are processed.
type Result ¶
type Result struct { Batch int64 TotalFailedTxCount int64 TotalTxCount atomic.Int64 StartTime time.Time EndTime time.Time MinResponseTime int64 MaxResponseTime int64 }
Result represents the result of a transaction.
type SendMode ¶
type SendMode string
SendMode represents the mode of sending transactions.
const ( // OneByOne represents sending transactions one by one. OneByOne SendMode = "oneByOne" // Parallel represents sending transactions in parallel. Parallel SendMode = "parallel" // Segment represents sending transactions in segments. Segment SendMode = "segment" // Batch represents sending transactions in batches. Batch SendMode = "batch" )
func ParseSendMode ¶
ParseSendMode parses the input string and returns the corresponding SendMode constant if it matches one of the defined modes. Otherwise, it returns an error.
Parameters: - mode: The input string to be parsed.
Return types: - SendMode: The corresponding SendMode constant. - error: An error if the input string does not match any defined modes.
type Transactor ¶
type Transactor struct {
// contains filtered or unexported fields
}
Transactor is a struct that can be used to send transactions.
func NewTransactor ¶
func NewTransactor(eth *ethclient.Client, maxConcurrentNum int, gen *TxGenerator, enable bool, opts ...TransactorOpts) *Transactor
NewTransactor creates a new Transactor instance.
It takes in an ethclient.Client pointer, a Pool pointer, and a TxGenerator pointer as parameters. It returns a pointer to a Transactor.
func (*Transactor) Exit ¶
func (t *Transactor) Exit()
Exit closes the batch and tallyCh channels, closes the pool, and prints the result.
No parameters. No return type.
func (*Transactor) Run ¶
func (t *Transactor) Run()
Run runs the Transactor.
It starts the producer and consumer goroutines to handle transaction processing. The function waits for a signal on the exit channel. If the signal is received, it prints statistics about the transaction processing, closes the transaction pool, and returns.
func (*Transactor) Stop ¶
func (t *Transactor) Stop()
Stop stops the Transactor.
No parameters. No return types.
type TransactorOpts ¶
type TransactorOpts func(*Transactor) *Transactor
TransactorOpts is a function that takes in a pointer to a Transactor object
func SetEndTime ¶
func SetEndTime(endTime time.Time) TransactorOpts
SetEndTime sets the end time for a TransactorOpts function.
endTime: the end time to be set (int64). Returns: a function that sets the end time for a Transactor (TransactorOpts).
func SetSendMode ¶
func SetSendMode(sendMode SendMode) TransactorOpts
SetSendMode sets the send mode for the TransactorOpts.
Parameters: - sendMode: the send mode to be set.
Returns: - a function that sets the send mode and returns the Transactor.
func SetTotalBatch ¶
func SetTotalBatch(totalBatch int64) TransactorOpts
SetTotalBatch sets the total batch value for the TransactorOpts.
totalBatch: The total batch value to be set. Returns: The modified TransactorOpts.
type TxGenerator ¶
type TxGenerator struct {
// contains filtered or unexported fields
}
TxGenerator generates transactions for the TicketGame contract.
func NewTxGenerator ¶
func NewTxGenerator( chainID *big.Int, createTx CreateTx, pool *Pool, options ...Option, ) *TxGenerator
NewTxGenerator initializes a new instance of the TxGenerator struct.
It takes the chainID, createOrSendTx, and pool as parameters. The chainID is a pointer to a big.Int type, representing the chain ID. The createOrSendTx is a function type that can be used to create or send transactions. The pool is a pointer to the Pool struct, representing a transaction pool.
It returns a pointer to the TxGenerator struct.
func (*TxGenerator) BatchGenTxs ¶
func (tg *TxGenerator) BatchGenTxs(sender *ecdsa.PrivateKey, senderNonce *big.Int) ([]*Payload, error)
BatchGenTxs generates a batch of transactions using the given sender's private key, sender's nonce, batch size, and player address.
Parameters: - sender: The sender's private key for signing the transactions. - senderNonce: The nonce value of the sender's account. - batchSize: The number of transactions to generate in the batch. - player: The address of the player to include in the transactions.
Return: - []string: The generated transactions as a slice of strings.
func (*TxGenerator) GenTx ¶
func (tg *TxGenerator) GenTx(sender *ecdsa.PrivateKey, senderNonce *big.Int) (*Payload, error)
GenTx generates a transaction using the provided sender's private key, sender nonce, and player address.
Parameters: - sender: The private key of the sender. - senderNonce: The nonce of the sender. - player: The address of the player.
Returns: - The hexadecimal representation of the generated transaction.
func (*TxGenerator) RandomBatchGenTxs ¶
func (tg *TxGenerator) RandomBatchGenTxs() ([]*Payload, error)
RandomBatchGenTxs generates a batch of random transactions.
It takes in the batchSize parameter, which specifies the number of transactions to generate in the batch. The player parameter is used to specify the address of the player associated with the transactions.
The function returns a slice of strings, which represents the generated transactions.
func (*TxGenerator) RandomGenTx ¶
func (tg *TxGenerator) RandomGenTx() (*Payload, error)
RandomGenTx generates a random transaction for the given player address.
player: the address of the player. Returns: the hex string representation of the generated transaction.
func (*TxGenerator) Run ¶
func (tg *TxGenerator) Run() ([]*Payload, bool, error)
Run runs the TxGenerator.
It generates a batch of transactions based on the TxGenerator's configuration. If the TxGenerator is concurrent, it calls the RandomBatchGenTxs method to generate the transactions. If the TxGenerator has a private key, it calls the BatchGenTxs method to generate the transactions using the private key. If neither of the above conditions are met, it generates a new private key and calls the BatchGenTxs method to generate the transactions. It returns the generated transactions and any error that occurred.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier is a struct that verifies the hashes in the queue.
func NewVerifier ¶
NewVerifier creates a new Verifier instance.
enable: a boolean indicating whether the Verifier is enabled. eth: an instance of ethclient.Client used for interacting with the Ethereum blockchain. Returns a pointer to the newly created Verifier instance.
func (*Verifier) Add ¶
Add adds a hash to the Verifier.
The parameter `hash` is the hash to be added to the Verifier.