types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

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

	// 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")
)

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 CosmosResult

func CosmosResult(wasmResult wasmTypes.Result, contractAddr sdk.AccAddress) sdk.Result

CosmosResult converts from a Wasm Result type

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 NewParams

func NewParams(ctx sdk.Context, creator sdk.AccAddress, deposit sdk.Coins, contractAcct auth.Account) wasmTypes.Env

NewParams initializes params for a contract instance

func NewWasmCoins

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

NewWasmCoins translates between Cosmos SDK coins and Wasm coins

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers the account types and interface

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 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"`
	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 *CreatedAt `json:"created,omitempty"`
}

ContractInfo stores a WASM contract instance

func NewContractInfo

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

NewContractInfo creates a new instance of a given WASM contract info

type CreatedAt

type CreatedAt 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
}

CreatedAt can be used to sort contracts

func NewCreatedAt

func NewCreatedAt(ctx sdk.Context) *CreatedAt

NewCreatedAt gets a timestamp from the context

func (*CreatedAt) LessThan

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

LessThan can be used to sort

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 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"`
	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 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 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