Skip to content

Commit

Permalink
Merge pull request #2 from cosmwasm/import-wasm-module
Browse files Browse the repository at this point in the history
Integrate wasm module
  • Loading branch information
ethanfrey authored Nov 22, 2019
2 parents 801630d + a3e7c30 commit 39a2b56
Show file tree
Hide file tree
Showing 22 changed files with 2,123 additions and 3 deletions.
20 changes: 18 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package app
import (
"io"
"os"
"path/filepath"

"github.com/spf13/viper"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/cli"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
Expand All @@ -29,6 +33,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"

"github.com/cosmwasm/wasmd/x/wasm"
)

const appName = "WasmApp"
Expand All @@ -52,6 +58,7 @@ var (
distr.AppModuleBasic{},
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distr.ProposalHandler),
params.AppModuleBasic{},
wasm.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
supply.AppModuleBasic{},
Expand Down Expand Up @@ -106,6 +113,7 @@ type WasmApp struct {
crisisKeeper crisis.Keeper
paramsKeeper params.Keeper
evidenceKeeper *evidence.Keeper
wasmKeeper wasm.Keeper

// the module manager
mm *module.Manager
Expand All @@ -129,7 +137,7 @@ func NewWasmApp(
keys := sdk.NewKVStoreKeys(
bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey,
mint.StoreKey, distr.StoreKey, slashing.StoreKey, gov.StoreKey,
params.StoreKey, evidence.StoreKey,
params.StoreKey, evidence.StoreKey, wasm.StoreKey,
)
tKeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)

Expand Down Expand Up @@ -168,6 +176,13 @@ func NewWasmApp(
)
app.crisisKeeper = crisis.NewKeeper(crisisSubspace, invCheckPeriod, app.supplyKeeper, auth.FeeCollectorName)

// just re-use the full router - do we want to limit this more?
var wasmRouter = bApp.Router()
// better way to get this dir???
homeDir := viper.GetString(cli.HomeFlag)
wasmDir := filepath.Join(homeDir, "wasm")
app.wasmKeeper = wasm.NewKeeper(app.cdc, keys[wasm.StoreKey], app.accountKeeper, app.bankKeeper, wasmRouter, wasmDir)

// create evidence keeper with evidence router
app.evidenceKeeper = evidence.NewKeeper(
app.cdc, keys[evidence.StoreKey], evidenceSubspace, evidence.DefaultCodespace,
Expand Down Expand Up @@ -206,6 +221,7 @@ func NewWasmApp(
slashing.NewAppModule(app.slashingKeeper, app.stakingKeeper),
staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper),
evidence.NewAppModule(*app.evidenceKeeper),
wasm.NewAppModule(app.wasmKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -220,7 +236,7 @@ func NewWasmApp(
app.mm.SetOrderInitGenesis(
distr.ModuleName, staking.ModuleName, auth.ModuleName, bank.ModuleName,
slashing.ModuleName, gov.ModuleName, mint.ModuleName, supply.ModuleName,
crisis.ModuleName, genutil.ModuleName, evidence.ModuleName,
crisis.ModuleName, genutil.ModuleName, evidence.ModuleName, wasm.ModuleName,
)

app.mm.RegisterInvariants(&app.crisisKeeper)
Expand Down
2 changes: 1 addition & 1 deletion cmd/wasmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func main() {
rootCmd.AddCommand(genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics))
rootCmd.AddCommand(AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome))
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))
rootCmd.AddCommand(testnetCmd(ctx, cdc, app.ModuleBasics, auth.GenesisAccountIterator{}))
// rootCmd.AddCommand(testnetCmd(ctx, cdc, app.ModuleBasics, auth.GenesisAccountIterator{}))
rootCmd.AddCommand(replayCmd())
rootCmd.AddCommand(debug.Cmd(cdc))

Expand Down
51 changes: 51 additions & 0 deletions docs/deploy-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,57 @@ wasmd start

This setup puts all the data for `wasmd` in `~/.wasmd`. You can examine the genesis file you created at `~/.wasmd/config/genesis.json`. With this configuration `wasmcli` is also ready to use and has an account with tokens (both staking and custom).

### Set up client

```bash
wasmcli config chain-id testing
wasmcli config trust-node true
wasmcli config node tcp://localhost:26657
wasmcli config output json
wasmcli config indent true

# verify initial setup
wasmcli query account $(wasmcli keys show validator -a)
wasmcli query wasm list-code
wasmcli query wasm list-contracts

# upload a contract and verify
cp $HOME/go/src/github.com/cosmwasm/wasmd/x/wasm/internal/keeper/testdata/contract.wasm upload.wasm
wasmcli tx wasm store validator upload.wasm --gas 800000
# TODO: stops after one hit
wasmcli query wasm list-code
wasmcli query wasm code 1 download.wasm
sha256sum upload.wasm download.wasm

# prepare more accounts
wasmcli keys add fred
wasmcli keys add bob
wasmcli tx send $(wasmcli keys show validator -a) $(wasmcli keys show fred -a) 98765stake
wasmcli query account $(wasmcli keys show fred -a)
wasmcli query account $(wasmcli keys show bob -a)

# instantiate contract and verify
INIT="{\"verifier\":\"$(wasmcli keys show fred -a)\", \"beneficiary\":\"$(wasmcli keys show bob -a)\"}"
wasmcli tx wasm instantiate validator 1 "$INIT" --amount=50000stake
sleep 3
wasmcli query wasm list-contracts
CONTRACT=cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5
wasmcli query wasm contract $CONTRACT
wasmcli query wasm contract-state $CONTRACT
wasmcli query account $CONTRACT

# execute fails if wrong person
wasmcli tx wasm execute validator $CONTRACT "{}"
sleep 3
wasmcli query tx <hash from above>
wasmcli query account $(wasmcli keys show bob -a)

wasmcli tx wasm execute fred $CONTRACT "{}"
sleep 3
wasmcli query account $(wasmcli keys show bob -a)
wasmcli query account $CONTRACT
```

## Multi-node, Local, Automated Testnet

From the [networks/local directory](https://github.com/cosmwasm/wasmd/tree/master/networks/local):
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ go 1.13

require (
github.com/btcsuite/btcd v0.0.0-20190807005414-4063feeff79a // indirect
github.com/confio/go-cosmwasm v0.3.3
github.com/cosmos/cosmos-sdk v0.34.4-0.20191114141721-d4c831e63ad3
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
github.com/golang/mock v1.3.1 // indirect
github.com/gorilla/mux v1.7.3
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/otiai10/copy v1.0.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtE
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/confio/go-cosmwasm v0.3.3 h1:kW7BFfUWjMJ0bLbircMkTWQaYjKkryuyDdfPr606VA0=
github.com/confio/go-cosmwasm v0.3.3/go.mod h1:pHipRby+f3cv97QPLELkzOAlNs/s87uDyhc+SnMn7L4=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
Expand Down
74 changes: 74 additions & 0 deletions x/wasm/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// nolint
package wasm

import (
"github.com/cosmwasm/wasmd/x/wasm/internal/keeper"
"github.com/cosmwasm/wasmd/x/wasm/internal/types"
)

// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmwasm/wasmd/x/wasm/internal/keeper/
// ALIASGEN: github.com/cosmwasm/wasmd/x/wasm/internal/types/

const (
GasMultiplier = keeper.GasMultiplier
MaxGas = keeper.MaxGas
QueryListContracts = keeper.QueryListContracts
QueryGetContract = keeper.QueryGetContract
QueryGetContractState = keeper.QueryGetContractState
QueryGetCode = keeper.QueryGetCode
QueryListCode = keeper.QueryListCode
DefaultCodespace = types.DefaultCodespace
CodeCreatedFailed = types.CodeCreatedFailed
CodeAccountExists = types.CodeAccountExists
CodeInstantiateFailed = types.CodeInstantiateFailed
CodeExecuteFailed = types.CodeExecuteFailed
CodeGasLimit = types.CodeGasLimit
ModuleName = types.ModuleName
StoreKey = types.StoreKey
TStoreKey = types.TStoreKey
QuerierRoute = types.QuerierRoute
RouterKey = types.RouterKey
MaxWasmSize = types.MaxWasmSize
)

var (
// functions aliases
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
MakeTestCodec = keeper.MakeTestCodec
CreateTestInput = keeper.CreateTestInput
RegisterCodec = types.RegisterCodec
ErrCreateFailed = types.ErrCreateFailed
ErrAccountExists = types.ErrAccountExists
ErrInstantiateFailed = types.ErrInstantiateFailed
ErrExecuteFailed = types.ErrExecuteFailed
ErrGasLimit = types.ErrGasLimit
GetCodeKey = types.GetCodeKey
GetContractAddressKey = types.GetContractAddressKey
GetContractStorePrefixKey = types.GetContractStorePrefixKey
NewCodeInfo = types.NewCodeInfo
NewParams = types.NewParams
NewWasmCoins = types.NewWasmCoins
NewContract = types.NewContract
CosmosResult = types.CosmosResult

// variable aliases
ModuleCdc = types.ModuleCdc
KeyLastCodeID = types.KeyLastCodeID
KeyLastInstanceID = types.KeyLastInstanceID
CodeKeyPrefix = types.CodeKeyPrefix
ContractKeyPrefix = types.ContractKeyPrefix
ContractStorePrefix = types.ContractStorePrefix
)

type (
Keeper = keeper.Keeper
GetCodeResponse = keeper.GetCodeResponse
MsgStoreCode = types.MsgStoreCode
MsgInstantiateContract = types.MsgInstantiateContract
MsgExecuteContract = types.MsgExecuteContract
CodeInfo = types.CodeInfo
Contract = types.Contract
)
Loading

0 comments on commit 39a2b56

Please sign in to comment.