Skip to content

Commit

Permalink
Merge pull request #249 from CosmWasm/0.9.1_to_cosmos-stargate_cli_fixes
Browse files Browse the repository at this point in the history
0.9.1 to cosmos stargate cli fixes
  • Loading branch information
alpe committed Aug 12, 2020
2 parents e535077 + c91b526 commit 6b5133e
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 36 deletions.
4 changes: 1 addition & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,8 @@ func NewWasmApp(
)

// Create IBC Keeper
// TODO: remove amino codec dependency once Tendermint version is upgraded with
// protobuf changes
app.ibcKeeper = ibckeeper.NewKeeper(
app.cdc, appCodec, keys[ibchost.StoreKey], app.stakingKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.stakingKeeper, scopedIBCKeeper,
)

// Create Transfer Keepers
Expand Down
38 changes: 30 additions & 8 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
package app

import (
"github.com/CosmWasm/wasmd/x/wasm"
"github.com/cosmos/cosmos-sdk/simapp"
simparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

func MakeEncodingConfig() simparams.EncodingConfig {
encodingConfig := simapp.MakeEncodingConfig() // todo: this is the simapp !!!
wasm.RegisterCodec(encodingConfig.Amino)
wasm.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Marshaler
TxConfig client.TxConfig
Amino *codec.Codec
}

func MakeEncodingConfig() EncodingConfig {
amino := codec.New()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewHybridCodec(amino, interfaceRegistry)
txGen := tx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), std.DefaultPublicKeyCodec{}, tx.DefaultSignModes)

std.RegisterCodec(amino)
std.RegisterInterfaces(interfaceRegistry)
ModuleBasics.RegisterCodec(amino)
ModuleBasics.RegisterInterfaces(interfaceRegistry)
return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txGen,
Amino: amino,
}
}
18 changes: 14 additions & 4 deletions cmd/wasmcli/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"os"

Expand Down Expand Up @@ -43,7 +44,7 @@ func main() {
WithInput(os.Stdin).
WithAccountRetriever(authtypes.NewAccountRetriever(encodingConfig.Marshaler)).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(app.DefaultNodeHome)
WithHomeDir(app.DefaultCLIHome)

rootCmd := &cobra.Command{
Use: "wasmcli",
Expand All @@ -70,10 +71,19 @@ func main() {
cli.NewCompletionCmd(rootCmd, true),
)

// Add flags and prefix all env exposed with WM
executor := cli.PrepareMainCmd(rootCmd, "WM", app.DefaultCLIHome)
// Create and set a client.Context on the command's Context. During the pre-run
// of the root command, a default initialized client.Context is provided to
// seed child command execution with values such as AccountRetriver, Keyring,
// and a Tendermint RPC. This requires the use of a pointer reference when
// getting and setting the client.Context. Ideally, we utilize
// https://github.com/spf13/cobra/pull/1118.
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{})
ctx = context.WithValue(ctx, server.ServerContextKey, server.NewDefaultContext())

executor := cli.PrepareBaseCmd(rootCmd, "WM", app.DefaultCLIHome)
err := executor.ExecuteContext(ctx)

err := executor.Execute()
if err != nil {
fmt.Printf("Failed executing CLI command: %s, exiting...\n", err)
os.Exit(1)
Expand Down
15 changes: 13 additions & 2 deletions cmd/wasmd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/json"
"io"
"os"
Expand Down Expand Up @@ -74,13 +75,23 @@ func main() {
debug.Cmd(),
)

server.AddCommands(rootCmd, newApp, exportAppStateAndTMValidators)
server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, exportAppStateAndTMValidators)

// Create and set a client.Context on the command's Context. During the pre-run
// of the root command, a default initialized client.Context is provided to
// seed child command execution with values such as AccountRetriver, Keyring,
// and a Tendermint RPC. This requires the use of a pointer reference when
// getting and setting the client.Context. Ideally, we utilize
// https://github.com/spf13/cobra/pull/1118.
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{})
ctx = context.WithValue(ctx, server.ServerContextKey, server.NewDefaultContext())

// prepare and add flags
executor := cli.PrepareBaseCmd(rootCmd, "WM", app.DefaultNodeHome)
rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod,
0, "Assert registered invariants every N blocks")
err := executor.Execute()
err := executor.ExecuteContext(ctx)
if err != nil {
panic(err)
}
Expand Down
11 changes: 0 additions & 11 deletions docker/run_all.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/run_rest_server.sh

This file was deleted.

2 changes: 1 addition & 1 deletion docker/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ for addr in "$@"; do
wasmd add-genesis-account "$addr" "1000000000$STAKE,1000000000$FEE"
done
# submit a genesis validator tx
(echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | wasmd gentx --name validator --amount "250000000$STAKE"
(echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | wasmd gentx validator --chain-id=testing --amount "250000000$STAKE"
wasmd collect-gentxs
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
// Note: update ENV GO_COSMWASM in Dockerfile when updating this
github.com/CosmWasm/go-cosmwasm v0.9.1
github.com/cosmos/cosmos-sdk v0.34.4-0.20200806092156-3076a8b12ec3
github.com/cosmos/cosmos-sdk v0.34.4-0.20200807102022-3322e269a184
github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a
github.com/gogo/protobuf v1.3.1
github.com/google/gofuzz v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cosmos/cosmos-sdk v0.34.4-0.20200806092156-3076a8b12ec3 h1:22rm9uHzeJtlGjVMRIqTUkRFapFU3nwN9xy8KLvLStg=
github.com/cosmos/cosmos-sdk v0.34.4-0.20200806092156-3076a8b12ec3/go.mod h1:7fv4+b5E8Iq9m0MKzR/v/QOLDKcpp+rBZW2JiNRtqMY=
github.com/cosmos/cosmos-sdk v0.34.4-0.20200807102022-3322e269a184 h1:Ogtqklf+8k2mdVl5JVwPVaBIk1Io9KyKdMzoxhq1cw8=
github.com/cosmos/cosmos-sdk v0.34.4-0.20200807102022-3322e269a184/go.mod h1:7fv4+b5E8Iq9m0MKzR/v/QOLDKcpp+rBZW2JiNRtqMY=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
Expand Down

0 comments on commit 6b5133e

Please sign in to comment.