web3_types

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: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ABIBuiltIn

func ABIBuiltIn(abiFile string) (*abi.ABI, error)

func ABIOpenFile

func ABIOpenFile(abiFile string) (*abi.ABI, error)

func ABIOpenURL

func ABIOpenURL(abiFile string) (*abi.ABI, error)

func Base

func Base(b int64) *big.Int

Base converts b base units to wei (*1e18).

func CompileSolidityString

func CompileSolidityString(ctx context.Context, source, solcVersion, evmVersion string, optimize bool) (map[string]*Contract, error)

CompileSolidityString builds and returns all the contracts contained within a source string.

func ConvertArgument

func ConvertArgument(abiType abi.Type, param interface{}) (interface{}, error)

ConvertArgument attempts to convert argument to the provided ABI type and size. Unrecognized types are passed through unmodified.

func ConvertArguments

func ConvertArguments(args abi.Arguments, params []interface{}) ([]interface{}, error)

ConvertArguments attempts to convert each param to the matching args type. Unrecognized param types are passed through unmodified.

Note: The encoding/json package uses float64 for numbers by default, which is inaccurate for many web3 types, and unsupported here. The json.Decoder method UseNumber() will switch to using json.Number instead, which is accurate (full precision, backed by the original string) and supported here.

func ConvertInt

func ConvertInt(signed bool, size int, i *big.Int) (interface{}, error)

ConvertInt converts a big.Int in to the provided type.

func ConvertToAddress

func ConvertToAddress(i interface{}) (common.Address, error)

func DecToInt

func DecToInt(d decimal.Decimal, decimals int32) *big.Int

DecToInt converts a decimal to a big int

func FloatAsInt

func FloatAsInt(amountF *big.Float, decimals int) *big.Int

FloatAsInt converts a float to a *big.Int based on the decimals passed in

func GetABI

func GetABI(abiFile string) (*abi.ABI, error)

GetABI accepts either built in contracts (erc20, erc721), a file location or a URL

func Gwei

func Gwei(g int64) *big.Int

Gwei converts g gwei to wei (*1e9).

func IntAsFloat

func IntAsFloat(i *big.Int, decimals int) *big.Float

IntAsFloat converts a *big.Int (ie: wei), to *big.Float (ie: ETH)

func IntToDec

func IntToDec(i *big.Int, decimals int32) decimal.Decimal

IntToDec converts a big int to a decimal

func ParseAmount

func ParseAmount(amount string) (*big.Int, error)

ParseAmount parses a string (human readable amount with units ie 1go, 1nanogo...) and returns big.Int value of this string in wei/atto

func ParseBase

func ParseBase(b string) (*big.Int, error)

func ParseBigInt

func ParseBigInt(value string) (*big.Int, error)

ParseBigInt parses a string (base 10 only) and returns big.Int value of this string in wei/atto

func ParseCombinedJSON

func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion string, compilerVersion string, compilerOptions string) (map[string]*Contract, error)

func ParseGwei

func ParseGwei(g string) (*big.Int, error)

func WeiAsBase

func WeiAsBase(w *big.Int) string

WeiAsBase converts w wei in to the base unit, and formats it as a decimal fraction with full precision (up to 18 decimals).

func WeiAsGwei

func WeiAsGwei(w *big.Int) string

WeiAsGwei converts w wei in to gwei, and formats it as a decimal fraction with full precision (up to 9 decimals).

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
	GasFeeCap *big.Int
	Value     *big.Int // amount of wei sent along with the call
	Data      []byte   // input data, usually an ABI-encoded contract method invocation
}

type Contract

type Contract struct {
	Code        string            `json:"code"`
	RuntimeCode string            `json:"runtime-code"`
	Info        ContractInfo      `json:"info"`
	Hashes      map[string]string `json:"hashes"`
}

Contract contains information about a compiled contract, alongside its code and runtime code.

type ContractInfo

type ContractInfo struct {
	Source          string      `json:"source"`
	Language        string      `json:"language"`
	LanguageVersion string      `json:"languageVersion"`
	CompilerVersion string      `json:"compilerVersion"`
	CompilerOptions string      `json:"compilerOptions"`
	SrcMap          interface{} `json:"srcMap"`
	SrcMapRuntime   string      `json:"srcMapRuntime"`
	AbiDefinition   interface{} `json:"abiDefinition"`
	UserDoc         interface{} `json:"userDoc"`
	DeveloperDoc    interface{} `json:"developerDoc"`
	Metadata        string      `json:"metadata"`
}

ContractInfo contains information about a compiled contract, including access to the ABI definition, source mapping, user and developer docs, and metadata.

Depending on the source, language version, compiler version, and compiler options will provide information about how the contract was compiled.

type ID

type ID struct {
	NetworkID   *big.Int      `json:"network_id"`
	ChainID     *big.Int      `json:"chain_id"`
	GenesisHash accounts.Hash `json:"genesis_hash"`
}

type Snapshot

type Snapshot struct {
	Number  uint64                        `json:"number"`
	Hash    accounts.Hash                 `json:"hash"`
	Signers map[accounts.Address]uint64   `json:"signers"`
	Voters  map[accounts.Address]struct{} `json:"voters"`
	Votes   []*Vote                       `json:"votes"`
	Tally   map[accounts.Address]Tally    `json:"tally"`
}

type Solidity

type Solidity struct {
	Path, Version, EVMVersion string
	Major, Minor, Patch       int
	Optimize                  bool
}

Solidity specifies the solidity compiler configuration.

func SolidityVersion

func SolidityVersion(source string) (*Solidity, error)

SolidityVersion runs solc and parses its version output.

type Tally

type Tally struct {
	Authorize bool `json:"authorize"`
	Votes     int  `json:"votes"`
}

type Vote

type Vote struct {
	Signer    accounts.Address `json:"signer"`
	Block     uint64           `json:"block"`
	Address   accounts.Address `json:"address"`
	Authorize bool             `json:"authorize"`
}

Jump to

Keyboard shortcuts

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