Skip to content

Commit

Permalink
Merge pull request cosmos#346 from CosmWasm/genesis_contract_msg_326
Browse files Browse the repository at this point in the history
Improve Contract initialization in genesis and tooling
  • Loading branch information
ethanfrey authored Jan 7, 2021
2 parents 5cc3231 + bac2339 commit 321491e
Show file tree
Hide file tree
Showing 25 changed files with 2,219 additions and 187 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


**Features:**
- Make it easy to initialize contracts in genesis file with new CLI commands[\#326](https://github.com/CosmWasm/wasmd/issues/326)
- Upgrade to WasmVM v0.13.0 [\#358](https://github.com/CosmWasm/wasmd/pull/358)
- Upgrade to cosmos-sdk v0.40.0-rc6 [\#354](https://github.com/CosmWasm/wasmd/pull/354)
- Upgrade to cosmos-sdk v0.40.0-rc5 [\#344](https://github.com/CosmWasm/wasmd/issues/344)
Expand Down
6 changes: 4 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper),
staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.bankKeeper),
upgrade.NewAppModule(app.upgradeKeeper),
wasm.NewAppModule(&app.wasmKeeper),
wasm.NewAppModule(&app.wasmKeeper, app.stakingKeeper),
evidence.NewAppModule(app.evidenceKeeper),
ibc.NewAppModule(app.ibcKeeper),
params.NewAppModule(app.paramsKeeper),
Expand All @@ -433,6 +433,8 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
// NOTE: Capability module must occur first so that it can initialize any capabilities
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
// wasm module should be a the end as it can call other modules functionality direct or via message dispatching during
// genesis phase. For example bank transfer, auth account check, staking, ...
app.mm.SetOrderInitGenesis(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
Expand Down Expand Up @@ -461,7 +463,7 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper),
slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper),
params.NewAppModule(app.paramsKeeper),
wasm.NewAppModule(&app.wasmKeeper),
wasm.NewAppModule(&app.wasmKeeper, app.stakingKeeper),
evidence.NewAppModule(app.evidenceKeeper),
ibc.NewAppModule(app.ibcKeeper),
transferModule,
Expand Down
26 changes: 26 additions & 0 deletions cmd/wasmd/genwasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
)

func AddGenesisWasmMsgCmd(defaultNodeHome string) *cobra.Command {
txCmd := &cobra.Command{
Use: "add-wasm-genesis-message",
Short: "Wasm genesis subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
txCmd.AddCommand(
wasmcli.GenesisStoreCodeCmd(defaultNodeHome),
wasmcli.GenesisInstantiateContractCmd(defaultNodeHome),
wasmcli.GenesisExecuteContractCmd(defaultNodeHome),
wasmcli.GenesisListContractsCmd(defaultNodeHome),
wasmcli.GenesisListCodesCmd(defaultNodeHome),
)
return txCmd

}
1 change: 1 addition & 0 deletions cmd/wasmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
AddGenesisWasmMsgCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
// testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
Expand Down
28 changes: 28 additions & 0 deletions contrib/local/00-genesis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
BASE_ACCOUNT=$(wasmd keys show validator -a)

echo "-----------------------"
echo "## Genesis CosmWasm contract"
wasmd add-wasm-genesis-message store "$DIR/../../x/wasm/internal/keeper/testdata/hackatom.wasm" --instantiate-everybody true --builder=foo/bar:latest --run-as validator

echo "-----------------------"
echo "## Genesis CosmWasm instance"
INIT="{\"verifier\":\"$(wasmd keys show validator -a)\", \"beneficiary\":\"$(wasmd keys show fred -a)\"}"
wasmd add-wasm-genesis-message instantiate-contract 1 "$INIT" --run-as validator --label=foobar --amount=100ustake --admin $BASE_ACCOUNT

echo "-----------------------"
echo "## Genesis CosmWasm execute"
FIRST_CONTRACT_ADDR=wasm18vd8fpwxzck93qlwghaj6arh4p7c5n89k7fvsl
MSG='{"release":{}}'
wasmd add-wasm-genesis-message execute $FIRST_CONTRACT_ADDR "$MSG" --run-as validator --amount=1ustake

echo "-----------------------"
echo "## List Genesis CosmWasm codes"
wasmd add-wasm-genesis-message list-codes

echo "-----------------------"
echo "## List Genesis CosmWasm contracts"
wasmd add-wasm-genesis-message list-contracts
20 changes: 20 additions & 0 deletions doc/proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Code](#cosmwasm.wasm.v1beta1.Code)
- [Contract](#cosmwasm.wasm.v1beta1.Contract)
- [GenesisState](#cosmwasm.wasm.v1beta1.GenesisState)
- [GenesisState.GenMsgs](#cosmwasm.wasm.v1beta1.GenesisState.GenMsgs)
- [Sequence](#cosmwasm.wasm.v1beta1.Sequence)

- [x/wasm/internal/types/msg.proto](#x/wasm/internal/types/msg.proto)
Expand Down Expand Up @@ -116,6 +117,25 @@ GenesisState - genesis state of x/wasm
| codes | [Code](#cosmwasm.wasm.v1beta1.Code) | repeated | |
| contracts | [Contract](#cosmwasm.wasm.v1beta1.Contract) | repeated | |
| sequences | [Sequence](#cosmwasm.wasm.v1beta1.Sequence) | repeated | |
| gen_msgs | [GenesisState.GenMsgs](#cosmwasm.wasm.v1beta1.GenesisState.GenMsgs) | repeated | |






<a name="cosmwasm.wasm.v1beta1.GenesisState.GenMsgs"></a>

### GenesisState.GenMsgs
GenMsgs define the messages that can be executed during genesis phase.
The intention is to have more human readable data that is auditable.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| store_code | [MsgStoreCode](#cosmwasm.wasm.v1beta1.MsgStoreCode) | | |
| instantiate_contract | [MsgInstantiateContract](#cosmwasm.wasm.v1beta1.MsgInstantiateContract) | | |
| execute_contract | [MsgExecuteContract](#cosmwasm.wasm.v1beta1.MsgExecuteContract) | | |



Expand Down
Loading

0 comments on commit 321491e

Please sign in to comment.