Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kefan wasm #157

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/okex/exchain-go-sdk/module/feesplit"
"github.com/okex/exchain-go-sdk/module/ibc"
"github.com/okex/exchain-go-sdk/module/wasm"
ibcTypes "github.com/okex/exchain/libs/ibc-go/modules/apps/transfer/types"
feesplitTypes "github.com/okex/exchain/x/feesplit/types"

Expand Down Expand Up @@ -35,6 +36,7 @@ import (
gosdktypes "github.com/okex/exchain-go-sdk/types"
"github.com/okex/exchain/libs/cosmos-sdk/codec"
farmtypes "github.com/okex/exchain/x/farm/types"
wasmTypes "github.com/okex/exchain/x/wasm/types"
)

// Client - structure of the main client of ExChain GoSDK
Expand Down Expand Up @@ -68,6 +70,7 @@ func NewClient(config gosdktypes.ClientConfig) Client {
token.NewTokenClient(pBaseClient),
tendermint.NewTendermintClient(pBaseClient),
ibc.NewIbcClient(pBaseClient),
wasm.NewWasmClient(pBaseClient),
feesplit.NewfeesplitClient(pBaseClient),
)

Expand Down Expand Up @@ -135,6 +138,9 @@ func (cli *Client) Ibc() exposed.Ibc {
return cli.modules[ibcTypes.ModuleName].(exposed.Ibc)
}

func (cli *Client) Wasm() exposed.Wasm {
return cli.modules[wasmTypes.ModuleName].(exposed.Wasm)
}
func (cli *Client) Feesplit() exposed.Feesplit {
return cli.modules[feesplitTypes.ModuleName].(exposed.Feesplit)
}
68 changes: 68 additions & 0 deletions exposed/wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package exposed

import (
"github.com/okex/exchain/libs/cosmos-sdk/crypto/keys"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/libs/cosmos-sdk/types/query"
"github.com/okex/exchain/x/wasm/types"
)
import gosdktypes "github.com/okex/exchain-go-sdk/types"

// Wasm shows the expected behavior for inner wasm client
type Wasm interface {
gosdktypes.Module
wasmTx
wasmQuery
}

type wasmTx interface {
// StoreCode upload a wasm binary to the chain
StoreCode(fromInfo keys.Info, passWd string, accNum, seqNum uint64, memo string, wasmFilePath string, onlyAddr string, everybody, nobody bool) (int, error)

// InstantiateContract instantiate a wasm contract by given the codeID
InstantiateContract(fromInfo keys.Info, passWd string, accNum, seqNum uint64, memo string, codeID uint64, initMsg string, amount string, label string, adminAddr string, noAdmin bool) (string, error)

// ExecuteContract execute a command on a wasm contract
ExecuteContract(fromInfo keys.Info, passWd string, accNum, seqNum uint64, memo string, contractAddr string, execMsg string, amount string) (*sdk.TxResponse, error)

// MigrateContract migrate a wasm contract to a new code version
MigrateContract(fromInfo keys.Info, passWd string, accNum, seqNum uint64, memo string, codeID uint64, contractAddr string, migrateMsg string) (*sdk.TxResponse, error)

// UpdateContractAdmin set new admin for a contract
UpdateContractAdmin(fromInfo keys.Info, passWd string, accNum, seqNum uint64, memo string, contractAddr string, adminAddr string) (*sdk.TxResponse, error)

// ClearContractAdmin clears admin for a contract to prevent further migrations
ClearContractAdmin(fromInfo keys.Info, passWd string, accNum, seqNum uint64, memo string, contractAddr string) (*sdk.TxResponse, error)
}

type wasmQuery interface {
// QueryListCode query all wasm bytecode on the chain
QueryListCode(pageReq *query.PageRequest) (*types.QueryCodesResponse, error)

// QueryListContract query all bytecode on the chain for given code id
QueryListContract(codeID uint64, pageReq *query.PageRequest) (*types.QueryContractsByCodeResponse, error)

// QueryCode query wasm bytecode for given code id
QueryCode(codeID uint64) (*types.QueryCodeResponse, error)

// QueryCodeInfo query metadata of code for given code id
QueryCodeInfo(codeID uint64) (*types.CodeInfoResponse, error)

// QueryContractInfo query metadata of a contract given its address
QueryContractInfo(address string) (*types.QueryContractInfoResponse, error)

// QueryContractHistory query the code history for a contract given its address
QueryContractHistory(address string, pageReq *query.PageRequest) (*types.QueryContractHistoryResponse, error)

// QueryContractStateAll query all internal state of a contract given its address
QueryContractStateAll(address string, pageReq *query.PageRequest) (*types.QueryAllContractStateResponse, error)

// QueryContractStateRaw query internal state for key of a contract given its address
QueryContractStateRaw(address string, queryData string) (*types.QueryRawContractStateResponse, error)

// QueryContractStateSmart query contract with given address with query data
QueryContractStateSmart(address string, queryData string) (*types.QuerySmartContractStateResponse, error)

// QueryListPinnedCode query all pinned code ids
QueryListPinnedCode(pageReq *query.PageRequest) (*types.QueryPinnedCodesResponse, error)
}
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ require (
github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d
github.com/ethereum/go-ethereum v1.10.8
github.com/golang/mock v1.6.0
github.com/kr/pretty v0.2.1 // indirect
github.com/minio/highwayhash v1.0.1 // indirect
github.com/okex/exchain v1.6.4
github.com/prometheus/client_golang v1.8.0 // indirect
github.com/okex/exchain v1.6.9-0.20230403021821-2ab2d0e4ec32
github.com/stretchr/testify v1.8.0
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect
)

replace (
Expand Down
Loading