common

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: MIT Imports: 24 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Start time.Time

Functions

func AlertColor

func AlertColor(str string) string

func BigToFloat added in v0.0.25

func BigToFloat(b *big.Int, decimal uint64) float64

BigToFloat converts a big int to float according to its number of decimal digits Example: - BigToFloat(1100, 3) = 1.1 - BigToFloat(1100, 2) = 11 - BigToFloat(1100, 5) = 0.11

func BigToFloatString added in v0.0.25

func BigToFloatString(value *big.Int, decimal uint64) string

func BuildContractCreationTx added in v0.0.25

func BuildContractCreationTx(
	txType uint8,
	nonce uint64,
	ethAmount *big.Int,
	gasLimit uint64,
	priceGwei float64,
	tipCapGwei float64,
	data []byte,
	chainID uint64,
) (tx *types.Transaction)

func BuildExactSendETHTx added in v0.0.25

func BuildExactSendETHTx(
	txType uint8,
	nonce uint64,
	to string,
	ethAmount *big.Int,
	gasLimit uint64,
	priceGwei float64,
	tipCapGwei float64,
	chainID uint64,
) (tx *types.Transaction)

func BuildExactTx added in v0.0.25

func BuildExactTx(
	txType uint8,
	nonce uint64,
	to string,
	ethAmount *big.Int,
	gasLimit uint64,
	priceGwei float64,
	tipCapGwei float64,
	data []byte,
	chainID uint64,
) (tx *types.Transaction)

func BuildTx added in v0.0.25

func BuildTx(
	txType uint8,
	nonce uint64,
	to string,
	ethAmount float64,
	gasLimit uint64,
	priceGwei float64,
	tipCapGwei float64,
	data []byte,
	chainID uint64,
) (tx *types.Transaction)

func DebugObjPrint added in v0.0.30

func DebugObjPrint(obj interface{})

func DebugPrintf added in v0.0.30

func DebugPrintf(format string, a ...any) (n int, err error)

func EthToWei added in v0.0.25

func EthToWei(n float64) *big.Int

EthToWei converts Gwei as a float to Wei as a big int

func FloatStringToBig added in v0.0.25

func FloatStringToBig(value string, decimal uint64) (*big.Int, error)

func FloatToBigInt added in v0.0.25

func FloatToBigInt(amount float64, decimal uint64) *big.Int

FloatToBigInt converts a float to a big int with specific decimal Example: - FloatToBigInt(1, 4) = 10000 - FloatToBigInt(1.234, 4) = 12340

func FloatToInt added in v0.0.25

func FloatToInt(amount float64) int64

func GetEIP1967BeaconABI added in v0.0.30

func GetEIP1967BeaconABI() *abi.ABI

func GetERC20ABI added in v0.0.25

func GetERC20ABI() *abi.ABI

func GetMultiCallABI added in v0.0.25

func GetMultiCallABI() *abi.ABI

func GetSignerAddressFromTx added in v0.0.30

func GetSignerAddressFromTx(tx *types.Transaction, chainID *big.Int) (common.Address, error)

func GweiToWei added in v0.0.25

func GweiToWei(n float64) *big.Int

GweiToWei converts Gwei as a float to Wei as a big int

func HexToAddress added in v0.0.25

func HexToAddress(hex string) common.Address

func HexToAddresses added in v0.0.25

func HexToAddresses(hexes []string) []common.Address

func HexToBig added in v0.0.25

func HexToBig(hex string) *big.Int

func HexToHash added in v0.0.25

func HexToHash(hex string) common.Hash

func InfoColor

func InfoColor(str string) string

func NameWithColor

func NameWithColor(name string) string

func PackERC20Data added in v0.0.25

func PackERC20Data(function string, params ...interface{}) ([]byte, error)

func PrintElapseTime added in v0.0.30

func PrintElapseTime(start time.Time, str string)

func PrintFunctionCall added in v0.0.20

func PrintFunctionCall(fc *FunctionCall)

func PrintTupleFieldNamesToWriter added in v0.0.33

func PrintTupleFieldNamesToWriter(writer io.Writer, tuple TupleParamResult, indentLevel int)

func PrintTxDetails

func PrintTxDetails(result *TxResult, network Network, writer io.Writer)

func PrintTxSuccessSummary added in v0.0.27

func PrintTxSuccessSummary(result *TxResult, network Network, writer io.Writer)

func PrintVerboseArraysToWriter added in v0.0.33

func PrintVerboseArraysToWriter(writer io.Writer, arrays []ParamResult, indentLevel int)

func PrintVerboseParamResultToWriter added in v0.0.33

func PrintVerboseParamResultToWriter(writer io.Writer, param ParamResult, indentLevel int, includeFieldNames bool)

func PrintVerboseTopicToWriter added in v0.0.33

func PrintVerboseTopicToWriter(writer io.Writer, topic TopicResult)

func PrintVerboseTupleToWriter added in v0.0.33

func PrintVerboseTupleToWriter(writer io.Writer, tuple TupleParamResult, indentLevel int, includeFieldNames bool)

func PrintVerboseTuplesToWriter added in v0.0.33

func PrintVerboseTuplesToWriter(writer io.Writer, tuples []TupleParamResult, indentLevel int)

func PrintVerboseValueToWriter added in v0.0.20

func PrintVerboseValueToWriter(writer io.Writer, values []Value)

func RawTxToHash added in v0.0.25

func RawTxToHash(data string) string

RawTxToHash returns valid hex data of a transaction to transaction hash

func ReadableNumber

func ReadableNumber(value string) string

func RunParallel added in v0.0.33

func RunParallel(funcs ...func() error) (error, int)

RunParallel takes multiple functions that each return an error, runs them in parallel using goroutines, then aggregates any errors using errors.Join (Go 1.20+).

func StringToBig added in v0.0.25

func StringToBig(input string) *big.Int

func StringToBigInt added in v0.0.25

func StringToBigInt(str string) (*big.Int, error)

func StringToFloat added in v0.0.25

func StringToFloat(input string, decimal uint64) float64

func VerboseAddress

func VerboseAddress(addr Address) string

func VerboseValues

func VerboseValues(values []Value) []string

Types

type ABIDatabase added in v0.0.20

type ABIDatabase func(address string, network jarvisnetworks.Network) (*abi.ABI, error)

type Address

type Address struct {
	Address string
	Desc    string
	Decimal int64
}

type FunctionCall added in v0.0.20

type FunctionCall struct {
	Destination          Address
	Value                *big.Int
	Method               string
	Params               []ParamResult
	DecodedFunctionCalls []*FunctionCall
	Error                string
}

type InternalTx added in v0.0.25

type InternalTx struct {
	From  string `json:"from"`
	To    string `json:"to"`
	Value string `json:"value"`
}

type LogResult

type LogResult struct {
	Name   string
	Topics []TopicResult
	Data   []ParamResult
}

type ParamResult

type ParamResult struct {
	Name   string
	Type   string
	Values []Value            // Values stores the values of the parameters, in case the param is an array of arbitrary types, it will have more than one value
	Tuples []TupleParamResult // []ParamResult represents a tuple, this has more than one tuple if the param is a slice or an array of tuples
	Arrays []ParamResult      // Arrays stores the values of the parameters, in case the param is a slice or an array of another slice/array, it will have more than one value
}

ParamResult is the general struct that aims to be able to store all of the information of a parameter

  1. Para meter is an arbitrary type such as string, int, uint, bool, address, hash, bytes, fixed bytes ParamResult{ Name: "param1", // in case it is an element of an array, name = array_name[index] Type: "string", // or "int", "uint", "bool", "address", "hash", "bytes", "fixed bytes" Values: [1]Value{}, // where this has only one value }
  2. Parameter is a slice or an array of arbitrary types ParamResult{ Name: "param1", Type: "string[]", // or "int[]", "uint[]", "bool[]", "address[]", "hash[]", "bytes[]", "fixed bytes[]" Values: [n]Value{}, // where this has multiple values }
  3. Parameter is a tuple ParamResult{ Name: "param1", Type: "tuple", Tuples: [1][]ParamResult{}, // where this has }
  4. Parameter is a slice or an array of tuples ParamResult{ Name: "param1", Type: "tuple[]", // or "tuple[2]", "tuple[2][3]" Tuples: [n][]ParamResult{}, // where this has multiple tuples, []ParamResult represents a tuple }
  5. Parameter is a slice or an array of another slice/array ParamResult{ Name: "param1", Type: "string[][]", // or "int[][]", "uint[][]", "bool[][]", "address[][]", "hash[][]", "bytes[][]", "fixed bytes[][]" Arrays: [n]ParamResult{}, // where this has multiple arrays, []ParamResult represents an array }

type TopicResult

type TopicResult struct {
	Name  string
	Value []Value
}

type Transaction added in v0.0.25

type Transaction struct {
	*types.Transaction
	Extra TxExtraInfo `json:"extra"`
}

func (*Transaction) MarshalJSON added in v0.0.25

func (tx *Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) UnmarshalJSON added in v0.0.25

func (tx *Transaction) UnmarshalJSON(msg []byte) error

type TupleParamResult added in v0.0.33

type TupleParamResult struct {
	Name   string
	Type   string
	Values []ParamResult
}

type TxExtraInfo added in v0.0.25

type TxExtraInfo struct {
	BlockNumber *string         `json:"blockNumber,omitempty"`
	BlockHash   *common.Hash    `json:"blockHash,omitempty"`
	From        *common.Address `json:"from,omitempty"`
}

type TxInfo added in v0.0.25

type TxInfo struct {
	Status      string
	Tx          *Transaction
	InternalTxs []InternalTx
	Receipt     *types.Receipt
}

func (*TxInfo) GasCost added in v0.0.25

func (self *TxInfo) GasCost() *big.Int

type TxResult

type TxResult struct {
	Hash      string
	Network   string
	Status    string
	From      Address
	Value     string
	To        Address
	Nonce     string
	GasPrice  string
	GasLimit  string
	GasUsed   string
	GasCost   string
	Timestamp string
	TxType    string

	FunctionCall *FunctionCall
	Logs         []LogResult

	Completed bool
	Error     string
}

func NewTxResult

func NewTxResult() *TxResult

type TxResults

type TxResults map[string]*TxResult

func (*TxResults) Write

func (tr *TxResults) Write(filepath string)

type Value

type Value struct {
	Value   string
	Type    string
	Address *Address
}

Jump to

Keyboard shortcuts

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