common

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrNotRunInEvm is raised when a function is not called inside the EVM.
	ErrNotRunInEvm = "not run in EVM"
	// ErrDifferentOrigin is raised when an approval is set but the origin address is not the same as the spender.
	ErrDifferentOrigin = "tx origin address %s does not match the delegator address %s"
	// ErrInvalidABI is raised when the ABI cannot be parsed.
	ErrInvalidABI = "invalid ABI: %w"
	// ErrInvalidAmount is raised when the amount cannot be cast to a big.Int.
	ErrInvalidAmount = "invalid amount: %v"
	// ErrInvalidDelegator is raised when the delegator address is not valid.
	ErrInvalidDelegator = "invalid delegator address: %s"
	// ErrInvalidDenom is raised when the denom is not valid.
	ErrInvalidDenom = "invalid denom: %s"
	// ErrInvalidMsgType is raised when the transaction type is not valid for the given precompile.
	ErrInvalidMsgType = "invalid %s transaction type: %s"
	// ErrInvalidNumberOfArgs is raised when the number of arguments is not what is expected.
	ErrInvalidNumberOfArgs = "invalid number of arguments; expected %d; got: %d"
	// ErrUnknownMethod is raised when the method is not known.
	ErrUnknownMethod = "unknown method: %s"
	// ErrIntegerOverflow is raised when an integer overflow occurs.
	ErrIntegerOverflow = "integer overflow when increasing allowance"
	// ErrNegativeAmount is raised when an amount is negative.
	ErrNegativeAmount = "negative amount when decreasing allowance"
	// ErrInvalidType is raised when the provided type is different than the expected.
	ErrInvalidType = "invalid type for %s: expected %T, received %T"
	// ErrInvalidDescription is raised when the input description cannot be cast to stakingtypes.Description{}.
	ErrInvalidDescription = "invalid description: %v"
	// ErrInvalidCommission is raised when the input commission cannot be cast to stakingtypes.CommissionRates{}.
	ErrInvalidCommission = "invalid commission: %v"
)

Variables

View Source
var (
	// TrueValue is the byte array representing a true value in solidity.
	TrueValue = []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1}
	// DefaultExpirationDuration is the default duration for an authorization to expire.
	DefaultExpirationDuration = time.Hour * 24 * 365
	// DefaultChainID is the standard chain id used for testing purposes
	DefaultChainID = utils.MainNetChainID + "-1"
	// DefaultPrecompilesBech32 is the standard bech32 address for the precompiles
	DefaultPrecompilesBech32 = []string{
		"haqq1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqj6krnj",
		"haqq1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqpqqnxumqn",
		"haqq1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqq4q8tzj",
		"haqq1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqpgkn7lq",
		"haqq1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqzx9xg3l",

		"haqq1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqy629ddg",
	}
)

Functions

func HandleGasError

func HandleGasError(ctx sdk.Context, contract *vm.Contract, initialGas sdk.Gas, err *error) func()

HandleGasError handles the out of gas panic by resetting the gas meter and returning an error. This is used in order to avoid panics and to allow for the EVM to continue cleanup if the tx or query run out of gas.

func HexAddressFromBech32String

func HexAddressFromBech32String(addr string) (res common.Address, err error)

HexAddressFromBech32String converts a hex address to a bech32 encoded address.

func LoadABI

func LoadABI(fs embed.FS, path string) (abi.ABI, error)

LoadABI read the ABI file described by the path and parse it as JSON.

func MakeTopic

func MakeTopic(rule interface{}) (common.Hash, error)

MakeTopic converts a filter query argument into a filter topic. NOTE: This was copied from accounts/abi/topics.go

func PackNum

func PackNum(value reflect.Value) []byte

PackNum packs the given number (using the reflect value) and will cast it to appropriate number representation.

func SafeAdd

func SafeAdd(a, b math.Int) (res *big.Int, overflow bool)

SafeAdd adds two integers and returns a boolean if an overflow occurs to avoid panic. TODO: Upstream this to the SDK math package.

func UnpackLog

func UnpackLog(contractABI abi.ABI, out interface{}, event string, log ethtypes.Log) error

UnpackLog unpacks a retrieved log into the provided output structure.

Types

type Coin

type Coin struct {
	Denom  string
	Amount *big.Int
}

Coin defines a struct that stores all needed information about a coin in types native to the EVM.

func NewCoinsResponse

func NewCoinsResponse(amount sdk.Coins) []Coin

NewCoinsResponse converts a response to an array of Coin.

func (Coin) ToSDKType

func (c Coin) ToSDKType() sdk.Coin

ToSDKType converts the Coin to the Cosmos SDK representation.

type Dec

type Dec struct {
	Value     *big.Int
	Precision uint8
}

Dec defines a struct that represents a decimal number of a given precision in types native to the EVM.

type DecCoin

type DecCoin struct {
	Denom     string
	Amount    *big.Int
	Precision uint8
}

DecCoin defines a struct that stores all needed information about a decimal coin in types native to the EVM.

func NewDecCoinsResponse

func NewDecCoinsResponse(amount sdk.DecCoins) []DecCoin

NewDecCoinsResponse converts a response to an array of DecCoin.

type EmitEventArgs

type EmitEventArgs struct {
	Ctx            sdk.Context
	StateDB        vm.StateDB
	ContractAddr   common.Address
	ContractEvents map[string]abi.Event
	EventData      interface{}
}

EmitEventArgs are the arguments required to emit an authorization event.

The event type can be:

  • ApprovalEvent
  • GenericApprovalEvent
  • AllowanceChangeEvent
  • ...

type ICS20Allocation

type ICS20Allocation struct {
	SourcePort    string
	SourceChannel string
	SpendLimit    []Coin
	AllowList     []string
}

ICS20Allocation defines the spend limit for a particular port and channel. We need this to be able to unpack to big.Int instead of math.Int.

type Precompile

type Precompile struct {
	abi.ABI
	AuthzKeeper          authzkeeper.Keeper
	ApprovalExpiration   time.Duration
	KvGasConfig          storetypes.GasConfig
	TransientKVGasConfig storetypes.GasConfig
}

Precompile is a common struct for all precompiles that holds the common data each precompile needs to run which includes the ABI, Gas config, approval expiration and the authz keeper.

func (Precompile) RequiredGas

func (p Precompile) RequiredGas(input []byte, isTransaction bool) uint64

RequiredGas calculates the base minimum required gas for a transaction or a query. It uses the method ID to determine if the input is a transaction or a query and uses the Cosmos SDK gas config flat cost and the flat per byte cost * len(argBz) to calculate the gas.

func (Precompile) RunSetup

func (p Precompile) RunSetup(
	evm *vm.EVM,
	contract *vm.Contract,
	readOnly bool,
	isTransaction func(name string) bool,
) (ctx sdk.Context, stateDB *statedb.StateDB, method *abi.Method, gasConfig sdk.Gas, args []interface{}, err error)

RunSetup runs the initial setup required to run a transaction or a query. It returns the sdk Context, EVM stateDB, ABI method, initial gas and calling arguments.

Jump to

Keyboard shortcuts

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