Documentation
¶
Index ¶
- Constants
- Variables
- func HandleGasError(ctx sdk.Context, contract *vm.Contract, initialGas storetypes.Gas, err *error, ...) func()
- func LoadABI(fs embed.FS, path string) (abi.ABI, error)
- func MakeTopic(rule interface{}) (common.Hash, error)
- func NewSdkCoinsFromCoins(coins []Coin) (sdk.Coins, error)
- func PackNum(value reflect.Value) []byte
- func SafeAdd(a, b math.Int) (res *big.Int, overflow bool)
- func UnpackLog(contractABI abi.ABI, out interface{}, event string, log ethtypes.Log) error
- type BalanceChangeEntry
- type BankKeeper
- type Coin
- type Dec
- type DecCoin
- type ICS20Allocation
- type Operation
- type Precompile
- func (p Precompile) AddJournalEntries(stateDB *statedb.StateDB, s Snapshot) error
- func (p Precompile) Address() common.Address
- func (p Precompile) RequiredGas(input []byte, isTransaction bool) uint64
- func (p Precompile) RunAtomic(s Snapshot, stateDB *statedb.StateDB, fn func() ([]byte, error)) ([]byte, error)
- func (p Precompile) RunSetup(evm *vm.EVM, contract *vm.Contract, readOnly bool, ...) (ctx sdk.Context, stateDB *statedb.StateDB, s Snapshot, method *abi.Method, ...)
- func (p *Precompile) SetAddress(addr common.Address)
- func (p *Precompile) SetBalanceChangeEntries(entries ...BalanceChangeEntry)
- type Snapshot
Constants ¶
const ( // ErrNotRunInEvm is raised when a function is not called inside the EVM. ErrNotRunInEvm = "not run in EVM" // ErrRequesterIsNotMsgSender is raised when the requester address is not the same as the msg.sender. ErrRequesterIsNotMsgSender = "msg.sender address %s does not match the requester 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" // ErrInvalidHexAddress is raised when the hex address is not valid. ErrInvalidHexAddress = "invalid hex address address: %s" // ErrInvalidDelegator is raised when the delegator address is not valid. ErrInvalidDelegator = "invalid delegator address: %s" // ErrInvalidValidator is raised when the validator address is not valid. ErrInvalidValidator = "invalid validator 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 ¶
var 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}
TrueValue is the byte array representing a true value in solidity.
Functions ¶
func HandleGasError ¶
func HandleGasError(ctx sdk.Context, contract *vm.Contract, initialGas storetypes.Gas, err *error, stateDB *statedb.StateDB, snapshot Snapshot) 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 MakeTopic ¶
MakeTopic converts a filter query argument into a filter topic. NOTE: This was copied from accounts/abi/topics.go
func NewSdkCoinsFromCoins ¶ added in v0.3.0
NewSdkCoinsFromCoins converts a slice of Coin to sdk.Coins.
func PackNum ¶
PackNum packs the given number (using the reflect value) and will cast it to appropriate number representation.
Types ¶
type BalanceChangeEntry ¶ added in v0.3.0
func NewBalanceChangeEntry ¶
type BankKeeper ¶ added in v0.2.0
type Coin ¶
Coin defines a struct that stores all needed information about a coin in types native to the EVM.
func NewCoinsResponse ¶
NewCoinsResponse converts a response to an array of Coin.
type Dec ¶
Dec defines a struct that represents a decimal number of a given precision in types native to the EVM.
type DecCoin ¶
DecCoin defines a struct that stores all needed information about a decimal coin in types native to the EVM.
func NewDecCoinsResponse ¶
NewDecCoinsResponse converts a response to an array of DecCoin.
type ICS20Allocation ¶
type ICS20Allocation struct {
SourcePort string
SourceChannel string
SpendLimit []Coin
AllowList []string
AllowedPacketData []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 Operation ¶
type Operation int8
Operation is a type that defines if the precompile call produced an addition or subtraction of an account's balance
type Precompile ¶
type Precompile struct {
abi.ABI
KvGasConfig storetypes.GasConfig
TransientKVGasConfig storetypes.GasConfig
// contains filtered or unexported fields
}
Precompile is a common struct for all precompiles that holds the common data each precompile needs to run which includes the ABI, Gas config.
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() common.Address
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) RunAtomic ¶ added in v0.2.0
func (p Precompile) RunAtomic(s Snapshot, stateDB *statedb.StateDB, fn func() ([]byte, error)) ([]byte, error)
RunAtomic is used within the Run function of each Precompile implementation. It handles rolling back to the provided snapshot if an error is returned from the core precompile logic. Note: This is only required for stateful precompiles.
func (Precompile) RunSetup ¶
func (p Precompile) RunSetup( evm *vm.EVM, contract *vm.Contract, readOnly bool, isTransaction func(name *abi.Method) bool, ) (ctx sdk.Context, stateDB *statedb.StateDB, s Snapshot, method *abi.Method, gasConfig storetypes.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.
func (*Precompile) SetAddress ¶
func (p *Precompile) SetAddress(addr common.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 Snapshot ¶
type Snapshot struct {
MultiStore storetypes.CacheMultiStore
Events sdk.Events
}
Snapshot contains all state and events previous to the precompile call This is needed to allow us to revert the changes during the EVM execution