util

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NEXT                     int    = -1
	BACK                     int    = -2
	CUSTOM                   int    = -3
	CONSTRUCTOR_METHOD_INDEX uint64 = 1000000 // assuming there is no contract with more than 1m methods
)

Variables

View Source
var GAS_INFO_TTL = 60 * time.Second

Functions

func AllZeroParamFunctions added in v0.0.30

func AllZeroParamFunctions(a *abi.ABI) []abi.Method

func AnalyzeAndShowMsigTxInfo

func AnalyzeAndShowMsigTxInfo(
	multisigContract *msig.MultisigContract,
	txid *big.Int,
	network Network,
) (fc *FunctionCall, confirmed bool, executed bool)

func CommonFunctionCallPreprocess

func CommonFunctionCallPreprocess(cmd *cobra.Command, args []string) (err error)

CommonFunctionCallPreprocess processes args passed to the command in order to initiate config's variables in a conventional way across many Function Call alike commands.

func CommonTxPreprocess

func CommonTxPreprocess(cmd *cobra.Command, args []string) (err error)

CommonTxPreprocess processes args passed to the command in order to initiate config's variables in a conventional way across many commands that do txs.

func HandleApproveOrRevokeOrExecuteMsig

func HandleApproveOrRevokeOrExecuteMsig(
	method string,
	cmd *cobra.Command,
	args []string,
	postProcess PostProcessFunc,
)

func HandlePostSign added in v0.0.30

func HandlePostSign(
	signedTx *types.Transaction,
	reader *reader.EthReader,
	analyzer *txanalyzer.TxAnalyzer,
	a *abi.ABI,
) (broadcasted bool, err error)

func PromptArray added in v0.0.30

func PromptArray(input abi.Argument, prefill string, network Network) (interface{}, error)

func PromptFilePath added in v0.0.30

func PromptFilePath(prompter string) string

func PromptFunctionCallData added in v0.0.30

func PromptFunctionCallData(
	analyzer util.TxAnalyzer,
	contractAddress string,
	methodIndex uint64,
	prefills []string,
	prefillMode bool,
	mode string,
	a *abi.ABI,
	customABIs map[string]*abi.ABI,
	network Network,
) (method *abi.Method, params []interface{}, err error)

func PromptIndex added in v0.0.30

func PromptIndex(prompter string, min, max int) int

func PromptInput added in v0.0.30

func PromptInput(prompter string) string

func PromptInputWithValidation added in v0.0.30

func PromptInputWithValidation(prompter string, validator StringValidator) string

func PromptItemInList added in v0.0.30

func PromptItemInList(prompter string, options []string) string

func PromptMethod added in v0.0.30

func PromptMethod(a *abi.ABI, methodIndex uint64, mode string) (*abi.Method, string, error)

func PromptNonArray added in v0.0.30

func PromptNonArray(input abi.Argument, prefill string, network Network) (interface{}, error)

func PromptNumber added in v0.0.30

func PromptNumber(prompter string, validator NumberValidator, network Network) *big.Int

func PromptParam added in v0.0.30

func PromptParam(
	interactiveMode bool,
	input abi.Argument,
	prefill string,
	network Network,
) (interface{}, error)

func PromptPercentageBps added in v0.0.30

func PromptPercentageBps(prompter string, upbound int64, network Network) *big.Int

func PromptTxConfirmation added in v0.0.30

func PromptTxConfirmation(
	analyzer util.TxAnalyzer,
	from Address,
	tx *types.Transaction,
	customABIs map[string]*abi.ABI,
	network Network,
) error

func PromptTxData added in v0.0.30

func PromptTxData(
	analyzer util.TxAnalyzer,
	contractAddress string,
	methodIndex uint64,
	prefills []string,
	prefillMode bool,
	a *abi.ABI,
	customABIs map[string]*abi.ABI,
	network Network,
) ([]byte, error)

func ScanForTxs added in v0.0.30

func ScanForTxs(para string) (nwks []string, addresses []string)

func ValidTxType added in v0.0.30

func ValidTxType(r *reader.EthReader, network Network) (uint8, error)

Types

type ContextManager added in v0.0.30

type ContextManager struct {
	// contains filtered or unexported fields
}

ContextManager manages

  1. multiple wallets and their informations in its life time. It basically gives next nonce to do transaction for specific wallet and specific network. It queries the node to check the nonce in lazy maner, it also takes mining txs into account.
  2. multiple networks gas price. The gas price will be queried lazily prior to txs and will be stored as cache for a while
  3. txs in the context manager's life time

func NewContextManager added in v0.0.30

func NewContextManager() *ContextManager

func (*ContextManager) Account added in v0.0.30

func (cm *ContextManager) Account(wallet common.Address) *account.Account

func (*ContextManager) Analyzer added in v0.0.30

func (cm *ContextManager) Analyzer(network Network) *TxAnalyzer

func (*ContextManager) BroadcastRawTx added in v0.0.30

func (cm *ContextManager) BroadcastRawTx(
	data string,
) (hash string, successful bool, allErrors error)

func (*ContextManager) BroadcastTx added in v0.0.30

func (cm *ContextManager) BroadcastTx(
	tx *types.Transaction,
) (hash string, broadcasted bool, allErrors error)

func (*ContextManager) Broadcaster added in v0.0.30

func (cm *ContextManager) Broadcaster(network Network) *Broadcaster

func (*ContextManager) BuildTx added in v0.0.30

func (cm *ContextManager) BuildTx(
	txType uint8,
	from, to common.Address,
	nonce *big.Int,
	value *big.Int,
	gasLimit uint64,
	gasPrice float64,
	tipCapGwei float64,
	data []byte,
	network Network,
) (tx *types.Transaction, err error)

func (*ContextManager) GasSetting added in v0.0.30

func (cm *ContextManager) GasSetting(network Network) (*GasInfo, error)

implement a cache mechanism to be more efficient

func (*ContextManager) Nonce added in v0.0.30

func (cm *ContextManager) Nonce(wallet common.Address, network Network) (*big.Int, error)
  1. get remote pending nonce
  2. get local pending nonce
  3. get mined nonce
  4. if mined nonce == remote == local, all good, lets return the mined nonce
  5. since mined nonce is always <= remote nonce, if mined nonce > local nonce, this session doesn't catch up with mined txs (in case there are txs that were from other apps and they were mined), return max(mined none, remote nonce) and set local nonce to max(mined none, remote nonce)
  6. if not, means mined nonce is smaller than both remote and local pending nonce 5.1 if remote == local: means all pending txs are from this session, we return local nonce 5.2 if remote > local: means there is pending txs from another app, we return remote nonce in order not to mess up with the other txs, but give a warning 5.3 if local > remote: means txs from this session are not broadcasted to the the notes, return local nonce and give warnings

func (*ContextManager) PendingNonce added in v0.0.30

func (cm *ContextManager) PendingNonce(wallet common.Address, network Network) *big.Int

func (*ContextManager) Reader added in v0.0.30

func (cm *ContextManager) Reader(network Network) *EthReader

func (*ContextManager) SignTx added in v0.0.30

func (cm *ContextManager) SignTx(
	wallet common.Address,
	tx *types.Transaction,
	network Network,
) (signedTx *types.Transaction, err error)

func (*ContextManager) SignTxAndBroadcast added in v0.0.30

func (cm *ContextManager) SignTxAndBroadcast(
	wallet common.Address,
	tx *types.Transaction,
	network Network,
) (signedTx *types.Transaction, successful bool, allErrors error)

func (*ContextManager) UnlockAccount added in v0.0.30

func (cm *ContextManager) UnlockAccount(addr common.Address) (*account.Account, error)

type GasInfo added in v0.0.30

type GasInfo struct {
	GasPrice         float64
	BaseGasPrice     *big.Int
	MaxPriorityPrice float64
	FeePerGas        float64
	Timestamp        time.Time
}

type NumberValidator added in v0.0.30

type NumberValidator func(number *big.Int) error

type PostProcessFunc

type PostProcessFunc func(fc *FunctionCall) error

type StringValidator added in v0.0.30

type StringValidator func(st string) error

Jump to

Keyboard shortcuts

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