types

package
v0.9.0-alpha5 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModuleName is the name of the contract module
	ModuleName = "wasm"

	// StoreKey is the string store representation
	StoreKey = ModuleName

	// TStoreKey is the string transient store representation
	TStoreKey = "transient_" + ModuleName

	// QuerierRoute is the querier route for the staking module
	QuerierRoute = ModuleName

	// RouterKey is the msg router key for the staking module
	RouterKey = ModuleName
)
View Source
const (
	MaxWasmSize = 500 * 1024

	// MaxLabelSize is the longest label that can be used when Instantiating a contract
	MaxLabelSize = 128

	// BuildTagRegexp is a docker image regexp.
	// We only support max 128 characters, with at least one organization name (subset of all legal names).
	//
	// Details from https://docs.docker.com/engine/reference/commandline/tag/#extended-description :
	//
	// An image name is made up of slash-separated name components (optionally prefixed by a registry hostname).
	// Name components may contain lowercase characters, digits and separators.
	// A separator is defined as a period, one or two underscores, or one or more dashes. A name component may not start or end with a separator.
	//
	// A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes.
	// A tag name may not start with a period or a dash and may contain a maximum of 128 characters.
	BuildTagRegexp = "^[a-z0-9][a-z0-9._-]*[a-z0-9](/[a-z0-9][a-z0-9._-]*[a-z0-9])+:[a-zA-Z0-9_][a-zA-Z0-9_.-]*$"

	MaxBuildTagSize = 128
)
View Source
const AttributeKeyContractAddr = "contract_address"
View Source
const CustomEventType = "wasm"

Variables

View Source
var (
	DefaultCodespace = ModuleName

	// ErrCreateFailed error for wasm code that has already been uploaded or failed
	ErrCreateFailed = sdkErrors.Register(DefaultCodespace, 1, "create wasm contract failed")

	// ErrAccountExists error for a contract account that already exists
	ErrAccountExists = sdkErrors.Register(DefaultCodespace, 2, "contract account already exists")

	// ErrInstantiateFailed error for rust instantiate contract failure
	ErrInstantiateFailed = sdkErrors.Register(DefaultCodespace, 3, "instantiate wasm contract failed")

	// ErrExecuteFailed error for rust execution contract failure
	ErrExecuteFailed = sdkErrors.Register(DefaultCodespace, 4, "execute wasm contract failed")

	// ErrGasLimit error for out of gas
	ErrGasLimit = sdkErrors.Register(DefaultCodespace, 5, "insufficient gas")

	// ErrInvalidGenesis error for invalid genesis file syntax
	ErrInvalidGenesis = sdkErrors.Register(DefaultCodespace, 6, "invalid genesis")

	// ErrNotFound error for an entry not found in the store
	ErrNotFound = sdkErrors.Register(DefaultCodespace, 7, "not found")

	// ErrQueryFailed error for rust smart query contract failure
	ErrQueryFailed = sdkErrors.Register(DefaultCodespace, 8, "query wasm contract failed")

	// ErrInvalidMsg error when we cannot process the error returned from the contract
	ErrInvalidMsg = sdkErrors.Register(DefaultCodespace, 9, "invalid CosmosMsg from the contract")

	// ErrMigrationFailed error for rust execution contract failure
	ErrMigrationFailed = sdkErrors.Register(DefaultCodespace, 10, "migrate wasm contract failed")
)

Codes for wasm contract errors

View Source
var (
	KeyLastCodeID     = []byte("lastCodeId")
	KeyLastInstanceID = []byte("lastContractId")

	CodeKeyPrefix       = []byte{0x01}
	ContractKeyPrefix   = []byte{0x02}
	ContractStorePrefix = []byte{0x03}
)

nolint

View Source
var ModuleCdc *codec.Codec

ModuleCdc generic sealed codec to be used throughout module

Functions

func GetCodeKey

func GetCodeKey(contractID uint64) []byte

GetCodeKey constructs the key for retreiving the ID for the WASM code

func GetContractAddressKey

func GetContractAddressKey(addr sdk.AccAddress) []byte

GetContractAddressKey returns the key for the WASM contract instance

func GetContractStorePrefixKey

func GetContractStorePrefixKey(addr sdk.AccAddress) []byte

GetContractStorePrefixKey returns the store prefix for the WASM contract instance

func NewEnv

func NewEnv(ctx sdk.Context, creator sdk.AccAddress, deposit sdk.Coins, contractAddr sdk.AccAddress) wasmTypes.Env

NewEnv initializes the environment for a contract instance

func NewWasmCoins

func NewWasmCoins(cosmosCoins sdk.Coins) (wasmCoins []wasmTypes.Coin)

NewWasmCoins translates between Cosmos SDK coins and Wasm coins

func ParseEvents added in v0.9.0

func ParseEvents(logs []wasmTypes.LogAttribute, contractAddr sdk.AccAddress) sdk.Events

ParseEvents converts wasm LogAttributes into an sdk.Events (with 0 or 1 elements)

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers the account types and interface

func ResultFromData

func ResultFromData(data string) *sdk.Result

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

ValidateGenesis performs basic validation of supply genesis data returning an error for any failed validation criteria.

Types

type AbsoluteTxPosition added in v0.9.0

type AbsoluteTxPosition struct {
	// BlockHeight is the block the contract was created at
	BlockHeight int64
	// TxIndex is a monotonic counter within the block (actual transaction index, or gas consumed)
	TxIndex uint64
}

AbsoluteTxPosition can be used to sort contracts

func NewCreatedAt

func NewCreatedAt(ctx sdk.Context) *AbsoluteTxPosition

NewCreatedAt gets a timestamp from the context

func (*AbsoluteTxPosition) LessThan added in v0.9.0

func (a *AbsoluteTxPosition) LessThan(b *AbsoluteTxPosition) bool

LessThan can be used to sort

type Code

type Code struct {
	CodeInfo   CodeInfo `json:"code_info"`
	CodesBytes []byte   `json:"code_bytes"`
}

Code struct encompasses CodeInfo and CodeBytes

type CodeInfo

type CodeInfo struct {
	CodeHash []byte         `json:"code_hash"`
	Creator  sdk.AccAddress `json:"creator"`
	Source   string         `json:"source"`
	Builder  string         `json:"builder"`
}

CodeInfo is data for the uploaded contract WASM code

func NewCodeInfo

func NewCodeInfo(codeHash []byte, creator sdk.AccAddress, source string, builder string) CodeInfo

NewCodeInfo fills a new Contract struct

type Contract

type Contract struct {
	ContractAddress sdk.AccAddress `json:"contract_address"`
	ContractInfo    ContractInfo   `json:"contract_info"`
	ContractState   []Model        `json:"contract_state"`
}

Contract struct encompasses ContractAddress, ContractInfo, and ContractState

type ContractInfo

type ContractInfo struct {
	CodeID  uint64          `json:"code_id"`
	Creator sdk.AccAddress  `json:"creator"`
	Admin   sdk.AccAddress  `json:"admin,omitempty"`
	Label   string          `json:"label"`
	InitMsg json.RawMessage `json:"init_msg,omitempty"`
	// never show this in query results, just use for sorting
	// (Note: when using json tag "-" amino refused to serialize it...)
	Created        *AbsoluteTxPosition `json:"created,omitempty"`
	LastUpdated    *AbsoluteTxPosition `json:"last_updated,omitempty"`
	PreviousCodeID uint64              `json:"previous_code_id,omitempty"`
}

ContractInfo stores a WASM contract instance

func NewContractInfo

func NewContractInfo(codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, createdAt *AbsoluteTxPosition) ContractInfo

NewContractInfo creates a new instance of a given WASM contract info

func (*ContractInfo) UpdateCodeID added in v0.9.0

func (c *ContractInfo) UpdateCodeID(ctx sdk.Context, newCodeID uint64)

type GenesisState

type GenesisState struct {
	Codes     []Code     `json:"codes"`
	Contracts []Contract `json:"contracts"`
}

GenesisState is the struct representation of the export genesis

type Model

type Model struct {
	// hex-encode key to read it better (this is often ascii)
	Key tmBytes.HexBytes `json:"key"`
	// base64-encode raw value
	Value []byte `json:"val"`
}

Model is a struct that holds a KV pair

type MsgClearAdmin added in v0.9.0

type MsgClearAdmin struct {
	Sender   sdk.AccAddress `json:"sender" yaml:"sender"`
	Contract sdk.AccAddress `json:"contract" yaml:"contract"`
}

func (MsgClearAdmin) GetSignBytes added in v0.9.0

func (msg MsgClearAdmin) GetSignBytes() []byte

func (MsgClearAdmin) GetSigners added in v0.9.0

func (msg MsgClearAdmin) GetSigners() []sdk.AccAddress

func (MsgClearAdmin) Route added in v0.9.0

func (msg MsgClearAdmin) Route() string

func (MsgClearAdmin) Type added in v0.9.0

func (msg MsgClearAdmin) Type() string

func (MsgClearAdmin) ValidateBasic added in v0.9.0

func (msg MsgClearAdmin) ValidateBasic() error

type MsgExecuteContract

type MsgExecuteContract struct {
	Sender    sdk.AccAddress  `json:"sender" yaml:"sender"`
	Contract  sdk.AccAddress  `json:"contract" yaml:"contract"`
	Msg       json.RawMessage `json:"msg" yaml:"msg"`
	SentFunds sdk.Coins       `json:"sent_funds" yaml:"sent_funds"`
}

func (MsgExecuteContract) GetSignBytes

func (msg MsgExecuteContract) GetSignBytes() []byte

func (MsgExecuteContract) GetSigners

func (msg MsgExecuteContract) GetSigners() []sdk.AccAddress

func (MsgExecuteContract) Route

func (msg MsgExecuteContract) Route() string

func (MsgExecuteContract) Type

func (msg MsgExecuteContract) Type() string

func (MsgExecuteContract) ValidateBasic

func (msg MsgExecuteContract) ValidateBasic() error

type MsgInstantiateContract

type MsgInstantiateContract struct {
	Sender sdk.AccAddress `json:"sender" yaml:"sender"`
	// Admin is an optional address that can execute migrations
	Admin     sdk.AccAddress  `json:"admin,omitempty" yaml:"admin"`
	Code      uint64          `json:"code_id" yaml:"code_id"`
	Label     string          `json:"label" yaml:"label"`
	InitMsg   json.RawMessage `json:"init_msg" yaml:"init_msg"`
	InitFunds sdk.Coins       `json:"init_funds" yaml:"init_funds"`
}

func (MsgInstantiateContract) GetSignBytes

func (msg MsgInstantiateContract) GetSignBytes() []byte

func (MsgInstantiateContract) GetSigners

func (msg MsgInstantiateContract) GetSigners() []sdk.AccAddress

func (MsgInstantiateContract) Route

func (msg MsgInstantiateContract) Route() string

func (MsgInstantiateContract) Type

func (msg MsgInstantiateContract) Type() string

func (MsgInstantiateContract) ValidateBasic

func (msg MsgInstantiateContract) ValidateBasic() error

type MsgMigrateContract added in v0.9.0

type MsgMigrateContract struct {
	Sender     sdk.AccAddress  `json:"sender" yaml:"sender"`
	Contract   sdk.AccAddress  `json:"contract" yaml:"contract"`
	Code       uint64          `json:"code_id" yaml:"code_id"`
	MigrateMsg json.RawMessage `json:"msg" yaml:"msg"`
}

func (MsgMigrateContract) GetSignBytes added in v0.9.0

func (msg MsgMigrateContract) GetSignBytes() []byte

func (MsgMigrateContract) GetSigners added in v0.9.0

func (msg MsgMigrateContract) GetSigners() []sdk.AccAddress

func (MsgMigrateContract) Route added in v0.9.0

func (msg MsgMigrateContract) Route() string

func (MsgMigrateContract) Type added in v0.9.0

func (msg MsgMigrateContract) Type() string

func (MsgMigrateContract) ValidateBasic added in v0.9.0

func (msg MsgMigrateContract) ValidateBasic() error

type MsgStoreCode

type MsgStoreCode struct {
	Sender sdk.AccAddress `json:"sender" yaml:"sender"`
	// WASMByteCode can be raw or gzip compressed
	WASMByteCode []byte `json:"wasm_byte_code" yaml:"wasm_byte_code"`
	// Source is a valid absolute HTTPS URI to the contract's source code, optional
	Source string `json:"source" yaml:"source"`
	// Builder is a valid docker image name with tag, optional
	Builder string `json:"builder" yaml:"builder"`
}

func (MsgStoreCode) GetSignBytes

func (msg MsgStoreCode) GetSignBytes() []byte

func (MsgStoreCode) GetSigners

func (msg MsgStoreCode) GetSigners() []sdk.AccAddress

func (MsgStoreCode) Route

func (msg MsgStoreCode) Route() string

func (MsgStoreCode) Type

func (msg MsgStoreCode) Type() string

func (MsgStoreCode) ValidateBasic

func (msg MsgStoreCode) ValidateBasic() error

type MsgUpdateAdmin added in v0.9.0

type MsgUpdateAdmin struct {
	Sender   sdk.AccAddress `json:"sender" yaml:"sender"`
	NewAdmin sdk.AccAddress `json:"new_admin" yaml:"new_admin"`
	Contract sdk.AccAddress `json:"contract" yaml:"contract"`
}

func (MsgUpdateAdmin) GetSignBytes added in v0.9.0

func (msg MsgUpdateAdmin) GetSignBytes() []byte

func (MsgUpdateAdmin) GetSigners added in v0.9.0

func (msg MsgUpdateAdmin) GetSigners() []sdk.AccAddress

func (MsgUpdateAdmin) Route added in v0.9.0

func (msg MsgUpdateAdmin) Route() string

func (MsgUpdateAdmin) Type added in v0.9.0

func (msg MsgUpdateAdmin) Type() string

func (MsgUpdateAdmin) ValidateBasic added in v0.9.0

func (msg MsgUpdateAdmin) ValidateBasic() error

type WasmConfig

type WasmConfig struct {
	SmartQueryGasLimit uint64 `mapstructure:"query_gas_limit"`
	CacheSize          uint64 `mapstructure:"lru_size"`
}

WasmConfig is the extra config required for wasm

func DefaultWasmConfig

func DefaultWasmConfig() WasmConfig

DefaultWasmConfig returns the default settings for WasmConfig

Jump to

Keyboard shortcuts

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