web3_actions

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnvilSessionLockHeader = "X-Anvil-Session-Lock-ID"
	DurableExecutionID     = "Durable-Execution-ID"
	EndSessionLockID       = "X-End-Session-Lock-ID"
	RouteGroupHeader       = "X-Route-Group"

	EthereumMainnetTableHeaderKeyValue = "ethereum-mainnet"

	XProcedureHeader = "X-Routing-Procedure"

	EthJsonRpcMaxBlockAggReduceProcedureKeyValue = "eth_maxBlockAggReduce"

	LoadBalancingStrategy    = "X-Load-Balancing-Strategy"
	Adaptive                 = "Adaptive"
	AdaptiveLoadBalancingKey = "X-Adaptive-Metrics-Key"
	JsonRpcAdaptiveMetrics   = "JSON-RPC"
)
View Source
const (
	ERC20     = "erc20"
	Transfer  = "transfer"
	Decimals  = "decimals"
	BalanceOf = "balanceOf"
	Pause     = "pause"
	Resume    = "resume"
	Upgrade   = "upgrade"
	Approve   = "approve"
	Name      = "name"
	Symbol    = "symbol"
)
View Source
const (
	TestnetURL = "https://testnet-rpc.gochain.io"
	MainnetURL = "https://rpc.gochain.io"
)
View Source
const (
	NonceOffset = "nonceOffset"
)
View Source
const (
	Owner = "owner"
)

Variables

View Source
var Networks = map[string]Network{
	"testnet": {
		Name:        "testnet",
		URL:         TestnetURL,
		ChainID:     big.NewInt(31337),
		Unit:        "GO",
		ExplorerURL: testnetExplorerURL,
	},
	"gochain": {
		Name:        "gochain",
		URL:         MainnetURL,
		ChainID:     big.NewInt(60),
		Unit:        "GO",
		ExplorerURL: mainnetExplorerURL,
	},
	"localhost": {
		Name: "localhost",
		URL:  "http://localhost:8545",
		Unit: "GO",
	},
	"ethereum": {
		Name: "ethereum",
		URL:  "https://mainnet.infura.io/v3/bc5b0e5cfd9b4385befb69a68a9400c3",

		ChainID:     big.NewInt(1),
		Unit:        "ETH",
		ExplorerURL: "https://etherscan.io",
	},
}
View Source
var NotFoundErr = errors.New("not found")

Functions

func FindEventById

func FindEventById(abi abi.ABI, id common.Hash) *abi.Event

func GetNonceOffset

func GetNonceOffset(ctx context.Context) uint64

func GetSender

func GetSender(tx *types.Transaction) (common.Address, error)

func GetSlot

func GetSlot(userAddress string, slot *big.Int) (string, error)

func ListContract

func ListContract(ctx context.Context, contractFile string) error

func SetNonceOffset

func SetNonceOffset(ctx context.Context, offset uint64) context.Context

func ValidateToAddress

func ValidateToAddress(ctx context.Context, toAddress string) error

Types

type CallMsg

type CallMsg struct {
	From      *accounts.Address // the sender of the 'transaction'
	To        *accounts.Address // the destination contract (nil for contract creation)
	Gas       uint64            // if 0, the call executes with near-infinite gas
	GasPrice  *big.Int          // wei <-> gas exchange ratio
	GasTipCap *big.Int          // a.k.a. maxPriorityFeePerGas
	GasFeeCap *big.Int          // a.k.a. maxFeePerGas
	Value     *big.Int          // amount of wei sent along with the call
	Data      []byte            // input data, usually an ABI-encoded contract method invocation
}

type GasPriceLimits

type GasPriceLimits struct {
	GasPrice  *big.Int
	GasLimit  uint64
	GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas
	GasFeeCap *big.Int // a.k.a. maxFeePerGas
}

type Network

type Network struct {
	Name        string
	URL         string
	ExplorerURL string
	Unit        string
	ChainID     *big.Int
}

type NodeInfo

type NodeInfo struct {
	CurrentBlockHash      string      `json:"currentBlockHash"`
	CurrentBlockNumber    hexutil.Big `json:"currentBlockNumber"`
	CurrentBlockTimestamp int         `json:"currentBlockTimestamp"`
	Environment           struct {
		BaseFee  hexutil.Big `json:"baseFee"`
		ChainId  hexutil.Big `json:"chainId"`
		GasLimit hexutil.Big `json:"gasLimit"`
		GasPrice hexutil.Big `json:"gasPrice"`
	} `json:"environment"`
	ForkConfig struct {
		ForkBlockNumber  int    `json:"forkBlockNumber"`
		ForkRetryBackoff int    `json:"forkRetryBackoff"`
		ForkUrl          string `json:"forkUrl"`
	} `json:"forkConfig"`
	HardFork         string `json:"hardFork"`
	TransactionOrder string `json:"transactionOrder"`
}

type SendContractTxPayload

type SendContractTxPayload struct {
	SmartContractAddr string
	SendEtherPayload  // payable would be an amount, otherwise for tokens use the params field
	ContractFile      string
	ContractABI       *abi.ABI // this has first priority, if nil will check default contracts using contract file
	MethodName        string   // name of the smart contract function
	Params            []interface{}
	Data              []byte
}

func (*SendContractTxPayload) GenerateBinDataFromParamsAbi

func (s *SendContractTxPayload) GenerateBinDataFromParamsAbi(ctx context.Context) error

type SendEtherPayload

type SendEtherPayload struct {
	TransferArgs
	GasPriceLimits
}

func (*SendEtherPayload) EffectiveGasPrice

func (tx *SendEtherPayload) EffectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int

type TransferArgs

type TransferArgs struct {
	Amount    *big.Int
	ToAddress accounts.Address
}

type Web3Actions

type Web3Actions struct {
	C *ethclient.Client
	*accounts.Account
	IrisClient       iris_programmable_proxy.Iris
	Headers          map[string]string
	NodeURL          string
	RelayProxyUrl    string
	Network          string
	IsAnvilNode      bool
	DurableExecution bool
}

func NewWeb3ActionsClient

func NewWeb3ActionsClient(nodeUrl string) Web3Actions

func NewWeb3ActionsClientWithAccount

func NewWeb3ActionsClientWithAccount(nodeUrl string, account *accounts.Account) Web3Actions

func (*Web3Actions) AddAdaptiveLoadBalancerHeaders

func (w *Web3Actions) AddAdaptiveLoadBalancerHeaders()

func (*Web3Actions) AddAnvilEthMainnetHeaders

func (w *Web3Actions) AddAnvilEthMainnetHeaders(sessionID string)

func (*Web3Actions) AddAnvilSessionLockHeader

func (w *Web3Actions) AddAnvilSessionLockHeader(sessionID string)

func (*Web3Actions) AddBearerToken

func (w *Web3Actions) AddBearerToken(token string)

func (*Web3Actions) AddDefaultEthereumMainnetTableHeader

func (w *Web3Actions) AddDefaultEthereumMainnetTableHeader()

func (*Web3Actions) AddDurableExecutionIDHeader

func (w *Web3Actions) AddDurableExecutionIDHeader(reqID string)

func (*Web3Actions) AddEndSessionLockHeader

func (w *Web3Actions) AddEndSessionLockHeader(sessionID string)

func (*Web3Actions) AddEndSessionLockToHeaderIfExisting

func (w *Web3Actions) AddEndSessionLockToHeaderIfExisting()

func (*Web3Actions) AddMaxBlockHeightProcedureEthJsonRpcHeader

func (w *Web3Actions) AddMaxBlockHeightProcedureEthJsonRpcHeader()

func (*Web3Actions) AddRoutingGroupHeader

func (w *Web3Actions) AddRoutingGroupHeader(routingGroup string)

func (*Web3Actions) ApproveSpenderERC20Token

func (w *Web3Actions) ApproveSpenderERC20Token(ctx context.Context, payload SendContractTxPayload) (*types.Transaction, error)

func (*Web3Actions) CallConstantFunction

func (w *Web3Actions) CallConstantFunction(ctx context.Context, payload *SendContractTxPayload) ([]interface{}, error)

CallConstantFunction executes a contract function call without submitting a transaction.

func (*Web3Actions) CallContract

func (w *Web3Actions) CallContract(ctx context.Context,
	payload *SendContractTxPayload, waitForReceipt bool, data []byte, timeoutInSeconds uint64) error

func (*Web3Actions) CallFunctionWithArgs

func (w *Web3Actions) CallFunctionWithArgs(ctx context.Context, payload *SendContractTxPayload) (*types.Transaction, error)

CallFunctionWithArgs submits a transaction to execute a smart contract function call.

func (*Web3Actions) CallFunctionWithData

func (w *Web3Actions) CallFunctionWithData(ctx context.Context, payload *SendContractTxPayload, data []byte) (*types.Transaction, error)

CallFunctionWithData if you already have the encoded function data, then use this

func (*Web3Actions) CallTransactFunction

func (w *Web3Actions) CallTransactFunction(ctx context.Context, payload *SendContractTxPayload) (*types.Transaction, error)

func (*Web3Actions) Close

func (w *Web3Actions) Close()

func (*Web3Actions) DeployBin

func (w *Web3Actions) DeployBin(ctx context.Context, binFilename, abiFilename string,
	gasPrice *big.Int, gasLimit uint64, constructorArgs ...interface{}) (*types.Transaction, error)

DeployBin will deploy a bin file to the network

func (*Web3Actions) DeployContract

func (w *Web3Actions) DeployContract(ctx context.Context, binHex string, payload SendContractTxPayload) (*types.Transaction, error)

DeployContract submits a contract creation transaction. abiJSON is only required when including params for the constructor.

func (*Web3Actions) Dial

func (w *Web3Actions) Dial()

func (*Web3Actions) EndAnvilSession

func (w *Web3Actions) EndAnvilSession() error

func (*Web3Actions) EndHardHatSessionReset

func (w *Web3Actions) EndHardHatSessionReset(ctx context.Context, nodeURL string, blockNum int) error

func (*Web3Actions) GetBalance

func (w *Web3Actions) GetBalance(ctx context.Context, address string, blockNumber *big.Int) (*big.Int, error)

func (*Web3Actions) GetBaseFee

func (w *Web3Actions) GetBaseFee(ctx context.Context) (*big.Int, error)

func (*Web3Actions) GetCode

func (w *Web3Actions) GetCode(ctx context.Context, address string, blockNumber *big.Int) ([]byte, error)

func (*Web3Actions) GetContractConst

func (w *Web3Actions) GetContractConst(ctx context.Context, payload *SendContractTxPayload) ([]interface{}, error)

func (*Web3Actions) GetContractDecimals

func (w *Web3Actions) GetContractDecimals(ctx context.Context, contractAddress string) (int, error)

func (*Web3Actions) GetContractName

func (w *Web3Actions) GetContractName(ctx context.Context, contractAddress string) (string, error)

func (*Web3Actions) GetContractSymbol

func (w *Web3Actions) GetContractSymbol(ctx context.Context, contractAddress string) (string, error)

func (*Web3Actions) GetEVMSnapshot

func (w *Web3Actions) GetEVMSnapshot(ctx context.Context) (*big.Int, error)

func (*Web3Actions) GetNodeInfo

func (w *Web3Actions) GetNodeInfo(ctx context.Context) (NodeInfo, error)

func (*Web3Actions) GetNonce

func (w *Web3Actions) GetNonce(ctx context.Context) (uint64, error)

func (*Web3Actions) GetNonceByPublicAddress

func (w *Web3Actions) GetNonceByPublicAddress(ctx context.Context, fromAddress accounts.Address) (uint64, error)

func (*Web3Actions) GetNumber

func (w *Web3Actions) GetNumber(ctx context.Context, address string, blockNumber *big.Int) (*big.Int, error)

func (*Web3Actions) GetOwner

func (w *Web3Actions) GetOwner(ctx context.Context, abiFile *abi.ABI, contractAddress string) (common.Address, error)

func (*Web3Actions) GetSessionLockHeader

func (w *Web3Actions) GetSessionLockHeader() string

func (*Web3Actions) GetSignedDeployTxToCallFunctionWithArgs

func (w *Web3Actions) GetSignedDeployTxToCallFunctionWithArgs(ctx context.Context, binHex string, payload *SendContractTxPayload) (*types.Transaction, error)

GetSignedDeployTxToCallFunctionWithArgs prepares the tx for broadcast

func (*Web3Actions) GetSignedSendTx

func (w *Web3Actions) GetSignedSendTx(ctx context.Context, params SendEtherPayload) (*types.Transaction, error)

func (*Web3Actions) GetSignedTxToCallFunctionWithArgs

func (w *Web3Actions) GetSignedTxToCallFunctionWithArgs(ctx context.Context, payload *SendContractTxPayload) (*types.Transaction, error)

GetSignedTxToCallFunctionWithArgs prepares the tx for broadcast

func (*Web3Actions) GetSignedTxToCallFunctionWithData

func (w *Web3Actions) GetSignedTxToCallFunctionWithData(ctx context.Context, payload *SendContractTxPayload, data []byte) (*types.Transaction, error)

GetSignedTxToCallFunctionWithData prepares the tx for broadcast

func (*Web3Actions) GetSignedTxToDeploySmartContract

func (w *Web3Actions) GetSignedTxToDeploySmartContract(ctx context.Context, payload *SendContractTxPayload, data []byte) (*types.Transaction, error)

GetSignedTxToDeploySmartContract prepares the tx for deploy

func (*Web3Actions) GetStorageAt

func (w *Web3Actions) GetStorageAt(ctx context.Context, addr, slot string) (hexutil.Bytes, error)

func (*Web3Actions) GetTargetContract

func (w *Web3Actions) GetTargetContract(ctx context.Context, rpcURL, contractAddress string) (string, error)

func (*Web3Actions) GetTxPoolContent

func (w *Web3Actions) GetTxPoolContent(ctx context.Context) (map[string]map[string]map[string]*types.Transaction, error)

func (*Web3Actions) GetTxReceipt

func (w *Web3Actions) GetTxReceipt(ctx context.Context, txhash string) (*types.Receipt, error)

func (*Web3Actions) HardhatSetStorageAt

func (w *Web3Actions) HardhatSetStorageAt(ctx context.Context, addr, slot, value string) error

func (*Web3Actions) ImpersonateAccount

func (w *Web3Actions) ImpersonateAccount(ctx context.Context, address string) error

func (*Web3Actions) IncreaseGas

func (w *Web3Actions) IncreaseGas(ctx context.Context, txHash string, amountGwei string) error

func (*Web3Actions) MineBlock

func (w *Web3Actions) MineBlock(ctx context.Context, blocksToMine hexutil.Big) error

func (*Web3Actions) ReadERC20Allowance

func (w *Web3Actions) ReadERC20Allowance(ctx context.Context, contractAddress, owner, spender string) (*big.Int, error)

func (*Web3Actions) ReadERC20TokenBalance

func (w *Web3Actions) ReadERC20TokenBalance(ctx context.Context, contractAddress, addrHash string) (*big.Int, error)

func (*Web3Actions) ReadERC20TokenDecimals

func (w *Web3Actions) ReadERC20TokenDecimals(ctx context.Context, payload SendContractTxPayload) (int32, error)

func (*Web3Actions) ReadERC20TokenName

func (w *Web3Actions) ReadERC20TokenName(ctx context.Context, contractAddress string) (string, error)

func (*Web3Actions) ReplaceTx

func (w *Web3Actions) ReplaceTx(ctx context.Context, chainID *big.Int, nonce uint64, to common.Address, amount *big.Int,
	gasPrice *big.Int, gasLimit uint64, data []byte) (*types.Transaction, error)

func (*Web3Actions) ResetNetwork

func (w *Web3Actions) ResetNetwork(ctx context.Context, rpcUrl string, blockNumber int) error

func (*Web3Actions) Send

Send performs a regular native coin transaction (not a contract)

func (*Web3Actions) SendRawTransaction

func (w *Web3Actions) SendRawTransaction(ctx context.Context, tx *types.Transaction) error

func (*Web3Actions) SendSignedTransaction

func (w *Web3Actions) SendSignedTransaction(ctx context.Context, signedTx *types.Transaction) error

SendSignedTransaction sends the Transaction

func (*Web3Actions) SetBalance

func (w *Web3Actions) SetBalance(ctx context.Context, address string, balance hexutil.Big) error

func (*Web3Actions) SetBalanceAtSlotNumber

func (w *Web3Actions) SetBalanceAtSlotNumber(ctx context.Context, scAddr, userAddr string, slotNum int, value *big.Int) error

func (*Web3Actions) SetCode

func (w *Web3Actions) SetCode(ctx context.Context, address string, bytes string) error

func (*Web3Actions) SetNonce

func (w *Web3Actions) SetNonce(ctx context.Context, address string, nonce hexutil.Big) error

func (*Web3Actions) SetRpcUrl

func (w *Web3Actions) SetRpcUrl(ctx context.Context, rpcUrl string) (any, error)

func (*Web3Actions) SetStorageAt

func (w *Web3Actions) SetStorageAt(ctx context.Context, addr, slot, value string) error

func (*Web3Actions) StopImpersonatingAccount

func (w *Web3Actions) StopImpersonatingAccount(ctx context.Context, address string) error

func (*Web3Actions) SubmitSignedTxAndReturnTxData

func (w *Web3Actions) SubmitSignedTxAndReturnTxData(ctx context.Context, signedTx *types.Transaction) (*types.Transaction, error)

func (*Web3Actions) SuggestAndSetGasPriceAndLimitForTx

func (w *Web3Actions) SuggestAndSetGasPriceAndLimitForTx(ctx context.Context, params *SendContractTxPayload, toAddr common.Address) error

func (*Web3Actions) SuggestAndSetGasPriceForContractDeploy

func (w *Web3Actions) SuggestAndSetGasPriceForContractDeploy(ctx context.Context, params *SendContractTxPayload) error

func (*Web3Actions) TransferERC20Token

func (w *Web3Actions) TransferERC20Token(ctx context.Context, payload SendContractTxPayload) (*types.Transaction, error)

func (*Web3Actions) UpgradeContract

func (w *Web3Actions) UpgradeContract(ctx context.Context, contractAddress, newTargetAddress string, amount *big.Int, timeoutInSeconds uint64) error

func (*Web3Actions) WaitForReceipt

func (w *Web3Actions) WaitForReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error)

WaitForReceipt polls for a transaction receipt until it is available, or ctx is cancelled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL