Documentation ¶
Overview ¶
The package is designed to be flexible and adaptable to various Ethereum-compatible networks like Ethereum mainnet, Binance Smart Chain (BSC), and Polygon. It provides a structured approach to handle accounts across these networks, making it easier for developers to interact with different blockchain environments through a unified interface.
Index ¶
- Constants
- type Account
- func (a *Account) Balance(ctx context.Context, blockNum *big.Int) (*big.Int, error)
- func (a *Account) DecodePassword() (string, error)
- func (a *Account) GetAddress() common.Address
- func (a *Account) GetClient() *clients.Client
- func (a *Account) HasTag(tag string) bool
- func (a *Account) SaveToPath(path string) error
- func (a *Account) SetAccountBalance(ctx context.Context, amount *big.Int) error
- func (a *Account) SetClient(client *clients.Client)
- func (a *Account) TransactOpts(client *clients.Client, amount *big.Int, simulate bool) (*bind.TransactOpts, error)
- func (a *Account) Transfer(ctx context.Context, to common.Address, value *big.Int) (*types.Transaction, error)
- type Manager
- func (m *Manager) Create(network utils.Network, password string, pin bool, tags ...string) (*Account, error)
- func (m *Manager) Delete(network utils.Network, address common.Address) error
- func (m *Manager) Get(network utils.Network, address common.Address) (*Account, error)
- func (m *Manager) GetConfig() *Options
- func (m *Manager) GetKeystore(network utils.Network) (*keystore.KeyStore, error)
- func (m *Manager) GetNetworkPath(network utils.Network) string
- func (m *Manager) List(network utils.Network, tags ...string) []*Account
- func (m *Manager) Load() error
- type Options
Constants ¶
const (
DEFAULT_GAS_LIMIT = uint64(90000)
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { *keystore.KeyStore `json:"-" yaml:"-"` // KeyStore for managing account keys Address common.Address `json:"address" yaml:"address"` // Ethereum address of the account Type utils.AccountType `json:"type" yaml:"type"` // Account type PrivateKey string `json:"private_key" yaml:"private_key"` // Private key of the account PublicKey string `json:"public_key" yaml:"public_key"` // Public key of the account KeystoreAccount account.Account `json:"account" yaml:"account"` // Ethereum account information Password string `json:"password" yaml:"password"` // Account's password Network utils.Network `json:"network" yaml:"network"` // Network information Tags []string `json:"tags" yaml:"tags"` // Arbitrary tags for the account // contains filtered or unexported fields }
Account represents an Ethereum account with extended functionalities. It embeds ClientPool for network interactions and KeyStore for account management. It also includes fields for account details, network information, and additional tags.
func LoadAccount ¶
LoadAccount loads an account from a JSON file located at a given path. The method reads the file, unmarshals the JSON content into an Account struct, and returns the populated Account instance or an error if the loading process fails.
func (*Account) Balance ¶
Balance retrieves the account's balance from the Ethereum network at a specified block number. Returns the balance as *big.Int or an error if the balance query fails.
func (*Account) DecodePassword ¶
DecodePassword decodes the base64-encoded password. Returns the decoded password or an error if decoding fails.
func (*Account) GetAddress ¶
GetAddress retrieves the Ethereum address of the account.
func (*Account) GetClient ¶
GetClient retrieves the assigned Ethereum client associated with the account.
func (*Account) HasTag ¶
HasTag checks if the account has a specific tag. Returns true if the tag exists, false otherwise.
func (*Account) SaveToPath ¶
SaveToPath serializes the account information and writes it to a specified file path. The account data is saved in JSON format. Returns an error if the writing process fails.
func (*Account) SetAccountBalance ¶
SetAccountBalance sets the account's balance to a specific amount. This method is mainly used for testing purposes in simulation environments like Anvil. It does not affect the real balance on the Ethereum network.
func (*Account) SetClient ¶
SetClient assigns a specific Ethereum client to the account for network interactions.
func (*Account) TransactOpts ¶
func (a *Account) TransactOpts(client *clients.Client, amount *big.Int, simulate bool) (*bind.TransactOpts, error)
TransactOpts generates transaction options for interacting with the Ethereum network. It configures nonce, gas price, gas limit, and value for the transaction. The method also handles different account types: simple and keystore-based accounts. For simple accounts, it directly uses the provided private key. For keystore accounts, it decrypts the key using the stored password. If 'simulate' is true, it returns transaction options without signing.
func (*Account) Transfer ¶
func (a *Account) Transfer(ctx context.Context, to common.Address, value *big.Int) (*types.Transaction, error)
Transfer initiates an Ethereum transfer from this account to another address. It ensures the account has sufficient balance and then constructs and signs a transaction. The method uses the account's stored passphrase for signing. Returns the signed transaction or an error if the transfer process fails.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles the account operations across various Ethereum networks. It maintains a map of keystores and accounts for each supported network.
func NewManager ¶
NewManager initializes a new Manager instance. It checks for the existence of keystore paths and supported networks, and loads existing accounts from the keystore.
func (*Manager) Create ¶
func (m *Manager) Create(network utils.Network, password string, pin bool, tags ...string) (*Account, error)
Create creates a new account for a given network with a specified password and optional tags. It saves the account to the network's keystore path and adds it to the accounts map.
func (*Manager) Delete ¶
Delete removes an account for a given network by its address. It deletes the account from both the keystore and the Manager's accounts map. Returns an error if the account is not found or if there's an issue with deletion.
func (*Manager) Get ¶
Get retrieves a specific account by its address for a given network. Returns an error if the account is not found.
func (*Manager) GetKeystore ¶
GetKeystore retrieves the keystore for a given network. Returns an error if the network is not supported.
func (*Manager) GetNetworkPath ¶
GetNetworkPath returns the file path for a given network's keystore.
type Options ¶
type Options struct { // KeystorePath specifies the file system path to the directory where the keystore files are stored. // The keystore is used to securely store the private keys of Ethereum accounts. KeystorePath string `json:"keystore_path" yaml:"keystore_path"` // SupportedNetworks lists the Ethereum based networks that the account manager will interact with. // Each network has a corresponding keystore and set of account configurations. SupportedNetworks []utils.Network `json:"supported_networks" yaml:"supported_networks"` }
Options defines the configuration parameters for account management.