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 ParseAddress(event sdk.Event, key string) (sdk.AccAddress, error)
- func ParseAmount(event sdk.Event) (*uint256.Int, error)
- func ParseFractionalAmount(event sdk.Event) (*big.Int, error)
- func ReturnRevertError(evm *vm.EVM, err error) ([]byte, error)
- func SafeAdd(a, b math.Int) (res *big.Int, overflow bool)
- func SetupABI(api abi.ABI, contract *vm.Contract, readOnly bool, ...) (method *abi.Method, args []interface{}, err error)
- func UnpackLog(contractABI abi.ABI, out interface{}, event string, log ethtypes.Log) error
- type BalanceHandler
- type BalanceHandlerFactory
- type BankKeeper
- type ChannelKeeper
- type Coin
- type Dec
- type DecCoin
- type DistributionKeeper
- type ERC20Keeper
- type ICS20Allocation
- type NativeAction
- type Precompile
- type SlashingKeeper
- type StakingKeeper
- type TransferKeeper
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) 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.
func ParseAddress ¶ added in v0.5.0
ParseAddress parses the address from the event attributes
func ParseFractionalAmount ¶ added in v0.5.0
func ReturnRevertError ¶ added in v0.3.0
ReturnRevertError returns a ExecutionReverted error with revert reason that should align with the behavior of go-ethereum implementation.
In the EVM interpreter, an opCall error is reported as ExecutionReverted, and its revert reason is stored in EVM memory and then returned by opRevert. Since precompiles are also invoked via opCall, they should be handled the same way. Therefore, the returned error must be ABI-encoded and returned, and the error type changed to ErrExecutionReverted.
related issue: https://github.com/cosmos/evm/issues/223
func SafeAdd ¶
SafeAdd adds two integers and returns a boolean if an overflow occurs to avoid panic. TODO: Upstream this to the SDK math package.
func SetupABI ¶ added in v0.5.0
func SetupABI( api abi.ABI, contract *vm.Contract, readOnly bool, isTransaction func(name *abi.Method) bool, ) (method *abi.Method, args []interface{}, err error)
SetupABI runs the initial setup required to run a transaction or a query. It returns the ABI method, initial gas and calling arguments.
Types ¶
type BalanceHandler ¶ added in v0.3.0
type BalanceHandler struct {
// contains filtered or unexported fields
}
BalanceHandler is a struct that handles balance changes in the Cosmos SDK context.
func (*BalanceHandler) AfterBalanceChange ¶ added in v0.3.0
Typically, accounts registered as BlockedAddresses in app.go—such as module accounts—are not expected to receive coins. However, in modules like precisebank, it is common to borrow and repay integer balances from the module account to support fractional balance handling.
As a result, even if a module account is marked as a BlockedAddress, a keeper-level SendCoins operation can emit an x/bank event in which the module account appears as a spender or receiver. If such events are parsed and used to invoke StateDB.AddBalance or StateDB.SubBalance, authorization errors can occur.
To prevent this, balance changes from events involving blocked addresses are not applied to the StateDB. Instead, the state changes resulting from the precompile call are applied directly via the MultiStore.
func (*BalanceHandler) BeforeBalanceChange ¶ added in v0.3.0
func (bh *BalanceHandler) BeforeBalanceChange(ctx sdk.Context)
BeforeBalanceChange is called before any balance changes by precompile methods. It records the current number of events in the context to later process balance changes using the recorded events.
type BalanceHandlerFactory ¶ added in v0.5.0
type BalanceHandlerFactory struct {
// contains filtered or unexported fields
}
BalanceHandlerFactory is a factory struct to create BalanceHandler instances.
func NewBalanceHandlerFactory ¶ added in v0.5.0
func NewBalanceHandlerFactory(bankKeeper BankKeeper) *BalanceHandlerFactory
NewBalanceHandler creates a new BalanceHandler instance.
func (BalanceHandlerFactory) NewBalanceHandler ¶ added in v0.5.0
func (bhf BalanceHandlerFactory) NewBalanceHandler() *BalanceHandler
type BankKeeper ¶ added in v0.2.0
type BankKeeper interface {
IterateAccountBalances(ctx context.Context, account sdk.AccAddress, cb func(coin sdk.Coin) bool)
IterateTotalSupply(ctx context.Context, cb func(coin sdk.Coin) bool)
GetSupply(ctx context.Context, denom string) sdk.Coin
GetDenomMetaData(ctx context.Context, denom string) (banktypes.Metadata, bool)
SetDenomMetaData(ctx context.Context, denomMetaData banktypes.Metadata)
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
SendCoins(ctx context.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
BlockedAddr(addr sdk.AccAddress) bool
}
type ChannelKeeper ¶ added in v0.5.0
type ChannelKeeper interface {
GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool)
GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, error)
}
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 DistributionKeeper ¶ added in v0.5.0
type DistributionKeeper interface {
WithdrawDelegationRewards(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error)
}
type ERC20Keeper ¶ added in v0.5.0
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 NativeAction ¶ added in v0.5.0
NativeAction abstract the native execution logic of the stateful precompile, it's passed to the base `Precompile` struct, base `Precompile` struct will handle things the native context setup, gas management, panic recovery etc, before and after the execution.
It's usually implemented by the precompile itself.
type Precompile ¶
type Precompile struct {
KvGasConfig storetypes.GasConfig
TransientKVGasConfig storetypes.GasConfig
ContractAddress common.Address
// BalanceHandlerFactory is optional
BalanceHandlerFactory *BalanceHandlerFactory
}
Precompile is the base struct for precompiles that requires to access cosmos native storage.
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) RunNativeAction ¶ added in v0.5.0
func (p Precompile) RunNativeAction(evm *vm.EVM, contract *vm.Contract, action NativeAction) ([]byte, error)
Run prepare the native context to execute native action for stateful precompile, it manages the snapshot and revert of the multi-store.
func (*Precompile) SetAddress ¶
func (p *Precompile) SetAddress(addr common.Address)
type SlashingKeeper ¶ added in v0.5.0
type SlashingKeeper interface {
Params(ctx context.Context, req *slashingtypes.QueryParamsRequest) (*slashingtypes.QueryParamsResponse, error)
SigningInfo(ctx context.Context, req *slashingtypes.QuerySigningInfoRequest) (*slashingtypes.QuerySigningInfoResponse, error)
SigningInfos(ctx context.Context, req *slashingtypes.QuerySigningInfosRequest) (*slashingtypes.QuerySigningInfosResponse, error)
}
type StakingKeeper ¶ added in v0.5.0
type StakingKeeper interface {
BondDenom(ctx context.Context) (string, error)
MaxValidators(ctx context.Context) (uint32, error)
GetDelegatorValidators(ctx context.Context, delegatorAddr sdk.AccAddress, maxRetrieve uint32) (stakingtypes.Validators, error)
GetRedelegation(ctx context.Context, delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) (red stakingtypes.Redelegation, err error)
GetValidator(ctx context.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, err error)
}
type TransferKeeper ¶ added in v0.5.0
type TransferKeeper interface {
Denom(ctx context.Context, req *ibctypes.QueryDenomRequest) (*ibctypes.QueryDenomResponse, error)
Denoms(ctx context.Context, req *ibctypes.QueryDenomsRequest) (*ibctypes.QueryDenomsResponse, error)
DenomHash(ctx context.Context, req *ibctypes.QueryDenomHashRequest) (*ibctypes.QueryDenomHashResponse, error)
Transfer(ctx context.Context, msg *ibctypes.MsgTransfer) (*ibctypes.MsgTransferResponse, error)
}