Documentation ¶
Overview ¶
util.go is a collection of utility functions to deploy and interact with a Maltcoin ERC20 token contract. The contained functions serve a simulated backend as well as an actual connection to a running blockchain node.
Index ¶
- Variables
- func DeployContractAndCommit(auth *bind.TransactOpts, client *backends.SimulatedBackend) (common.Address, *types.Transaction, *maltcoin.Maltcoin, error)
- func FillTransactionSignerFields(auth *bind.TransactOpts, client *ethclient.Client, callMsg ethereum.CallMsg) (*bind.TransactOpts, error)
- func GeneratePrivKeysAndAddresses(n uint64) ([]*ecdsa.PrivateKey, []common.Address, error)
- func GetCallData(name string, args ...interface{}) ([]byte, error)
- func GetClient() (*ethclient.Client, error)
- func GetClientAndTransactionSigner(privKey *ecdsa.PrivateKey) (*ethclient.Client, *bind.TransactOpts, error)
- func GetReceipt(backend ReceiptBackend, txHashHex string) (*types.Receipt, error)
- func GetSimulatedClientAndTransactionSigner(privKey *ecdsa.PrivateKey, blockGasLimit uint64, chainID *big.Int) (*backends.SimulatedBackend, *bind.TransactOpts, error)
- type ReceiptBackend
Constants ¶
This section is empty.
Variables ¶
var ( // Defines the max gas per block for the simulated backend MaxGasPerBlock = uint64(5000000) // Defines 10^18 as a big integer Ten18 = big.NewInt(1e18) // According to the go-ethereum docs, the chain ID for simulated // backends must be 1337 // (https://pkg.go.dev/github.com/ethereum/go-ethereum@v1.10.19/accounts/abi/bind/backends#NewSimulatedBackend). TestChainID = big.NewInt(1337) )
Functions ¶
func DeployContractAndCommit ¶
func DeployContractAndCommit(auth *bind.TransactOpts, client *backends.SimulatedBackend) (common.Address, *types.Transaction, *maltcoin.Maltcoin, error)
DeployContractAndCommit deploys an instance of the ERC20 token contract and commits the transaction to the simulated backend. The function returns the contract address, the transaction, and an instance of the contract binding.
func FillTransactionSignerFields ¶
func FillTransactionSignerFields(auth *bind.TransactOpts, client *ethclient.Client, callMsg ethereum.CallMsg) (*bind.TransactOpts, error)
FillTransactionSignerFields takes the transaction signer, the client and a byte array of the data to be called in a transaction. It gathers necessary gas price, nonce and estimated gas and assigns these to the fields of the transaction signer, which the function then returns.
func GeneratePrivKeysAndAddresses ¶
GeneratePrivKeysAndAddresses returns a slice of private keys and addresses.
func GetCallData ¶
GetCallData returns the necessary byte array to fill an ethereum.CallMsg struct's data field. This data is a byte representation of the method call paired with its corresponding arguments.
func GetClient ¶
GetClient connects to a local blockchain node and returns the client. This is only a wrapper function to use the preconfigured blockchain URL.
func GetClientAndTransactionSigner ¶
func GetClientAndTransactionSigner(privKey *ecdsa.PrivateKey) (*ethclient.Client, *bind.TransactOpts, error)
GetClientAndTransactionSigner connects to a local Evmos node on port 8545, queries the chain id and uses this together with the private key to create a transaction signer. The function returns the client and the transaction signer.
func GetReceipt ¶
func GetReceipt(backend ReceiptBackend, txHashHex string) (*types.Receipt, error)
GetReceipt converts a given transaction hash in hex string format and returns the transaction receipt, if the hash is valid.
func GetSimulatedClientAndTransactionSigner ¶
func GetSimulatedClientAndTransactionSigner(privKey *ecdsa.PrivateKey, blockGasLimit uint64, chainID *big.Int) (*backends.SimulatedBackend, *bind.TransactOpts, error)
GetSimulatedClientAndTransactionSigner establishes a new simulated backend for testing purposes. An initial token balance is assigned to the address of the given private key. The maximum gas a block can consume is defined with the blockGasLimit input. The private key and chain id are used to create a transaction signer for any transactions on the blockchain. The function returns the client and the transaction signer.