wasm

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 17 Imported by: 0

README

Wasm module

Usage

(Tx) Store code
// can instantiate only store msg sender
storeMsg := types.StoreMsg {
    FilePath: "./wasmcontract.wasm",
    InstantiatePermission: "instantiate-only-sender" //optional. if method is empty string, everybody
}

// can instantiate address
// method and address must be seperated by "."
storeMsg := types.StoreMsg {
    FilePath: "./wasmcontract.wasm",
    InstantiatePermission: "instantiate-only-address.xpla19w2r47nczglwlpfynqe5769cwkwq5fvmzu5pu7" 
}

txbytes, err := xplac.StoreCode(storeMsg).CreateAndSignTx()
res, _ := xplac.Broadcast(txbytes)
(Tx) Instantiate contract
instantiateMsg := types.InstantiateMsg {
    CodeId: "1",
    Amount: "10",
    Label: "Contract instant",
    InitMsg: `{"owner":"xpla19w2r47nczglwlpfynqe5769cwkwq5fvmzu5pu7"}`,
}
txbytes, err := xplac.InstantiateContract(instantiateMsg).CreateAndSignTx()
res, _ := xplac.Broadcast(txbytes)
(Tx) Execute contract
executeMsg := types.ExecuteMsg {
    ContractAddress: "xpla14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s525s0h",
    Amount: "0",
    ExecMsg: `{"execute_method":{"execute_key":"execute_test","execute_value":"xpla19w2r47nczglwlpfynqe5769cwkwq5fvmzu5pu7"}}`,
}
txbytes, err := xplac.ExecuteContract(executeMsg).CreateAndSignTx()
res, _ := xplac.Broadcast(txbytes)
(Tx) Clear contract admin
clearContractAdminMsg := types.ClearContractAdminMsg{
    ContractAddress: "xpla14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s525s0h",
}
txbytes, err := xplac.ClearContractAdmin(clearContractAdminMsg).CreateAndSignTx()
res, _ := xplac.Broadcast(txbytes)
(Tx) Set contract admin
setContractAdminMsg := types.SetContractAdminMsg{
    ContractAddress: "xpla14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s525s0h",
    NewAdmin: "xpla19w2r47nczglwlpfynqe5769cwkwq5fvmzu5pu7",
}

txbytes, err := xplac.SetContractAdmin(setContractAdminMsg).CreateAndSignTx()
res, _ := xplac.Broadcast(txbytes)
(Tx) Migrate
migrateMsg := types.MigrateMsg{
    ContractAddress: "xpla14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s525s0h",
    CodeId: "123",
    MigrateMsg: "json encoded migrate msg",
}

txbytes, err := xplac.Migrate(migrateMsg).CreateAndSignTx()
(Query) contract
queryMsg := types.QueryMsg {
    ContractAddress: "xpla14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s525s0h",
    QueryMsg: `{"query_method":{"query":"query_test"}}`,
}

response, _ := xplac.QueryContract(queryMsg).Query()
(Query) list code
response, _ := xplac.ListCode().Query()
(Query) list contract by code
listContractByCodeMsg := types.ListContractByCodeMsg {
    CodeId: "1",
}

response, err := xplac.ListContractByCode(listContractByCodeMsg).Query()
(Query) Download contract wasm file
downloadMsg := types.DownloadMsg{
    CodeId: "1",
    DownloadFileName: "test",
}

response, err := xplac.Download(downloadMsg).Query()
(Query) code info
codeInfoMsg := types.CodeInfoMsg{
    CodeId: "1",
}

response, err := xplac.CodeInfo(codeInfoMsg).Query()
(Query) Contract info
contractInfoMsg := types.ContractInfoMsg {
    ContractAddress: "xpla14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s525s0h",
}

response, err := xplac.ContractInfo(contractInfoMsg).Query()
(Query) all contract state
contractStateAllMsg := types.ContractStateAllMsg{
    ContractAddress: "xpla14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s525s0h",
}

response, err := xplac.ContractStateAll(contractStateAllMsg).Query()
(Query) contract history
contractHistoryMsg := types.ContractHistoryMsg {
    ContractAddress: "xpla14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s525s0h",
}

response, err := xplac.ContractHistory(contractHistoryMsg).Query()
(Query) pinned
response, err := xplac.Pinned().Query()
(Query) Lib wasmvm version
response, err := xplac.LibwasmvmVersion().Query()

Documentation

Index

Constants

View Source
const (
	WasmModule                    = "wasm"
	WasmStoreMsgType              = "store-code"
	WasmInstantiateMsgType        = "instantiate-contract"
	WasmExecuteMsgType            = "execute-contract"
	WasmClearContractAdminMsgType = "clear-contract-admin"
	WasmSetContractAdminMsgType   = "set-contract-admin"
	WasmMigrateMsgType            = "migrate"
	WasmQueryContractMsgType      = "query-contract"
	WasmListCodeMsgType           = "list-code"
	WasmListContractByCodeMsgType = "list-contract-by-code"
	WasmDownloadMsgType           = "download"
	WasmCodeInfoMsgType           = "code-info"
	WasmContractInfoMsgType       = "contract-info"
	WasmContractStateAllMsgType   = "contract-state-all"
	WasmContractHistoryMsgType    = "contract-history"
	WasmPinnedMsgType             = "pinned"
	WasmLibwasmvmVersionMsgType   = "libwasmvm-version"
)

Variables

This section is empty.

Functions

func AsciiDecodeString

func AsciiDecodeString(s string) ([]byte, error)

func MakeClearContractAdminMsg

func MakeClearContractAdminMsg(clearContractAdminMsg types.ClearContractAdminMsg, sender sdk.AccAddress) (wasmtypes.MsgClearAdmin, error)

(Tx) make msg - clear contract admin

func MakeCodeInfoMsg

func MakeCodeInfoMsg(codeInfoMsg types.CodeInfoMsg) (wasmtypes.QueryCodeRequest, error)

(Query) make msg - code info

func MakeContractHistoryMsg

func MakeContractHistoryMsg(contractHistoryMsg types.ContractHistoryMsg) (wasmtypes.QueryContractHistoryRequest, error)

(Query) make msg - history

func MakeContractInfoMsg

func MakeContractInfoMsg(contractInfoMsg types.ContractInfoMsg) (wasmtypes.QueryContractInfoRequest, error)

(Query) make msg - contract info

func MakeContractStateAllMsg

func MakeContractStateAllMsg(contractStateAllMsg types.ContractStateAllMsg) (wasmtypes.QueryAllContractStateRequest, error)

(Query) make msg - contract state all

func MakeDownloadMsg

func MakeDownloadMsg(downloadMsg types.DownloadMsg) ([]interface{}, error)

(Query) make msg - download

func MakeExecuteMsg

func MakeExecuteMsg(executeMsg types.ExecuteMsg, addr sdk.AccAddress) (wasmtypes.MsgExecuteContract, error)

(Tx) make msg - execute

func MakeInstantiateMsg

func MakeInstantiateMsg(instantiateMsg types.InstantiateMsg, addr sdk.AccAddress) (wasmtypes.MsgInstantiateContract, error)

(Tx) make msg - instantiate

func MakeLibwasmvmVersionMsg

func MakeLibwasmvmVersionMsg() (string, error)

(Query) make msg - libwasmvm version

func MakeListContractByCodeMsg

func MakeListContractByCodeMsg(listContractByCodeMsg types.ListContractByCodeMsg) (wasmtypes.QueryContractsByCodeRequest, error)

(Query) make msg - list contract by code

func MakeListcodeMsg

func MakeListcodeMsg() (wasmtypes.QueryCodesRequest, error)

(Query) make msg - list code

func MakeMigrateMsg

func MakeMigrateMsg(migrateMsg types.MigrateMsg, sender sdk.AccAddress) (wasmtypes.MsgMigrateContract, error)

(Tx) make msg - migrate

func MakePinnedMsg

func MakePinnedMsg() (wasmtypes.QueryPinnedCodesRequest, error)

(Query) make msg - pinned

func MakeQueryMsg

(Query) make msg - query contract

func MakeSetContractAdmintMsg

func MakeSetContractAdmintMsg(setContractAdminMsg types.SetContractAdminMsg, sender sdk.AccAddress) (wasmtypes.MsgUpdateAdmin, error)

(Tx) make msg - set contract admin

func MakeStoreCodeMsg

func MakeStoreCodeMsg(storeMsg types.StoreMsg, addr sdk.AccAddress) (wasmtypes.MsgStoreCode, error)

(Tx) make msg - store code

func NewCoreModule added in v0.1.2

func NewCoreModule() core.CoreModule

func QueryWasm

func QueryWasm(i core.QueryClient) (string, error)

Query client for wasm module.

Types

type ArgumentDecoder

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

func NewArgDecoder

func NewArgDecoder(def func(string) ([]byte, error)) *ArgumentDecoder

Make new query decoder.

func (*ArgumentDecoder) DecodeString

func (a *ArgumentDecoder) DecodeString(s string) ([]byte, error)

type WasmExternal added in v0.1.2

type WasmExternal struct {
	Xplac provider.XplaClient
}

func NewWasmExternal added in v0.1.2

func NewWasmExternal(xplac provider.XplaClient) (e WasmExternal)

func (WasmExternal) ClearContractAdmin added in v0.1.2

func (e WasmExternal) ClearContractAdmin(clearContractAdminMsg types.ClearContractAdminMsg) provider.XplaClient

Clears admin for a contract to prevent further migrations.

func (WasmExternal) CodeInfo added in v0.1.2

func (e WasmExternal) CodeInfo(codeInfoMsg types.CodeInfoMsg) provider.XplaClient

Prints out metadata of a code ID.

func (WasmExternal) ContractHistory added in v0.1.2

func (e WasmExternal) ContractHistory(contractHistoryMsg types.ContractHistoryMsg) provider.XplaClient

Prints out the code history for a contract given its address.

func (WasmExternal) ContractInfo added in v0.1.2

func (e WasmExternal) ContractInfo(contractInfoMsg types.ContractInfoMsg) provider.XplaClient

Prints out metadata of a contract given its address.

func (WasmExternal) ContractStateAll added in v0.1.2

func (e WasmExternal) ContractStateAll(contractStateAllMsg types.ContractStateAllMsg) provider.XplaClient

Prints out all internal state of a contract given its address.

func (WasmExternal) Download added in v0.1.2

func (e WasmExternal) Download(downloadMsg types.DownloadMsg) provider.XplaClient

Downloads wasm bytecode for given code ID.

func (WasmExternal) ExecuteContract added in v0.1.2

func (e WasmExternal) ExecuteContract(executeMsg types.ExecuteMsg) provider.XplaClient

Execute a wasm contract.

func (WasmExternal) InstantiateContract added in v0.1.2

func (e WasmExternal) InstantiateContract(instantiageMsg types.InstantiateMsg) provider.XplaClient

Instantiate a wasm contract.

func (WasmExternal) LibwasmvmVersion added in v0.1.2

func (e WasmExternal) LibwasmvmVersion() provider.XplaClient

Get libwasmvm version.

func (WasmExternal) ListCode added in v0.1.2

func (e WasmExternal) ListCode() provider.XplaClient

Query list all wasm bytecode on the chain.

func (WasmExternal) ListContractByCode added in v0.1.2

func (e WasmExternal) ListContractByCode(listContractByCodeMsg types.ListContractByCodeMsg) provider.XplaClient

Query list wasm all bytecode on the chain for given code ID.

func (WasmExternal) Migrate added in v0.1.2

func (e WasmExternal) Migrate(migrateMsg types.MigrateMsg) provider.XplaClient

Migrate a wasm contract to a new code version.

func (WasmExternal) Pinned added in v0.1.2

func (e WasmExternal) Pinned() provider.XplaClient

Query list all pinned code IDs.

func (WasmExternal) QueryContract added in v0.1.2

func (e WasmExternal) QueryContract(queryMsg types.QueryMsg) provider.XplaClient

Calls contract with given address with query data and prints the returned result.

func (WasmExternal) SetContractAdmin added in v0.1.2

func (e WasmExternal) SetContractAdmin(setContractAdminMsg types.SetContractAdminMsg) provider.XplaClient

Set new admin for a contract.

func (WasmExternal) StoreCode added in v0.1.2

func (e WasmExternal) StoreCode(storeMsg types.StoreMsg) provider.XplaClient

Upload a wasm binary.

Jump to

Keyboard shortcuts

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