keeper

package
v0.14.0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: Apache-2.0 Imports: 86 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryListContractByCode = "list-contracts-by-code"
	QueryGetContract        = "contract-info"
	QueryGetContractState   = "contract-state"
	QueryGetCode            = "code"
	QueryListCode           = "list-code"
	QueryContractHistory    = "contract-history"
)
View Source
const (
	QueryMethodContractStateSmart = "smart"
	QueryMethodContractStateAll   = "all"
	QueryMethodContractStateRaw   = "raw"
)
View Source
const CompileCost uint64 = 2

CompileCost is how much SDK gas we charge *per byte* for compiling WASM code.

View Source
const GasMultiplier uint64 = 100

GasMultiplier is how many cosmwasm gas points = 1 sdk gas point SDK reference costs can be found here: https://github.com/cosmos/cosmos-sdk/blob/02c6c9fafd58da88550ab4d7d494724a477c8a68/store/types/gas.go#L153-L164 A write at ~3000 gas and ~200us = 10 gas per us (microsecond) cpu/io Rough timing have 88k gas at 90us, which is equal to 1k sdk gas... (one read)

Please note that all gas prices returned to the wasmer engine should have this multiplied

View Source
const InstanceCost uint64 = 40_000

InstanceCost is how much SDK gas we charge each time we load a WASM instance. Creating a new instance is costly, and this helps put a recursion limit to contracts calling contracts.

View Source
const MaxGas = 10_000_000_000

MaxGas for a contract is 10 billion wasmer gas (enforced in rust to prevent overflow) The limit for v0.9.3 is defined here: https://github.com/CosmWasm/cosmwasm/blob/v0.9.3/packages/vm/src/backends/singlepass.rs#L15-L23 (this will be increased in future releases)

Variables

View Source
var (
	CostHumanize  = 5 * GasMultiplier
	CostCanonical = 4 * GasMultiplier
)
View Source
var TestingStakeParams = stakingtypes.Params{
	UnbondingTime:     100,
	MaxValidators:     10,
	MaxEntries:        10,
	HistoricalEntries: 10,
	BondDenom:         "stake",
}

Functions

func BankQuerier

func BankQuerier(bankKeeper types.BankViewKeeper) func(ctx sdk.Context, request *wasmvmtypes.BankQuery) ([]byte, error)

func ContractFromPortID

func ContractFromPortID(portID string) (sdk.AccAddress, error)

func ConvertWasmIBCTimeout

func ConvertWasmIBCTimeout(ibcTimeout wasmvmtypes.IBCTimeout) (uint64, ibcclienttypes.Height)

ConvertWasmIBCTimeout converts the wasmvm ibc timeout type to cosmos-sdk height and relative block timeout

func EncodeBankMsg

func EncodeBankMsg(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error)

func EncodeDistributionMsg

func EncodeDistributionMsg(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error)

func EncodeIBCMsg

func EncodeIBCMsg(portSource types.ICS20TransferPortSource) func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error)

func EncodeStakingMsg

func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error)

func EncodeWasmMsg

func EncodeWasmMsg(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)

func ExportGenesis

func ExportGenesis(ctx sdk.Context, keeper *Keeper) *types.GenesisState

ExportGenesis returns a GenesisState for a given context and keeper.

func FuzzAbsoluteTxPosition

func FuzzAbsoluteTxPosition(m *types.AbsoluteTxPosition, c fuzz.Continue)

func FuzzAccessConfig

func FuzzAccessConfig(m *types.AccessConfig, c fuzz.Continue)

func FuzzAccessType

func FuzzAccessType(m *types.AccessType, c fuzz.Continue)

func FuzzAddr

func FuzzAddr(m *sdk.AccAddress, c fuzz.Continue)

func FuzzAddrString

func FuzzAddrString(m *string, c fuzz.Continue)

func FuzzContractCodeHistory

func FuzzContractCodeHistory(m *types.ContractCodeHistoryEntry, c fuzz.Continue)

func FuzzContractInfo

func FuzzContractInfo(m *types.ContractInfo, c fuzz.Continue)

func FuzzStateModel

func FuzzStateModel(m *types.Model, c fuzz.Continue)

func IBCQuerier

func IBCQuerier(wasm contractMetaDataSource, channelKeeper types.ChannelKeeper) func(ctx sdk.Context, caller sdk.AccAddress, request *wasmvmtypes.IBCQuery) ([]byte, error)

func InitGenesis

func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, stakingKeeper ValidatorSetSource, msgHandler sdk.Handler) ([]abci.ValidatorUpdate, error)

InitGenesis sets supply information for genesis.

CONTRACT: all types of accounts must have been already initialized/created

func LimitReader

func LimitReader(r io.Reader, n int64) io.Reader

LimitReader returns a Reader that reads from r but stops with types.ErrLimit after n bytes. The underlying implementation is a *io.LimitedReader.

func MakeEncodingConfig

func MakeEncodingConfig(_ TestingT) params2.EncodingConfig

func MakeTestCodec

func MakeTestCodec(t TestingT) codec.Marshaler

func NewGrpcQuerier

func NewGrpcQuerier(cdc codec.Marshaler, storeKey sdk.StoreKey, keeper types.ViewKeeper, queryGasLimit sdk.Gas) *grpcQuerier

func NewLegacyQuerier

func NewLegacyQuerier(keeper types.ViewKeeper, gasLimit sdk.Gas) sdk.Querier

NewLegacyQuerier creates a new querier

func NewMsgServerImpl

func NewMsgServerImpl(k types.ContractOpsKeeper) types.MsgServer

func NewWasmProposalHandler

func NewWasmProposalHandler(k decoratedKeeper, enabledProposalTypes []types.ProposalType) govtypes.Handler

NewWasmProposalHandler creates a new governance Handler for wasm proposals

func NewWasmProposalHandlerX

func NewWasmProposalHandlerX(k types.ContractOpsKeeper, enabledProposalTypes []types.ProposalType) govtypes.Handler

NewWasmProposalHandlerX creates a new governance Handler for wasm proposals

func NoCustomMsg

func NoCustomMsg(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)

func NoCustomQuerier

func NoCustomQuerier(sdk.Context, json.RawMessage) ([]byte, error)

func PortIDForContract

func PortIDForContract(addr sdk.AccAddress) string

func Querier

func Querier(k *Keeper) *grpcQuerier

Querier creates a new grpc querier instance

func RandomAccountAddress

func RandomAccountAddress(_ TestingT) sdk.AccAddress

func RandomBech32AccountAddress

func RandomBech32AccountAddress(t TestingT) string

func StakingQuerier

func StakingQuerier(keeper types.StakingKeeper, distKeeper types.DistributionKeeper) func(ctx sdk.Context, request *wasmvmtypes.StakingQuery) ([]byte, error)

func StargateQuerier

func StargateQuerier(queryRouter GRPCQueryRouter) func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error)

func StoreReflectContract

func StoreReflectContract(t TestingT, ctx sdk.Context, keepers TestKeepers) uint64

func TestHandler

func TestHandler(k types.ContractOpsKeeper) sdk.Handler

TestHandler returns a wasm handler for tests (to avoid circular imports)

func WasmQuerier

func WasmQuerier(wasm wasmQueryKeeper) func(ctx sdk.Context, request *wasmvmtypes.WasmQuery) ([]byte, error)

Types

type AuthorizationPolicy

type AuthorizationPolicy interface {
	CanCreateCode(c types.AccessConfig, creator sdk.AccAddress) bool
	CanInstantiateContract(c types.AccessConfig, actor sdk.AccAddress) bool
	CanModifyContract(admin, actor sdk.AccAddress) bool
}

type BankCoinTransferrer

type BankCoinTransferrer struct {
	// contains filtered or unexported fields
}

BankCoinTransferrer replicates the cosmos-sdk behaviour as in https://github.com/cosmos/cosmos-sdk/blob/v0.41.4/x/bank/keeper/msg_server.go#L26

func NewBankCoinTransferrer

func NewBankCoinTransferrer(keeper types.BankKeeper) BankCoinTransferrer

func (BankCoinTransferrer) TransferCoins

func (c BankCoinTransferrer) TransferCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error

TransferCoins transfers coins from source to destination account when coin send was enabled for them and the recipient is not in the blocked address list.

type BankEncoder

type BankEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error)

type BurnerExampleInitMsg

type BurnerExampleInitMsg struct {
	Payout sdk.AccAddress `json:"payout"`
}

func (BurnerExampleInitMsg) GetBytes

func (m BurnerExampleInitMsg) GetBytes(t TestingT) []byte

type CoinTransferrer

type CoinTransferrer interface {
	// TransferCoins sends the coin amounts from the source to the destination with rules applied.
	TransferCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
}

type CustomEncoder

type CustomEncoder func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)

type CustomQuerier

type CustomQuerier func(ctx sdk.Context, request json.RawMessage) ([]byte, error)

type DefaultAuthorizationPolicy

type DefaultAuthorizationPolicy struct {
}

func (DefaultAuthorizationPolicy) CanCreateCode

func (p DefaultAuthorizationPolicy) CanCreateCode(config types.AccessConfig, actor sdk.AccAddress) bool

func (DefaultAuthorizationPolicy) CanInstantiateContract

func (p DefaultAuthorizationPolicy) CanInstantiateContract(config types.AccessConfig, actor sdk.AccAddress) bool

func (DefaultAuthorizationPolicy) CanModifyContract

func (p DefaultAuthorizationPolicy) CanModifyContract(admin, actor sdk.AccAddress) bool

type DefaultWasmVMContractResponseHandler

type DefaultWasmVMContractResponseHandler struct {
	// contains filtered or unexported fields
}

DefaultWasmVMContractResponseHandler default implementation that first dispatches submessage then normal messages. The Submessage execution may include an success/failure response handling by the contract that can overwrite the original

func NewDefaultWasmVMContractResponseHandler

func NewDefaultWasmVMContractResponseHandler(md msgDispatcher) *DefaultWasmVMContractResponseHandler

func (DefaultWasmVMContractResponseHandler) Handle

func (h DefaultWasmVMContractResponseHandler) Handle(
	ctx sdk.Context,
	contractAddr sdk.AccAddress,
	ibcPort string,
	submessages []wasmvmtypes.SubMsg,
	messages []wasmvmtypes.CosmosMsg,
	origRspData []byte,
) ([]byte, error)

Handle processes the data returned by a contract invocation.

type DistributionEncoder

type DistributionEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error)

type ExampleContract

type ExampleContract struct {
	InitialAmount sdk.Coins
	Creator       crypto.PrivKey
	CreatorAddr   sdk.AccAddress
	CodeID        uint64
}

func StoreBurnerExampleContract

func StoreBurnerExampleContract(t TestingT, ctx sdk.Context, keepers TestKeepers) ExampleContract

func StoreExampleContract

func StoreExampleContract(t TestingT, ctx sdk.Context, keepers TestKeepers, wasmFile string) ExampleContract

func StoreHackatomExampleContract

func StoreHackatomExampleContract(t TestingT, ctx sdk.Context, keepers TestKeepers) ExampleContract

func StoreIBCReflectContract

func StoreIBCReflectContract(t TestingT, ctx sdk.Context, keepers TestKeepers) ExampleContract

func StoreRandomContract

func StoreRandomContract(t TestingT, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContract

StoreRandomContract sets the mock wasmerEngine in keeper and calls store

type ExampleContractInstance

type ExampleContractInstance struct {
	ExampleContract
	Contract sdk.AccAddress
}

func SeedNewContractInstance

func SeedNewContractInstance(t TestingT, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContractInstance

SeedNewContractInstance sets the mock wasmerEngine in keeper and calls store + instantiate to init the contract's metadata

type GRPCQueryHandler

type GRPCQueryHandler = func(ctx sdk.Context, req abci.RequestQuery) (abci.ResponseQuery, error)

GRPCQueryHandler defines a function type which handles ABCI Query requests using gRPC

type GRPCQueryRouter

type GRPCQueryRouter interface {
	Route(path string) GRPCQueryHandler
}

type GovAuthorizationPolicy

type GovAuthorizationPolicy struct {
}

func (GovAuthorizationPolicy) CanCreateCode

func (GovAuthorizationPolicy) CanInstantiateContract

func (p GovAuthorizationPolicy) CanInstantiateContract(types.AccessConfig, sdk.AccAddress) bool

func (GovAuthorizationPolicy) CanModifyContract

func (p GovAuthorizationPolicy) CanModifyContract(sdk.AccAddress, sdk.AccAddress) bool

type HackatomExampleInitMsg

type HackatomExampleInitMsg struct {
	Verifier    sdk.AccAddress `json:"verifier"`
	Beneficiary sdk.AccAddress `json:"beneficiary"`
}

func (HackatomExampleInitMsg) GetBytes

func (m HackatomExampleInitMsg) GetBytes(t TestingT) []byte

type HackatomExampleInstance

type HackatomExampleInstance struct {
	ExampleContract
	Contract        sdk.AccAddress
	Verifier        crypto.PrivKey
	VerifierAddr    sdk.AccAddress
	Beneficiary     crypto.PrivKey
	BeneficiaryAddr sdk.AccAddress
}

func InstantiateHackatomExampleContract

func InstantiateHackatomExampleContract(t TestingT, ctx sdk.Context, keepers TestKeepers) HackatomExampleInstance

InstantiateHackatomExampleContract load and instantiate the "./testdata/hackatom.wasm" contract

type IBCEncoder

type IBCEncoder func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error)

type IBCRawPacketHandler

type IBCRawPacketHandler struct {
	// contains filtered or unexported fields
}

IBCRawPacketHandler handels IBC.SendPacket messages which are published to an IBC channel.

func (IBCRawPacketHandler) DispatchMsg

func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error)

DispatchMsg publishes a raw IBC packet onto the channel.

type IBCReflectExampleInstance

type IBCReflectExampleInstance struct {
	Contract      sdk.AccAddress
	Admin         sdk.AccAddress
	CodeID        uint64
	ReflectCodeID uint64
}

func InstantiateIBCReflectContract

func InstantiateIBCReflectContract(t TestingT, ctx sdk.Context, keepers TestKeepers) IBCReflectExampleInstance

InstantiateIBCReflectContract load and instantiate the "./testdata/ibc_reflect.wasm" contract

type IBCReflectInitMsg

type IBCReflectInitMsg struct {
	ReflectCodeID uint64 `json:"reflect_code_id"`
}

func (IBCReflectInitMsg) GetBytes

func (m IBCReflectInitMsg) GetBytes(t TestingT) []byte

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Keeper will have a reference to Wasmer with it's own data directory.

func NewKeeper

func NewKeeper(
	cdc codec.Marshaler,
	storeKey sdk.StoreKey,
	paramSpace paramtypes.Subspace,
	accountKeeper authkeeper.AccountKeeper,
	bankKeeper types.BankKeeper,
	stakingKeeper types.StakingKeeper,
	distKeeper types.DistributionKeeper,
	channelKeeper types.ChannelKeeper,
	portKeeper types.PortKeeper,
	capabilityKeeper types.CapabilityKeeper,
	portSource types.ICS20TransferPortSource,
	router sdk.Router,
	queryRouter GRPCQueryRouter,
	homeDir string,
	wasmConfig types.WasmConfig,
	supportedFeatures string,
	opts ...Option,
) Keeper

NewKeeper creates a new contract Keeper instance If customEncoders is non-nil, we can use this to override some of the message handler, especially custom

func (Keeper) AuthenticateCapability

func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool

AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function

func (Keeper) ClaimCapability

func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error

ClaimCapability allows the transfer module to claim a capability that IBC module passes to it

func (Keeper) GetByteCode

func (k Keeper) GetByteCode(ctx sdk.Context, codeID uint64) ([]byte, error)

func (Keeper) GetCodeInfo

func (k Keeper) GetCodeInfo(ctx sdk.Context, codeID uint64) *types.CodeInfo

func (Keeper) GetContractHistory

func (k Keeper) GetContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress) []types.ContractCodeHistoryEntry

func (Keeper) GetContractInfo

func (k Keeper) GetContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) *types.ContractInfo

func (Keeper) GetContractState

func (k Keeper) GetContractState(ctx sdk.Context, contractAddress sdk.AccAddress) sdk.Iterator

func (Keeper) GetMaxWasmCodeSize

func (k Keeper) GetMaxWasmCodeSize(ctx sdk.Context) uint64

func (Keeper) GetNextCodeID

func (k Keeper) GetNextCodeID(ctx sdk.Context) uint64

GetNextCodeID reads the next sequence id used for storing wasm code. Read only operation.

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) types.Params

GetParams returns the total set of wasm parameters.

func (Keeper) HasContractInfo

func (k Keeper) HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool

func (Keeper) InitializePinnedCodes

func (k Keeper) InitializePinnedCodes(ctx sdk.Context) error

InitializePinnedCodes updates wasmvm to pin to cache all contracts marked as pinned

func (Keeper) IsPinnedCode

func (k Keeper) IsPinnedCode(ctx sdk.Context, codeID uint64) bool

IsPinnedCode returns true when codeID is pinned in wasmvm cache

func (Keeper) IterateCodeInfos

func (k Keeper) IterateCodeInfos(ctx sdk.Context, cb func(uint64, types.CodeInfo) bool)

func (Keeper) IterateContractInfo

func (k Keeper) IterateContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, types.ContractInfo) bool)

func (Keeper) IterateContractsByCode

func (k Keeper) IterateContractsByCode(ctx sdk.Context, codeID uint64, cb func(address sdk.AccAddress) bool)

IterateContractsByCode iterates over all contracts with given codeID ASC on code update time.

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger.

func (Keeper) OnAckPacket

func (k Keeper) OnAckPacket(
	ctx sdk.Context,
	contractAddr sdk.AccAddress,
	acknowledgement wasmvmtypes.IBCAcknowledgement,
) error

OnAckPacket calls the contract to handle the "acknowledgement" data which can contain success or failure of a packet acknowledgement written on the receiving chain for example. This is application level data and fully owned by the contract. The use of the standard acknowledgement envelope is recommended: https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#acknowledgement-envelope

On application errors the contract can revert an operation like returning tokens as in ibc-transfer.

For more information see: https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#packet-flow--handling

func (Keeper) OnCloseChannel

func (k Keeper) OnCloseChannel(
	ctx sdk.Context,
	contractAddr sdk.AccAddress,
	channel wasmvmtypes.IBCChannel,
) error

OnCloseChannel calls the contract to let it know the IBC channel is closed. Calling modules MAY atomically execute appropriate application logic in conjunction with calling chanCloseConfirm.

Once closed, channels cannot be reopened and identifiers cannot be reused. Identifier reuse is prevented because we want to prevent potential replay of previously sent packets See https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#channel-lifecycle-management

func (Keeper) OnConnectChannel

func (k Keeper) OnConnectChannel(
	ctx sdk.Context,
	contractAddr sdk.AccAddress,
	channel wasmvmtypes.IBCChannel,
) error

OnConnectChannel calls the contract to let it know the IBC channel was established. In the IBC protocol this is either the `Channel Open Ack` event on the initiating chain or `Channel Open Confirm` on the counterparty chain.

There is an open issue with the [cosmos-sdk](https://github.com/cosmos/cosmos-sdk/issues/8334) that the counterparty channelID is empty on the initiating chain See https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#channel-lifecycle-management

func (Keeper) OnOpenChannel

func (k Keeper) OnOpenChannel(
	ctx sdk.Context,
	contractAddr sdk.AccAddress,
	channel wasmvmtypes.IBCChannel,
) error

OnOpenChannel calls the contract to participate in the IBC channel handshake step. In the IBC protocol this is either the `Channel Open Init` event on the initiating chain or `Channel Open Try` on the counterparty chain. Protocol version and channel ordering should be verified for example. See https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#channel-lifecycle-management

func (Keeper) OnRecvPacket

func (k Keeper) OnRecvPacket(
	ctx sdk.Context,
	contractAddr sdk.AccAddress,
	packet wasmvmtypes.IBCPacket,
) ([]byte, error)

OnRecvPacket calls the contract to process the incoming IBC packet. The contract fully owns the data processing and returns the acknowledgement data for the chain level. This allows custom applications and protocols on top of IBC. Although it is recommended to use the standard acknowledgement envelope defined in https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#acknowledgement-envelope

For more information see: https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#packet-flow--handling

func (Keeper) OnTimeoutPacket

func (k Keeper) OnTimeoutPacket(
	ctx sdk.Context,
	contractAddr sdk.AccAddress,
	packet wasmvmtypes.IBCPacket,
) error

OnTimeoutPacket calls the contract to let it know the packet was never received on the destination chain within the timeout boundaries. The contract should handle this on the application level and undo the original operation

func (Keeper) QueryGasLimit

func (k Keeper) QueryGasLimit() sdk.Gas

QueryGasLimit returns the gas limit for smart queries.

func (Keeper) QueryRaw

func (k Keeper) QueryRaw(ctx sdk.Context, contractAddress sdk.AccAddress, key []byte) []byte

QueryRaw returns the contract's state for give key. Returns `nil` when key is `nil`.

func (Keeper) QuerySmart

func (k Keeper) QuerySmart(ctx sdk.Context, contractAddr sdk.AccAddress, req []byte) ([]byte, error)

QuerySmart queries the smart contract itself.

func (Keeper) Sudo

func (k Keeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) (*sdk.Result, error)

Sudo allows priviledged access to a contract. This can never be called by governance or external tx, but only by another native Go module directly. Thus, the keeper doesn't place any access controls on it, that is the responsibility or the app developer (who passes the wasm.Keeper in app.go)

type LimitedReader

type LimitedReader struct {
	// contains filtered or unexported fields
}

func (*LimitedReader) Read

func (l *LimitedReader) Read(p []byte) (n int, err error)

type MessageDispatcher

type MessageDispatcher struct {
	// contains filtered or unexported fields
}

MessageDispatcher coordinates message sending and submessage reply/ state commits

func NewMessageDispatcher

func NewMessageDispatcher(messenger Messenger, keeper replyer) *MessageDispatcher

NewMessageDispatcher constructor

func (MessageDispatcher) DispatchMessages

func (d MessageDispatcher) DispatchMessages(ctx sdk.Context, contractAddr sdk.AccAddress, ibcPort string, msgs []wasmvmtypes.CosmosMsg) error

DispatchMessages sends all messages.

func (MessageDispatcher) DispatchSubmessages

func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk.AccAddress, ibcPort string, msgs []wasmvmtypes.SubMsg) ([]byte, error)

DispatchSubmessages builds a sandbox to execute these messages and returns the execution result to the contract that dispatched them, both on success as well as failure

type MessageEncoders

type MessageEncoders struct {
	Bank         func(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error)
	Custom       func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)
	Distribution func(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error)
	IBC          func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error)
	Staking      func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error)
	Stargate     func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error)
	Wasm         func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)
}

func DefaultEncoders

func DefaultEncoders(unpacker codectypes.AnyUnpacker, portSource types.ICS20TransferPortSource) MessageEncoders

func (MessageEncoders) Encode

func (e MessageEncoders) Encode(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) ([]sdk.Msg, error)

func (MessageEncoders) Merge

type MessageHandlerChain

type MessageHandlerChain struct {
	// contains filtered or unexported fields
}

MessageHandlerChain defines a chain of handlers that are called one by one until it can be handled.

func NewMessageHandlerChain

func NewMessageHandlerChain(first Messenger, others ...Messenger) *MessageHandlerChain

func (MessageHandlerChain) DispatchMsg

func (m MessageHandlerChain) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) ([]sdk.Event, [][]byte, error)

DispatchMsg dispatch message to handlers.

type MessageHandlerFunc

type MessageHandlerFunc func(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error)

MessageHandlerFunc is a helper to construct simple function based message handler

func NewBurnCoinMessageHandler

func NewBurnCoinMessageHandler(burner types.Burner) MessageHandlerFunc

NewBurnCoinMessageHandler handles wasmvm.BurnMsg messages

func (MessageHandlerFunc) DispatchMsg

func (m MessageHandlerFunc) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error)

type Messenger

type Messenger interface {
	// DispatchMsg encodes the wasmVM message and dispatches it.
	DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error)
}

Messenger is an extension point for custom wasmd message handling

func NewDefaultMessageHandler

func NewDefaultMessageHandler(
	router sdk.Router,
	channelKeeper types.ChannelKeeper,
	capabilityKeeper types.CapabilityKeeper,
	bankKeeper types.Burner,
	unpacker codectypes.AnyUnpacker,
	portSource types.ICS20TransferPortSource,
	customEncoders ...*MessageEncoders,
) Messenger

type MultipliedGasMeter

type MultipliedGasMeter struct {
	// contains filtered or unexported fields
}

MultipliedGasMeter wraps the GasMeter from context and multiplies all reads by out defined multiplier

func (MultipliedGasMeter) GasConsumed

func (m MultipliedGasMeter) GasConsumed() sdk.Gas

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an extension point to instantiate keeper with non default values

func WithCoinTransferrer

func WithCoinTransferrer(x CoinTransferrer) Option

WithCoinTransferrer is an optional constructor parameter to set a custom coin transferrer

func WithMessageEncoders

func WithMessageEncoders(x *MessageEncoders) Option

WithMessageEncoders is an optional constructor parameter to pass custom message encoder to the default wasm message handler. This option expects the `DefaultMessageHandler` set an should not be combined with Option `WithMessageHandler`.

func WithMessageHandler

func WithMessageHandler(x Messenger) Option

WithMessageHandler is an optional constructor parameter to set a custom handler for wasmVM messages. This option should not be combined with Option `WithMessageEncoders`.

func WithQueryHandler

func WithQueryHandler(x WasmVMQueryHandler) Option

WithQueryHandler is an optional constructor parameter to set custom query handler for wasmVM requests. This option should not be combined with Option `WithQueryPlugins`.

func WithQueryPlugins

func WithQueryPlugins(x *QueryPlugins) Option

WithQueryPlugins is an optional constructor parameter to pass custom query plugins for wasmVM requests. This option expects the default `QueryHandler` set an should not be combined with Option `WithQueryHandler`.

func WithVMCacheMetrics

func WithVMCacheMetrics(r prometheus.Registerer) Option

func WithWasmEngine

func WithWasmEngine(x types.WasmerEngine) Option

WithWasmEngine is an optional constructor parameter to replace the default wasmVM engine with the given one.

type PermissionedKeeper

type PermissionedKeeper struct {
	// contains filtered or unexported fields
}

func NewDefaultPermissionKeeper

func NewDefaultPermissionKeeper(nested decoratedKeeper) *PermissionedKeeper

func NewGovPermissionKeeper

func NewGovPermissionKeeper(nested decoratedKeeper) *PermissionedKeeper

func NewPermissionedKeeper

func NewPermissionedKeeper(nested decoratedKeeper, authZPolicy AuthorizationPolicy) *PermissionedKeeper

func (PermissionedKeeper) ClearContractAdmin

func (p PermissionedKeeper) ClearContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress) error

func (PermissionedKeeper) Create

func (p PermissionedKeeper) Create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, source string, builder string, instantiateAccess *types.AccessConfig) (codeID uint64, err error)

func (PermissionedKeeper) Execute

func (p PermissionedKeeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) (*sdk.Result, error)

func (PermissionedKeeper) Instantiate

func (p PermissionedKeeper) Instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, deposit sdk.Coins) (sdk.AccAddress, []byte, error)

func (PermissionedKeeper) Migrate

func (p PermissionedKeeper) Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) (*sdk.Result, error)

func (PermissionedKeeper) PinCode

func (p PermissionedKeeper) PinCode(ctx sdk.Context, codeID uint64) error

func (PermissionedKeeper) SetContractInfoExtension

func (p PermissionedKeeper) SetContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra types.ContractInfoExtension) error

SetExtraContractAttributes updates the extra attributes that can be stored with the contract info

func (PermissionedKeeper) UnpinCode

func (p PermissionedKeeper) UnpinCode(ctx sdk.Context, codeID uint64) error

func (PermissionedKeeper) UpdateContractAdmin

func (p PermissionedKeeper) UpdateContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newAdmin sdk.AccAddress) error

type QueryHandler

type QueryHandler struct {
	Ctx     sdk.Context
	Plugins WasmVMQueryHandler
	Caller  sdk.AccAddress
}

func NewQueryHandler

func NewQueryHandler(ctx sdk.Context, vmQueryHandler WasmVMQueryHandler, caller sdk.AccAddress) QueryHandler

func (QueryHandler) GasConsumed

func (q QueryHandler) GasConsumed() uint64

func (QueryHandler) Query

func (q QueryHandler) Query(request wasmvmtypes.QueryRequest, gasLimit uint64) ([]byte, error)

type QueryPlugins

type QueryPlugins struct {
	Bank     func(ctx sdk.Context, request *wasmvmtypes.BankQuery) ([]byte, error)
	Custom   CustomQuerier
	IBC      func(ctx sdk.Context, caller sdk.AccAddress, request *wasmvmtypes.IBCQuery) ([]byte, error)
	Staking  func(ctx sdk.Context, request *wasmvmtypes.StakingQuery) ([]byte, error)
	Stargate func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error)
	Wasm     func(ctx sdk.Context, request *wasmvmtypes.WasmQuery) ([]byte, error)
}

func DefaultQueryPlugins

func DefaultQueryPlugins(
	bank types.BankViewKeeper,
	staking types.StakingKeeper,
	distKeeper types.DistributionKeeper,
	channelKeeper types.ChannelKeeper,
	queryRouter GRPCQueryRouter,
	wasm wasmQueryKeeper,
) QueryPlugins

func (QueryPlugins) HandleQuery

func (e QueryPlugins) HandleQuery(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error)

HandleQuery executes the requested query

func (QueryPlugins) Merge

type SDKMessageHandler

type SDKMessageHandler struct {
	// contains filtered or unexported fields
}

SDKMessageHandler can handles messages that can be encoded into sdk.Message types and routed.

func NewSDKMessageHandler

func NewSDKMessageHandler(router sdk.Router, encoders msgEncoder) SDKMessageHandler

func (SDKMessageHandler) DispatchMsg

func (h SDKMessageHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error)

type StakingEncoder

type StakingEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error)

type StargateEncoder

type StargateEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error)

func EncodeStargateMsg

func EncodeStargateMsg(unpacker codectypes.AnyUnpacker) StargateEncoder

type TestKeepers

type TestKeepers struct {
	AccountKeeper  authkeeper.AccountKeeper
	StakingKeeper  stakingkeeper.Keeper
	DistKeeper     distributionkeeper.Keeper
	BankKeeper     bankkeeper.Keeper
	GovKeeper      govkeeper.Keeper
	ContractKeeper types.ContractOpsKeeper
	WasmKeeper     *Keeper
	IBCKeeper      *ibckeeper.Keeper
	Router         *baseapp.Router
	EncodingConfig params2.EncodingConfig
}

func CreateDefaultTestInput

func CreateDefaultTestInput(t TestingT) (sdk.Context, TestKeepers)

CreateDefaultTestInput common settings for CreateTestInput

func CreateTestInput

func CreateTestInput(t TestingT, isCheckTx bool, supportedFeatures string, opts ...Option) (sdk.Context, TestKeepers)

encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default)

type TestingT

type TestingT interface {
	Errorf(format string, args ...interface{})
	FailNow()
	TempDir() string
	Helper()
}

type ValidatorSetSource

type ValidatorSetSource interface {
	ApplyAndReturnValidatorSetUpdates(sdk.Context) (updates []abci.ValidatorUpdate, err error)
}

ValidatorSetSource is a subset of the staking keeper

type WasmEncoder

type WasmEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)

type WasmVMMetricsCollector

type WasmVMMetricsCollector struct {
	CacheHitsDescr     *prometheus.Desc
	CacheMissesDescr   *prometheus.Desc
	CacheElementsDescr *prometheus.Desc
	CacheSizeDescr     *prometheus.Desc
	// contains filtered or unexported fields
}

WasmVMMetricsCollector custom metrics collector to be used with Prometheus

func NewWasmVMMetricsCollector

func NewWasmVMMetricsCollector(s metricSource) *WasmVMMetricsCollector

NewWasmVMMetricsCollector constructor

func (*WasmVMMetricsCollector) Collect

func (p *WasmVMMetricsCollector) Collect(c chan<- prometheus.Metric)

Collect is called by the Prometheus registry when collecting metrics.

func (*WasmVMMetricsCollector) Describe

func (p *WasmVMMetricsCollector) Describe(descs chan<- *prometheus.Desc)

Describe sends the super-set of all possible descriptors of metrics

func (*WasmVMMetricsCollector) Register

Register registers all metrics

type WasmVMQueryHandler

type WasmVMQueryHandler interface {
	// HandleQuery executes the requested query
	HandleQuery(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error)
}

WasmVMQueryHandler is an extension point for custom query handler implementations

type WasmVMResponseHandler

type WasmVMResponseHandler interface {
	// Handle processes the data returned by a contract invocation.
	Handle(
		ctx sdk.Context,
		contractAddr sdk.AccAddress,
		ibcPort string,
		submessages []wasmvmtypes.SubMsg,
		messages []wasmvmtypes.CosmosMsg,
		origRspData []byte,
	) ([]byte, error)
}

WasmVMResponseHandler is an extension point to handles the response data returned by a contract call.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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