common

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: LGPL-3.0 Imports: 11 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"
)
View Source
const UnknownMethodCallGas uint64 = 3000

Variables

This section is empty.

Functions

func GetCosmosAddressFromEVMAddressArg

func GetCosmosAddressFromEVMAddressArg(arg interface{}) (sdk.AccAddress, error)

func HandleGasError

func HandleGasError(ctx sdk.Context, contract *vm.Contract, initialGas storetypes.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 MustGetABI

func MustGetABI(f embed.FS, filename string) abi.ABI

func NewBalanceChangeEntry

func NewBalanceChangeEntry(acc ethcommon.Address, amt *big.Int, op Operation) balanceChangeEntry

func ValidateArgsLength

func ValidateArgsLength(args []interface{}, length int) error

func ValidateNonPayable

func ValidateNonPayable(value *big.Int) error

Types

type Contexter

type Contexter interface {
	Ctx() sdk.Context
}

type Operation

type Operation int8

Operation is a type that defines if the precompile call produced an addition or subtraction of an account's balance

const (
	Sub Operation = iota
	Add
)

type Precompile

type Precompile struct {
	abi.ABI
	// contains filtered or unexported fields
}

func NewPrecompile

func NewPrecompile(
	abi abi.ABI,
	address ethcommon.Address,
	executor PrecompileExecutor,
) *Precompile

func (Precompile) AddJournalEntries

func (p Precompile) AddJournalEntries(stateDB *statedb.StateDB, s snapshot) error

AddJournalEntries adds the balanceChange (if corresponds) and precompileCall entries on the stateDB journal This allows to revert the call changes within an evm tx

func (Precompile) Address

func (p Precompile) Address() ethcommon.Address

func (Precompile) GetABI

func (p Precompile) GetABI() abi.ABI

func (Precompile) GetMethodIDByName

func (p Precompile) GetMethodIDByName(name string) (methodId []byte, err error)

func (Precompile) Prepare

func (p Precompile) Prepare(
	evm *vm.EVM,
	contract *vm.Contract,
) (ctx sdk.Context,
	stateDB *statedb.StateDB,
	s snapshot,
	method *abi.Method,
	initialGas storetypes.Gas,
	args []interface{},
	err error,
)

Prepare 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.

func (Precompile) RequiredGas

func (p Precompile) RequiredGas(input []byte) uint64

RequiredGas calculates the base minimum required gas for a transaction or a query.

func (Precompile) Run

func (p Precompile) Run(
	evm *vm.EVM,
	contract *vm.Contract,
	sender ethcommon.Address,
	callingContract vm.ContractRef,
	input []byte,
	value *big.Int,
	readOnly bool,
	isFromDelegateCall bool,
) (bz []byte, err error)

func (*Precompile) SetAddress

func (p *Precompile) SetAddress(addr ethcommon.Address)

func (*Precompile) SetBalanceChangeEntries

func (p *Precompile) SetBalanceChangeEntries(entries ...balanceChangeEntry)

SetBalanceChangeEntries sets the balanceChange entries as the journalEntries field of the precompile. These entries will be added to the stateDB's journal when calling the AddJournalEntries function

type PrecompileExecutor

type PrecompileExecutor interface {
	RequiredGas(input []byte, method *abi.Method) uint64

	Execute(
		ctx sdk.Context,
		evm *vm.EVM,
		method *abi.Method,
		caller ethcommon.Address,
		callingContract vm.ContractRef,
		args []interface{},
		value *big.Int,
		readOnly bool,
		isFromDelegateCall bool,
	) (ret []byte, err error)
}

Jump to

Keyboard shortcuts

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