First run-through documented, along with TODOs

This commit is contained in:
Ethan Frey
2019-11-22 19:00:20 +01:00
parent 35aab0ee65
commit 5f304e335c
3 changed files with 62 additions and 7 deletions

View File

@@ -59,6 +59,55 @@ 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: add id to json output
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 fred -a)\"}"
wasmcli tx wasm create validator 1 "$INIT" --amount=50000stake
wasmcli query wasm list-contracts
CONTRACT=cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5
# TODO: remove prefix store - make init_msg string
wasmcli query wasm contract $CONTRACT
wasmcli query wasm contract-state $CONTRACT
wasmcli query account $CONTRACT
# execute fails if wrong person
# TODO: make exec - fix logic
wasmcli tx wasm send validator $CONTRACT "{}"
wasmcli query account $(wasmcli keys show bob -a)
wasmcli tx wasm send fred $CONTRACT "{}"
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):

View File

@@ -50,7 +50,7 @@ func GetCmdListCode(cdc *codec.Codec) *cobra.Command {
if err != nil {
return err
}
fmt.Println(res)
fmt.Println(string(res))
return nil
},
}
@@ -107,7 +107,7 @@ func GetCmdListContracts(cdc *codec.Codec) *cobra.Command {
if err != nil {
return err
}
fmt.Println(res)
fmt.Println(string(res))
return nil
},
}
@@ -133,7 +133,7 @@ func GetCmdGetContractInfo(cdc *codec.Codec) *cobra.Command {
if err != nil {
return err
}
fmt.Println(res)
fmt.Println(string(res))
return nil
},
}
@@ -159,7 +159,7 @@ func GetCmdGetContractState(cdc *codec.Codec) *cobra.Command {
if err != nil {
return err
}
fmt.Println(res)
fmt.Println(string(res))
return nil
},
}

View File

@@ -18,12 +18,18 @@ func NewHandler(k Keeper) sdk.Handler {
switch msg := msg.(type) {
case MsgStoreCode:
return handleStoreCode(ctx, k, &msg)
case *MsgStoreCode:
return handleStoreCode(ctx, k, msg)
case MsgInstantiateContract:
return handleInstantiate(ctx, k, &msg)
case *MsgInstantiateContract:
return handleInstantiate(ctx, k, msg)
case MsgExecuteContract:
return handleExecute(ctx, k, &msg)
case *MsgExecuteContract:
return handleExecute(ctx, k, msg)
default:
@@ -33,7 +39,7 @@ func NewHandler(k Keeper) sdk.Handler {
}
}
func handleStoreCode(ctx sdk.Context, k Keeper, msg MsgStoreCode) sdk.Result {
func handleStoreCode(ctx sdk.Context, k Keeper, msg *MsgStoreCode) sdk.Result {
codeID, err := k.Create(ctx, msg.Sender, msg.WASMByteCode)
if err != nil {
return err.Result()
@@ -55,7 +61,7 @@ func handleStoreCode(ctx sdk.Context, k Keeper, msg MsgStoreCode) sdk.Result {
}
}
func handleInstantiate(ctx sdk.Context, k Keeper, msg MsgInstantiateContract) sdk.Result {
func handleInstantiate(ctx sdk.Context, k Keeper, msg *MsgInstantiateContract) sdk.Result {
contractAddr, err := k.Instantiate(ctx, msg.Sender, msg.Code, msg.InitMsg, msg.InitFunds)
if err != nil {
return err.Result()
@@ -78,7 +84,7 @@ func handleInstantiate(ctx sdk.Context, k Keeper, msg MsgInstantiateContract) sd
}
}
func handleExecute(ctx sdk.Context, k Keeper, msg MsgExecuteContract) sdk.Result {
func handleExecute(ctx sdk.Context, k Keeper, msg *MsgExecuteContract) sdk.Result {
res, err := k.Execute(ctx, msg.Contract, msg.Sender, msg.SentFunds, msg.Msg)
if err != nil {
return err.Result()