diff --git a/Gopkg.lock b/Gopkg.lock index 68350442d84d..bf9fa4149c6c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -10,6 +10,7 @@ revision = "48b08affede2cea076a3cf13b2e3f72ed262b743" [[projects]] + branch = "master" digest = "1:09a7f74eb6bb3c0f14d8926610c87f569c5cff68e978d30e9a3540aeb626fdf0" name = "github.com/bartekn/go-bip39" packages = ["."] @@ -38,7 +39,7 @@ name = "github.com/btcsuite/btcd" packages = ["btcec"] pruneopts = "UT" - revision = "2a560b2036bee5e3679ec2133eb6520b2f195213" + revision = "67e573d211ace594f1366b4ce9d39726c4b19bd0" [[projects]] digest = "1:386de157f7d19259a7f9c81f26ce011223ce0f090353c1152ffdf730d7d10ac2" @@ -62,13 +63,6 @@ revision = "346938d642f2ec3594ed81d874461961cd0faa76" version = "v1.1.0" -[[projects]] - digest = "1:c7644c73a3d23741fdba8a99b1464e021a224b7e205be497271a8003a15ca41b" - name = "github.com/ebuchman/fail-test" - packages = ["."] - pruneopts = "UT" - revision = "95f809107225be108efcf10a3509e4ea6ceef3c4" - [[projects]] digest = "1:abeb38ade3f32a92943e5be54f55ed6d6e3b6602761d74b4aab4c9dd45c18abd" name = "github.com/fsnotify/fsnotify" @@ -171,12 +165,13 @@ version = "v1.2.0" [[projects]] - digest = "1:ea40c24cdbacd054a6ae9de03e62c5f252479b96c716375aace5c120d68647c8" + digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10" name = "github.com/hashicorp/hcl" packages = [ ".", "hcl/ast", "hcl/parser", + "hcl/printer", "hcl/scanner", "hcl/strconv", "hcl/token", @@ -245,12 +240,12 @@ version = "v1.0.0" [[projects]] - digest = "1:e32dfc6abff6a3633ef4d9a1022fd707c8ef26f1e1e8f855dc58dc415ce7c8f3" + digest = "1:53bc4cd4914cd7cd52139990d5170d6dc99067ae31c56530621b18b35fc30318" name = "github.com/mitchellh/mapstructure" packages = ["."] pruneopts = "UT" - revision = "fe40af7a9c397fa3ddba203c38a5042c5d0475ad" - version = "v1.1.1" + revision = "3536a929edddb9a5b34bd6861dc4a9647cb459fe" + version = "v1.1.2" [[projects]] digest = "1:95741de3af260a92cc5c7f3f3061e85273f5a81b5db20d4bd68da74bd521675e" @@ -296,7 +291,7 @@ [[projects]] branch = "master" - digest = "1:63b68062b8968092eb86bedc4e68894bd096ea6b24920faca8b9dcf451f54bb5" + digest = "1:db712fde5d12d6cdbdf14b777f0c230f4ff5ab0be8e35b239fc319953ed577a4" name = "github.com/prometheus/common" packages = [ "expfmt", @@ -304,11 +299,11 @@ "model", ] pruneopts = "UT" - revision = "c7de2306084e37d54b8be01f3541a8464345e9a5" + revision = "7e9e6cabbd393fc208072eedef99188d0ce788b6" [[projects]] branch = "master" - digest = "1:ef1dd9945e58ee9b635273d28c0ef3fa3742a7dedc038ebe207fd63e6ce000ef" + digest = "1:ef74914912f99c79434d9c09658274678bc85080ebe3ab32bec3940ebce5e1fc" name = "github.com/prometheus/procfs" packages = [ ".", @@ -317,7 +312,7 @@ "xfs", ] pruneopts = "UT" - revision = "418d78d0b9a7b7de3a6bbc8a23def624cc977bb2" + revision = "185b4288413d2a0dd0806f78c90dde719829e5ae" [[projects]] digest = "1:ea0700160aca4ef099f4e06686a665a87691f4248dddd40796925eda2e46bd64" @@ -346,12 +341,12 @@ version = "v1.1.2" [[projects]] - digest = "1:516e71bed754268937f57d4ecb190e01958452336fa73dbac880894164e91c1f" + digest = "1:08d65904057412fc0270fc4812a1c90c594186819243160dc779a402d4b6d0bc" name = "github.com/spf13/cast" packages = ["."] pruneopts = "UT" - revision = "8965335b8c7107321228e3e3702cab9832751bac" - version = "v1.2.0" + revision = "8c9545af88b134710ab1cd196795e7f2388358d7" + version = "v1.3.0" [[projects]] digest = "1:7ffc0983035bc7e297da3688d9fe19d60a420e9c38bef23f845c53788ed6a05e" @@ -370,12 +365,12 @@ version = "v1.0.0" [[projects]] - digest = "1:dab83a1bbc7ad3d7a6ba1a1cc1760f25ac38cdf7d96a5cdd55cd915a4f5ceaf9" + digest = "1:c1b1102241e7f645bc8e0c22ae352e8f0dc6484b6cb4d132fa9f24174e0119e2" name = "github.com/spf13/pflag" packages = ["."] pruneopts = "UT" - revision = "9a97c102cda95a86cec2345a6f09f55a939babf5" - version = "v1.0.2" + revision = "298182f68c66c05229eb03ac171abe6e309ee79a" + version = "v1.0.3" [[projects]] digest = "1:f8e1a678a2571e265f4bf91a3e5e32aa6b1474a55cb0ea849750cc177b664d96" @@ -423,18 +418,6 @@ pruneopts = "UT" revision = "e5840949ff4fff0c56f9b6a541e22b63581ea9df" -[[projects]] - branch = "master" - digest = "1:087aaa7920e5d0bf79586feb57ce01c35c830396ab4392798112e8aae8c47722" - name = "github.com/tendermint/ed25519" - packages = [ - ".", - "edwards25519", - "extra25519", - ] - pruneopts = "UT" - revision = "d8387025d2b9d158cf4efb07e7ebf814bcce2057" - [[projects]] digest = "1:2c971a45c89ca2ccc735af50919cdee05fbdc54d4bf50625073693300e31ead8" name = "github.com/tendermint/go-amino" @@ -452,7 +435,7 @@ version = "v0.11.0" [[projects]] - digest = "1:f9c7a1f3ee087476f4883c33cc7c1bdbe56b9670b2fb27855ea2f386393272f5" + digest = "1:395820b381043b9d2204e181ddf0f9147397c4a7b8f5dc3162de4cfcddf4589a" name = "github.com/tendermint/tendermint" packages = [ "abci/client", @@ -485,6 +468,7 @@ "libs/db", "libs/errors", "libs/events", + "libs/fail", "libs/flowrate", "libs/log", "libs/pubsub", @@ -505,7 +489,6 @@ "rpc/core", "rpc/core/types", "rpc/grpc", - "rpc/lib", "rpc/lib/client", "rpc/lib/server", "rpc/lib/types", @@ -518,8 +501,8 @@ "version", ] pruneopts = "UT" - revision = "90eda9bfb6e6daeed1c8015df41cb36772d91778" - version = "v0.25.1-rc0" + revision = "03e42d2e3866f01a00625f608e3bbfaeb30690de" + version = "v0.26.1-rc0" [[projects]] digest = "1:7886f86064faff6f8d08a3eb0e8c773648ff5a2e27730831e2bfbf07467f6666" @@ -530,13 +513,15 @@ version = "v0.1.0" [[projects]] - digest = "1:aaff04fa01d9b824fde6799759cc597b3ac3671b9ad31924c28b6557d0ee5284" + digest = "1:6f6dc6060c4e9ba73cf28aa88f12a69a030d3d19d518ef8e931879eaa099628d" name = "golang.org/x/crypto" packages = [ "bcrypt", "blowfish", "chacha20poly1305", "curve25519", + "ed25519", + "ed25519/internal/edwards25519", "hkdf", "internal/chacha20", "internal/subtle", diff --git a/Gopkg.toml b/Gopkg.toml index 0902bc412607..09e3d28d9ec1 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -57,7 +57,7 @@ [[override]] name = "github.com/tendermint/tendermint" - version = "=0.25.1-rc0" + version = "0.26.1-rc0" ## deps without releases: @@ -106,4 +106,3 @@ [prune] go-tests = true unused-packages = true - diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index cfbbe5cc2edd..66eaae099379 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -11,7 +11,6 @@ import ( "strings" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" distr "github.com/cosmos/cosmos-sdk/x/distribution" @@ -81,14 +80,6 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) { } } -// get app init parameters for server init command -func GaiaAppInit() server.AppInit { - - return server.AppInit{ - AppGenState: GaiaAppGenStateJSON, - } -} - // Create the core parameters for genesis initialization for gaia // note that the pubkey input is this machines pubkey func GaiaAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) ( diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index ae076571b504..2983789b1b1e 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -37,14 +37,12 @@ func main() { Short: "Gaia Daemon (server)", PersistentPreRunE: server.PersistentPreRunEFn(ctx), } - appInit := app.GaiaAppInit() - rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc, appInit)) + rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc)) rootCmd.AddCommand(gaiaInit.CollectGenTxsCmd(ctx, cdc)) - rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc, server.AppInit{})) + rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc)) rootCmd.AddCommand(gaiaInit.GenTxCmd(ctx, cdc)) - server.AddCommands(ctx, cdc, rootCmd, appInit, - newApp, exportAppStateAndTMValidators) + server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators) // prepare and add flags executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome) diff --git a/cmd/gaia/init/collect.go b/cmd/gaia/init/collect.go index 34b65e560bce..fc5504cce5a7 100644 --- a/cmd/gaia/init/collect.go +++ b/cmd/gaia/init/collect.go @@ -64,7 +64,7 @@ func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { return err } - toPrint.AppMessage = appMessage + toPrint.Message = appMessage // print out some key information return displayInfo(cdc, toPrint) }, @@ -105,7 +105,7 @@ func genAppStateFromConfig(cdc *codec.Codec, config *cfg.Config, initCfg initCon return } - err = WriteGenesisFile(genFile, initCfg.ChainID, nil, appState) + err = server.WriteGenesisFile(genFile, initCfg.ChainID, nil, appState) return } diff --git a/cmd/gaia/init/init.go b/cmd/gaia/init/init.go index 0290ae4fb2bb..738251bd6fdd 100644 --- a/cmd/gaia/init/init.go +++ b/cmd/gaia/init/init.go @@ -3,7 +3,6 @@ package init import ( "encoding/json" "fmt" - "github.com/tendermint/tendermint/privval" "os" "path/filepath" @@ -18,7 +17,6 @@ import ( "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/p2p" - "github.com/tendermint/tendermint/types" ) const ( @@ -28,10 +26,10 @@ const ( ) type printInfo struct { - Moniker string `json:"moniker"` - ChainID string `json:"chain_id"` - NodeID string `json:"node_id"` - AppMessage json.RawMessage `json:"app_message"` + Moniker string `json:"moniker"` + ChainID string `json:"chain_id"` + NodeID string `json:"node_id"` + Message json.RawMessage `json:"message"` } // nolint: errcheck @@ -46,7 +44,7 @@ func displayInfo(cdc *codec.Codec, info printInfo) error { // get cmd to initialize all files for tendermint and application // nolint -func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command { +func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "init", Short: "Initialize private validator, p2p, genesis, and application configuration files", @@ -74,15 +72,15 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob viper.GetBool(flagOverwrite)); err != nil { return err } - if err = WriteGenesisFile(genFile, chainID, nil, appState); err != nil { + if err = server.WriteGenesisFile(genFile, chainID, nil, appState); err != nil { return err } toPrint := printInfo{ - ChainID: chainID, - Moniker: config.Moniker, - NodeID: nodeID, - AppMessage: appState, + ChainID: chainID, + Moniker: config.Moniker, + NodeID: nodeID, + Message: appState, } cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config) @@ -105,40 +103,10 @@ func InitializeNodeValidatorFiles(config *cfg.Config) (nodeID string, valPubKey return } nodeID = string(nodeKey.ID()) - valPubKey = ReadOrCreatePrivValidator(config.PrivValidatorFile()) + valPubKey = server.ReadOrCreatePrivValidator(config.PrivValidatorFile()) return } -// WriteGenesisFile creates and writes the genesis configuration to disk. An -// error is returned if building or writing the configuration to file fails. -// nolint: unparam -func WriteGenesisFile(genesisFile, chainID string, validators []types.GenesisValidator, appState json.RawMessage) error { - genDoc := types.GenesisDoc{ - ChainID: chainID, - Validators: validators, - AppState: appState, - } - - if err := genDoc.ValidateAndComplete(); err != nil { - return err - } - - return genDoc.SaveAs(genesisFile) -} - -// read of create the private key file for this config -func ReadOrCreatePrivValidator(privValFile string) crypto.PubKey { - // private validator - var privValidator *privval.FilePV - if common.FileExists(privValFile) { - privValidator = privval.LoadFilePV(privValFile) - } else { - privValidator = privval.GenFilePV(privValFile) - privValidator.Save() - } - return privValidator.GetPubKey() -} - func initializeEmptyGenesis(cdc *codec.Codec, genFile string, chainID string, overwrite bool) (appState json.RawMessage, err error) { if !overwrite && common.FileExists(genFile) { diff --git a/cmd/gaia/init/init_test.go b/cmd/gaia/init/init_test.go index bd5274c26113..f6845c3114eb 100644 --- a/cmd/gaia/init/init_test.go +++ b/cmd/gaia/init/init_test.go @@ -30,10 +30,7 @@ func TestInitCmd(t *testing.T) { require.Nil(t, err) ctx := server.NewContext(cfg, logger) cdc := app.MakeCodec() - appInit := server.AppInit{ - AppGenState: mock.AppGenState, - } - cmd := InitCmd(ctx, cdc, appInit) + cmd := InitCmd(ctx, cdc) err = cmd.RunE(nil, nil) require.NoError(t, err) } @@ -58,10 +55,7 @@ func TestEmptyState(t *testing.T) { require.Nil(t, err) ctx := server.NewContext(cfg, logger) cdc := app.MakeCodec() - appInit := server.AppInit{ - AppGenState: mock.AppGenStateEmpty, - } - cmd := InitCmd(ctx, cdc, appInit) + cmd := InitCmd(ctx, cdc) err = cmd.RunE(nil, nil) require.NoError(t, err) @@ -105,10 +99,7 @@ func TestStartStandAlone(t *testing.T) { require.Nil(t, err) ctx := server.NewContext(cfg, logger) cdc := app.MakeCodec() - appInit := server.AppInit{ - AppGenState: mock.AppGenState, - } - initCmd := InitCmd(ctx, cdc, appInit) + initCmd := InitCmd(ctx, cdc) err = initCmd.RunE(nil, nil) require.NoError(t, err) diff --git a/cmd/gaia/init/testnet.go b/cmd/gaia/init/testnet.go index 5f729b0a4b7e..a2aaa27024ff 100644 --- a/cmd/gaia/init/testnet.go +++ b/cmd/gaia/init/testnet.go @@ -36,8 +36,7 @@ var ( const nodeDirPerm = 0755 // get cmd to initialize all files for tendermint testnet and application -func TestnetFilesCmd(ctx *server.Context, cdc *codec.Codec, - appInit server.AppInit) *cobra.Command { +func TestnetFilesCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "testnet", @@ -137,7 +136,7 @@ func testnetWithConfig(config *cfg.Config, cdc *codec.Codec) error { keyPass = app.DefaultKeyPass } - addr, secret, err := server.GenerateSaveCoinKey(clientDir, nodeDirName, keyPass, true) + addr, secret, err := server.GenerateSaveAccountKeyAndSecret(clientDir, nodeDirName, keyPass, true) if err != nil { _ = os.RemoveAll(outDir) return err diff --git a/docs/getting-started/join-testnet.md b/docs/getting-started/join-testnet.md index ce070c4fe967..d921df91f8ae 100644 --- a/docs/getting-started/join-testnet.md +++ b/docs/getting-started/join-testnet.md @@ -29,19 +29,6 @@ You can edit this `name` later, in the `~/.gaiad/config/config.toml` file: moniker = "" ``` -You can edit the `~/.gaiad/config/gaiad.toml` file in order to enable the anti spam mechanism and reject incoming transactions with less than a minimum fee: - -``` -# This is a TOML config file. -# For more information, see https://github.com/toml-lang/toml - -##### main base config options ##### - -# Validators reject any tx from the mempool with less than the minimum fee per gas. -minimum_fees = "" -``` - - Your full node has been initialized! Please skip to [Genesis & Seeds](#genesis-seeds). ## Upgrading From Previous Testnet diff --git a/docs/sdk/sdk-by-examples/simple-governance/bridging-it-all.md b/docs/sdk/sdk-by-examples/simple-governance/bridging-it-all.md index 546eb7d875f6..9978adfff7f9 100644 --- a/docs/sdk/sdk-by-examples/simple-governance/bridging-it-all.md +++ b/docs/sdk/sdk-by-examples/simple-governance/bridging-it-all.md @@ -97,6 +97,8 @@ To interact with our application, let us add the commands from the `simple_gover The `simplegovd` command will run the daemon server as a background process. First, let us create some `utils` functions: ```go +// NOTE: This is outdated, AppInit has been removed. +// XXX: Update tutorial. // cmd/simplegovd/main.go // SimpleGovAppInit initial parameters var SimpleGovAppInit = server.AppInit{ @@ -137,7 +139,7 @@ func main() { PersistentPreRunE: server.PersistentPreRunEFn(ctx), } - server.AddCommands(ctx, cdc, rootCmd, SimpleGovAppInit, + server.AddCommands(ctx, cdc, rootCmd, server.ConstructAppCreator(newApp, "simplegov"), server.ConstructAppExporter(exportAppState, "simplegov")) @@ -253,4 +255,4 @@ func MakeCodec() *codec.Codec { cdc.RegisterConcrete(&types.AppAccount{}, "simpleGov/Account", nil) return cdc } -``` \ No newline at end of file +``` diff --git a/examples/basecoin/cmd/basecoind/main.go b/examples/basecoin/cmd/basecoind/main.go index 4f40a145094e..b33d968ebe95 100644 --- a/examples/basecoin/cmd/basecoind/main.go +++ b/examples/basecoin/cmd/basecoind/main.go @@ -9,8 +9,6 @@ import ( "github.com/tendermint/tendermint/p2p" "github.com/cosmos/cosmos-sdk/baseapp" - gaiaInit "github.com/cosmos/cosmos-sdk/cmd/gaia/init" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/basecoin/app" @@ -39,10 +37,9 @@ func main() { PersistentPreRunE: server.PersistentPreRunEFn(ctx), } - appInit := server.DefaultAppInit - rootCmd.AddCommand(InitCmd(ctx, cdc, appInit)) + rootCmd.AddCommand(InitCmd(ctx, cdc)) - server.AddCommands(ctx, cdc, rootCmd, appInit, + server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators) // prepare and add flags @@ -58,7 +55,7 @@ func main() { // get cmd to initialize all files for tendermint and application // nolint: errcheck -func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command { +func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "init", Short: "Initialize genesis config, priv-validator file, and p2p-node file", @@ -78,38 +75,44 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob } nodeID := string(nodeKey.ID()) - pk := gaiaInit.ReadOrCreatePrivValidator(config.PrivValidatorFile()) - genTx, appMessage, validator, err := server.SimpleAppGenTx(cdc, pk) - if err != nil { - return err + pk := server.ReadOrCreatePrivValidator(config.PrivValidatorFile()) + validator := tmtypes.GenesisValidator{ + PubKey: pk, + Power: 10, } - appState, err := appInit.AppGenState( - cdc, tmtypes.GenesisDoc{}, []json.RawMessage{genTx}) - if err != nil { - return err - } - appStateJSON, err := cdc.MarshalJSON(appState) + addr, secret, err := server.GenerateAccountKeyAndSecret() if err != nil { return err } + appStateJSON := (fmt.Sprintf(`{ + "accounts": [{ + "address": "%s", + "coins": [ + { + "denom": "mycoin", + "amount": "9007199254740992" + } + ] + }] +}`, addr)) toPrint := struct { - ChainID string `json:"chain_id"` - NodeID string `json:"node_id"` - AppMessage json.RawMessage `json:"app_message"` + ChainID string `json:"chain_id"` + NodeID string `json:"node_id"` + Message string `json:"message"` }{ chainID, nodeID, - appMessage, + fmt.Sprintf("Secret: %v", secret), } out, err := codec.MarshalJSONIndent(cdc, toPrint) if err != nil { return err } fmt.Fprintf(os.Stderr, "%s\n", string(out)) - return gaiaInit.WriteGenesisFile(config.GenesisFile(), chainID, - []tmtypes.GenesisValidator{validator}, appStateJSON) + return server.WriteGenesisFile(config.GenesisFile(), chainID, + []tmtypes.GenesisValidator{validator}, []byte(appStateJSON)) }, } diff --git a/examples/democoin/cmd/democoind/main.go b/examples/democoin/cmd/democoind/main.go index 2f48a64f34c9..6531b8360dcf 100644 --- a/examples/democoin/cmd/democoind/main.go +++ b/examples/democoin/cmd/democoind/main.go @@ -6,20 +6,18 @@ import ( "io" "os" - "github.com/cosmos/cosmos-sdk/client" - "github.com/spf13/viper" - "github.com/tendermint/tendermint/libs/common" - "github.com/tendermint/tendermint/p2p" - "github.com/spf13/cobra" + "github.com/spf13/viper" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/cli" + "github.com/tendermint/tendermint/libs/common" dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/p2p" tmtypes "github.com/tendermint/tendermint/types" - gaiaInit "github.com/cosmos/cosmos-sdk/cmd/gaia/init" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/examples/democoin/app" "github.com/cosmos/cosmos-sdk/server" @@ -30,42 +28,9 @@ const ( flagClientHome = "home-client" ) -// init parameters -var CoolAppInit = server.AppInit{ - AppGenState: CoolAppGenState, -} - -// coolGenAppParams sets up the app_state and appends the cool app state -func CoolAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) ( - appState json.RawMessage, err error) { - appState, err = server.SimpleAppGenState(cdc, tmtypes.GenesisDoc{}, appGenTxs) - if err != nil { - return - } - - key := "cool" - value := json.RawMessage(`{ - "trend": "ice-cold" - }`) - - appState, err = server.InsertKeyJSON(cdc, appState, key, value) - if err != nil { - return - } - - key = "pow" - value = json.RawMessage(`{ - "difficulty": "1", - "count": "0" - }`) - - appState, err = server.InsertKeyJSON(cdc, appState, key, value) - return -} - // get cmd to initialize all files for tendermint and application // nolint: errcheck -func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command { +func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "init", Short: "Initialize genesis config, priv-validator file, and p2p-node file", @@ -85,38 +50,51 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob } nodeID := string(nodeKey.ID()) - pk := gaiaInit.ReadOrCreatePrivValidator(config.PrivValidatorFile()) - genTx, appMessage, validator, err := server.SimpleAppGenTx(cdc, pk) - if err != nil { - return err + pk := server.ReadOrCreatePrivValidator(config.PrivValidatorFile()) + validator := tmtypes.GenesisValidator{ + PubKey: pk, + Power: 10, } - appState, err := appInit.AppGenState(cdc, tmtypes.GenesisDoc{}, - []json.RawMessage{genTx}) - if err != nil { - return err - } - appStateJSON, err := cdc.MarshalJSON(appState) + addr, secret, err := server.GenerateAccountKeyAndSecret() if err != nil { return err } + appStateJSON := (fmt.Sprintf(`{ + "cool": { + "trend": "ice-cold" + }, + "pow": { + "difficulty": "1", + "count": "0" + }, + "accounts": [{ + "address": "%s", + "coins": [ + { + "denom": "mycoin", + "amount": "9007199254740992" + } + ] + }] +}`, addr)) toPrint := struct { - ChainID string `json:"chain_id"` - NodeID string `json:"node_id"` - AppMessage json.RawMessage `json:"app_message"` + ChainID string `json:"chain_id"` + NodeID string `json:"node_id"` + Message string `json:"message"` }{ chainID, nodeID, - appMessage, + fmt.Sprintf("Secret: %v", secret), } out, err := codec.MarshalJSONIndent(cdc, toPrint) if err != nil { return err } fmt.Fprintf(os.Stderr, "%s\n", string(out)) - return gaiaInit.WriteGenesisFile(config.GenesisFile(), chainID, - []tmtypes.GenesisValidator{validator}, appStateJSON) + return server.WriteGenesisFile(config.GenesisFile(), chainID, + []tmtypes.GenesisValidator{validator}, []byte(appStateJSON)) }, } @@ -157,10 +135,8 @@ func main() { PersistentPreRunE: server.PersistentPreRunEFn(ctx), } - rootCmd.AddCommand(InitCmd(ctx, cdc, CoolAppInit)) - rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc, CoolAppInit)) - - server.AddCommands(ctx, cdc, rootCmd, CoolAppInit, + rootCmd.AddCommand(InitCmd(ctx, cdc)) + server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators) // prepare and add flags diff --git a/server/config/config.go b/server/config/config.go deleted file mode 100644 index 239097b13737..000000000000 --- a/server/config/config.go +++ /dev/null @@ -1,37 +0,0 @@ -package config - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -const ( - defaultMinimumFees = "" -) - -// BaseConfig defines the server's basic configuration -type BaseConfig struct { - // Tx minimum fee - MinFees string `mapstructure:"minimum_fees"` -} - -// Config defines the server's top level configuration -type Config struct { - BaseConfig `mapstructure:",squash"` -} - -// SetMinimumFee sets the minimum fee. -func (c *Config) SetMinimumFees(fees sdk.Coins) { c.MinFees = fees.String() } - -// SetMinimumFee sets the minimum fee. -func (c *Config) MinimumFees() sdk.Coins { - fees, err := sdk.ParseCoins(c.MinFees) - if err != nil { - panic(fmt.Sprintf("invalid minimum fees: %v", err)) - } - return fees -} - -// DefaultConfig returns server's default configuration. -func DefaultConfig() *Config { return &Config{BaseConfig{MinFees: defaultMinimumFees}} } diff --git a/server/config/config_test.go b/server/config/config_test.go deleted file mode 100644 index e4d552ad21f3..000000000000 --- a/server/config/config_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package config - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" -) - -func TestDefaultConfig(t *testing.T) { - cfg := DefaultConfig() - require.True(t, cfg.MinimumFees().IsZero()) -} - -func TestSetMinimumFees(t *testing.T) { - cfg := DefaultConfig() - cfg.SetMinimumFees(sdk.Coins{sdk.NewCoin("foo", sdk.NewInt(100))}) - require.Equal(t, "100foo", cfg.MinFees) -} diff --git a/server/config/toml.go b/server/config/toml.go deleted file mode 100644 index 3c60fbdf93fb..000000000000 --- a/server/config/toml.go +++ /dev/null @@ -1,46 +0,0 @@ -package config - -import ( - "bytes" - "text/template" - - "github.com/spf13/viper" - cmn "github.com/tendermint/tendermint/libs/common" -) - -const defaultConfigTemplate = `# This is a TOML config file. -# For more information, see https://github.com/toml-lang/toml - -##### main base config options ##### - -# Validators reject any tx from the mempool with less than the minimum fee per gas. -minimum_fees = "{{ .BaseConfig.MinFees }}" -` - -var configTemplate *template.Template - -func init() { - var err error - tmpl := template.New("cosmosConfigFileTemplate") - if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil { - panic(err) - } -} - -// ParseConfig retrieves the default environment configuration for Cosmos. -func ParseConfig() (*Config, error) { - conf := DefaultConfig() - err := viper.Unmarshal(conf) - return conf, err -} - -// WriteConfigFile renders config using the template and writes it to configFilePath. -func WriteConfigFile(configFilePath string, config *Config) { - var buffer bytes.Buffer - - if err := configTemplate.Execute(&buffer, config); err != nil { - panic(err) - } - - cmn.MustWriteFile(configFilePath, buffer.Bytes(), 0644) -} diff --git a/server/init.go b/server/init.go index 75e13f452653..05b94746703a 100644 --- a/server/init.go +++ b/server/init.go @@ -2,102 +2,19 @@ package server import ( "encoding/json" - "errors" "fmt" + "github.com/cosmos/cosmos-sdk/crypto/keys" - "github.com/tendermint/tendermint/crypto" dbm "github.com/tendermint/tendermint/libs/db" "github.com/tendermint/tendermint/types" clkeys "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - tmtypes "github.com/tendermint/tendermint/types" ) -// Core functionality passed from the application to the server init command -type AppInit struct { - // AppGenState creates the core parameters initialization. It takes in a - // pubkey meant to represent the pubkey of the validator of this machine. - AppGenState func(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) ( - appState json.RawMessage, err error) -} - -// SimpleGenTx is a simple genesis tx -type SimpleGenTx struct { - Addr sdk.AccAddress `json:"addr"` -} - -//_____________________________________________________________________ - -// simple default application init -var DefaultAppInit = AppInit{ - AppGenState: SimpleAppGenState, -} - -// Generate a genesis transaction -func SimpleAppGenTx(cdc *codec.Codec, pk crypto.PubKey) ( - appGenTx, cliPrint json.RawMessage, validator types.GenesisValidator, err error) { - var addr sdk.AccAddress - var secret string - addr, secret, err = GenerateCoinKey() - if err != nil { - return - } - var bz []byte - simpleGenTx := SimpleGenTx{Addr: addr} - bz, err = cdc.MarshalJSON(simpleGenTx) - if err != nil { - return - } - appGenTx = json.RawMessage(bz) - mm := map[string]string{"secret": secret} - bz, err = cdc.MarshalJSON(mm) - if err != nil { - return - } - cliPrint = json.RawMessage(bz) - validator = tmtypes.GenesisValidator{ - PubKey: pk, - Power: 10, - } - return -} - -// create the genesis app state -func SimpleAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) ( - appState json.RawMessage, err error) { - - if len(appGenTxs) != 1 { - err = errors.New("must provide a single genesis transaction") - return - } - - var tx SimpleGenTx - err = cdc.UnmarshalJSON(appGenTxs[0], &tx) - if err != nil { - return - } - - appState = json.RawMessage(fmt.Sprintf(`{ - "accounts": [{ - "address": "%s", - "coins": [ - { - "denom": "mycoin", - "amount": "9007199254740992" - } - ] - }] -}`, tx.Addr)) - return -} - -//___________________________________________________________________________________________ - -// GenerateCoinKey returns the address of a public key, along with the secret +// GenerateAccountKeyAndSecret returns the address of a public key, along with the secret // phrase to recover the private key. -func GenerateCoinKey() (sdk.AccAddress, string, error) { +func GenerateAccountKeyAndSecret() (sdk.AccAddress, string, error) { // construct an in-memory key store keybase := keys.New( @@ -113,9 +30,9 @@ func GenerateCoinKey() (sdk.AccAddress, string, error) { return sdk.AccAddress(addr), secret, nil } -// GenerateSaveCoinKey returns the address of a public key, along with the secret +// GenerateSaveAccountKeyAndSecret returns the address of a public key, along with the secret // phrase to recover the private key. -func GenerateSaveCoinKey(clientRoot, keyName, keyPass string, overwrite bool) (sdk.AccAddress, string, error) { +func GenerateSaveAccountKeyAndSecret(clientRoot, keyName, keyPass string, overwrite bool) (sdk.AccAddress, string, error) { // get the keystore from the client keybase, err := clkeys.GetKeyBaseFromDirWithWritePerm(clientRoot) @@ -140,3 +57,20 @@ func GenerateSaveCoinKey(clientRoot, keyName, keyPass string, overwrite bool) (s addr := info.GetPubKey().Address() return sdk.AccAddress(addr), secret, nil } + +// WriteGenesisFile creates and writes the genesis configuration to disk. An +// error is returned if building or writing the configuration to file fails. +// nolint: unparam +func WriteGenesisFile(genesisFile, chainID string, validators []types.GenesisValidator, appState json.RawMessage) error { + genDoc := types.GenesisDoc{ + ChainID: chainID, + Validators: validators, + AppState: appState, + } + + if err := genDoc.ValidateAndComplete(); err != nil { + return err + } + + return genDoc.SaveAs(genesisFile) +} diff --git a/server/util.go b/server/util.go index 51f10c765a98..0d16b08c4803 100644 --- a/server/util.go +++ b/server/util.go @@ -1,7 +1,6 @@ package server import ( - "encoding/json" "net" "os" "os/signal" @@ -14,13 +13,15 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server/config" "github.com/cosmos/cosmos-sdk/version" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" cfg "github.com/tendermint/tendermint/config" + crypto "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/cli" tmflags "github.com/tendermint/tendermint/libs/cli/flags" + "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/privval" ) // server context @@ -101,19 +102,6 @@ func interceptLoadConfig() (conf *cfg.Config, err error) { conf, err = tcmd.ParseConfig() // NOTE: ParseConfig() creates dir/files as necessary. } - cosmosConfigFilePath := filepath.Join(rootDir, "config/gaiad.toml") - viper.SetConfigName("cosmos") - _ = viper.MergeInConfig() - var cosmosConf *config.Config - if _, err := os.Stat(cosmosConfigFilePath); os.IsNotExist(err) { - cosmosConf, _ := config.ParseConfig() - config.WriteConfigFile(cosmosConfigFilePath, cosmosConf) - } - - if cosmosConf == nil { - _, err = config.ParseConfig() - } - return } @@ -128,7 +116,7 @@ func validateConfig(conf *cfg.Config) error { // add server commands func AddCommands( ctx *Context, cdc *codec.Codec, - rootCmd *cobra.Command, appInit AppInit, + rootCmd *cobra.Command, appCreator AppCreator, appExport AppExporter) { rootCmd.PersistentFlags().String("log_level", ctx.Config.LogLevel, "Log level") @@ -155,25 +143,7 @@ func AddCommands( ) } -//___________________________________________________________________________________ - -// InsertKeyJSON inserts a new JSON field/key with a given value to an existing -// JSON message. An error is returned if any serialization operation fails. -// -// NOTE: The ordering of the keys returned as the resulting JSON message is -// non-deterministic, so the client should not rely on key ordering. -func InsertKeyJSON(cdc *codec.Codec, baseJSON []byte, key string, value json.RawMessage) ([]byte, error) { - var jsonMap map[string]json.RawMessage - - if err := cdc.UnmarshalJSON(baseJSON, &jsonMap); err != nil { - return nil, err - } - - jsonMap[key] = value - bz, err := codec.MarshalJSONIndent(cdc, jsonMap) - - return json.RawMessage(bz), err -} +//---------------------------------------- // https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go // TODO there must be a better way to get external IP @@ -242,3 +212,16 @@ func addrToIP(addr net.Addr) net.IP { } return ip } + +// read of create the private key file for this config +func ReadOrCreatePrivValidator(privValFile string) crypto.PubKey { + // private validator + var privValidator *privval.FilePV + if common.FileExists(privValFile) { + privValidator = privval.LoadFilePV(privValFile) + } else { + privValidator = privval.GenFilePV(privValFile) + privValidator.Save() + } + return privValidator.GetPubKey() +} diff --git a/server/util_test.go b/server/util_test.go deleted file mode 100644 index 2c16759c9dfc..000000000000 --- a/server/util_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package server - -import ( - "encoding/json" - "testing" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/stretchr/testify/require" -) - -func TestInsertKeyJSON(t *testing.T) { - cdc := codec.New() - - foo := map[string]string{"foo": "foofoo"} - bar := map[string]string{"barInner": "barbar"} - - // create raw messages - bz, err := cdc.MarshalJSON(foo) - require.NoError(t, err) - fooRaw := json.RawMessage(bz) - - bz, err = cdc.MarshalJSON(bar) - require.NoError(t, err) - barRaw := json.RawMessage(bz) - - // make the append - appBz, err := InsertKeyJSON(cdc, fooRaw, "barOuter", barRaw) - require.NoError(t, err) - - // test the append - var appended map[string]json.RawMessage - err = cdc.UnmarshalJSON(appBz, &appended) - require.NoError(t, err) - - var resBar map[string]string - err = cdc.UnmarshalJSON(appended["barOuter"], &resBar) - require.NoError(t, err) - - require.Equal(t, bar, resBar, "appended: %v", appended) -}