diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fc71fdea900..df585e79fa6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,52 @@ # Changelog -## 0.3.0 (March 13, 2017) +## 0.3.0 (March 14, 2017) BREAKING CHANGES: - Remove `--data` flag and use `BCHOME` to set the home directory (defaults to `~/.basecoin`) - Remove `--in-proc` flag and start Tendermint in-process by default (expect Tendermint files in $BCHOME/tendermint). To start just the ABCI app/server, use `basecoin start --without-tendermint`. +- Consolidate genesis files so the Basecoin genesis is an object under `app_options` in Tendermint genesis. For instance: + +``` +{ + "app_hash": "", + "chain_id": "foo_bar_chain", + "genesis_time": "0001-01-01T00:00:00.000Z", + "validators": [ + { + "amount": 10, + "name": "", + "pub_key": [ + 1, + "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30" + ] + } + ], + "app_options": { + "accounts": [{ + "pub_key": { + "type": "ed25519", + "data": "6880db93598e283a67c4d88fc67a8858aa2de70f713fe94a5109e29c137100c2" + }, + "coins": [ + { + "denom": "blank", + "amount": 12345 + }, + { + "denom": "ETH", + "amount": 654321 + } + ] + }], + "plugin_options": ["plugin1/key1", "value1", "plugin1/key2", "value2"] + } +} +``` + +Note the array of key-value pairs is now under `app_options.plugin_options` while the `app_options` themselves are well formed. FEATURES: diff --git a/app/app.go b/app/app.go index b783ea5c6cf3..5aafff04ce89 100644 --- a/app/app.go +++ b/app/app.go @@ -60,7 +60,7 @@ func (app *Basecoin) SetOption(key string, value string) string { if plugin == nil { return "Invalid plugin name: " + pluginName } - log.Info("SetOption on plugin", "plugin", pluginName, "key", key, "value", value) + log.Notice("SetOption on plugin", "plugin", pluginName, "key", key, "value", value) return plugin.SetOption(app.state, key, value) } else { // Set option on basecoin diff --git a/app/genesis.go b/app/genesis.go index 8f96aa8bc9b0..ad8b2b6c9e34 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -2,32 +2,37 @@ package app import ( "encoding/json" - "fmt" "github.com/pkg/errors" "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/go-common" - "github.com/tendermint/go-wire" - tmtypes "github.com/tendermint/tendermint/types" + //tmtypes "github.com/tendermint/tendermint/types" ) func (app *Basecoin) LoadGenesis(path string) error { - tmDoc, appDoc, err := loadGenesis(path) + genDoc, err := loadGenesis(path) if err != nil { return err } - fmt.Println("TMGendoc", tmDoc) - fmt.Println("AppGendoc", appDoc) - app.SetOption("base/chain_id", appDoc.ChainID) - for _, acc := range appDoc.Accounts { + // set chain_id + app.SetOption("base/chain_id", genDoc.ChainID) + + // set accounts + for _, acc := range genDoc.AppOptions.Accounts { accBytes, err := json.Marshal(acc) if err != nil { return err } r := app.SetOption("base/account", string(accBytes)) // TODO: SetOption returns an error - log.Notice("SetOption", "result", r) + log.Notice("Done setting Account via SetOption", "result", r) + } + + // set plugin options + for _, kv := range genDoc.AppOptions.pluginOptions { + r := app.SetOption(kv.Key, kv.Value) + log.Notice("Done setting Plugin key-value pair via SetOption", "result", r, "k", kv.Key, "v", kv.Value) } return nil } @@ -39,32 +44,40 @@ type keyValue struct { // includes tendermint (in the json, we ignore here) type FullGenesisDoc struct { + ChainID string `json:"chain_id"` AppOptions *GenesisDoc `json:"app_options"` } type GenesisDoc struct { - ChainID string `json:"chain_id"` - Accounts []types.Account `json:"accounts"` + Accounts []types.Account `json:"accounts"` + PluginOptions []json.RawMessage `json:"plugin_options"` + + pluginOptions []keyValue // unmarshaled rawmessages } -func loadGenesis(filePath string) (*tmtypes.GenesisDoc, *GenesisDoc, error) { +func loadGenesis(filePath string) (*FullGenesisDoc, error) { bytes, err := cmn.ReadFile(filePath) if err != nil { - return nil, nil, errors.Wrap(err, "loading genesis file") + return nil, errors.Wrap(err, "loading genesis file") } - tmGenesis := new(tmtypes.GenesisDoc) - appGenesis := new(FullGenesisDoc) - // the tendermint genesis is go-wire - err = wire.ReadJSONBytes(bytes, tmGenesis) + // tmGenesis := new(tmtypes.GenesisDoc) + // err = wire.ReadJSONBytes(bytes, tmGenesis) // the basecoin genesis go-data :) - err = json.Unmarshal(bytes, appGenesis) + genDoc := new(FullGenesisDoc) + err = json.Unmarshal(bytes, genDoc) + if err != nil { + return nil, errors.Wrap(err, "unmarshaling genesis file") + } + + pluginOpts, err := parseGenesisList(genDoc.AppOptions.PluginOptions) if err != nil { - return nil, nil, errors.Wrap(err, "unmarshaling genesis file") + return nil, err } - return tmGenesis, appGenesis.AppOptions, nil + genDoc.AppOptions.pluginOptions = pluginOpts + return genDoc, nil } func parseGenesisList(kvz_ []json.RawMessage) (kvz []keyValue, err error) { diff --git a/app/testdata/genesis.json b/app/testdata/genesis.json index 0308716c9ce8..ee8879fd288f 100644 --- a/app/testdata/genesis.json +++ b/app/testdata/genesis.json @@ -1,19 +1,22 @@ -[ - "base/chainID", "foo_bar_chain", - "base/account", { - "pub_key": { - "type": "ed25519", - "data": "6880db93598e283a67c4d88fc67a8858aa2de70f713fe94a5109e29c137100c2" - }, - "coins": [ - { - "denom": "blank", - "amount": 12345 +{ + "chain_id": "foo_bar_chain", + "app_options": { + "accounts": [{ + "pub_key": { + "type": "ed25519", + "data": "6880db93598e283a67c4d88fc67a8858aa2de70f713fe94a5109e29c137100c2" }, - { - "denom": "ETH", - "amount": 654321 - } - ] + "coins": [ + { + "denom": "blank", + "amount": 12345 + }, + { + "denom": "ETH", + "amount": 654321 + } + ] + }], + "plugin_options": ["plugin1/key1", "value1", "plugin1/key2", "value2"] } -] +} diff --git a/cmd/commands/init.go b/cmd/commands/init.go index 695220445cbf..de60b0b5b8bd 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -69,7 +69,7 @@ const privValJSON = `{ const genesisJSON = `{ "app_hash": "", - "chain_id": "test-chain-Ppk1h3", + "chain_id": "test_chain_id", "genesis_time": "0001-01-01T00:00:00.000Z", "validators": [ { @@ -82,7 +82,6 @@ const genesisJSON = `{ } ], "app_options": { - "chain_id": "test_chain_id", "accounts": [{ "pub_key": { "type": "ed25519", diff --git a/demo/data/chain1/genesis.json b/demo/data/chain1/genesis.json index 4b9ab3079ab3..d50161a5aad8 100644 --- a/demo/data/chain1/genesis.json +++ b/demo/data/chain1/genesis.json @@ -13,7 +13,6 @@ } ], "app_options": { - "chain_id": "test_chain_1", "accounts": [ { "pub_key": { diff --git a/demo/data/chain2/genesis.json b/demo/data/chain2/genesis.json index 2079970346b0..c53461756202 100644 --- a/demo/data/chain2/genesis.json +++ b/demo/data/chain2/genesis.json @@ -13,7 +13,6 @@ } ], "app_options": { - "chain_id": "test_chain_2", "accounts": [ { "pub_key": { diff --git a/docs/guide/basecoin-tool.md b/docs/guide/basecoin-tool.md index 7046093d9c17..8d87e43f9803 100644 --- a/docs/guide/basecoin-tool.md +++ b/docs/guide/basecoin-tool.md @@ -81,7 +81,7 @@ Now we can make a `genesis.json` file and add an account with our public key: ```json [ - "base/chainID", "example-chain", + "base/chain_id", "example-chain", "base/account", { "pub_key": [1, "43AA6C88034F9EB8D2717CA4BBFCBA745EFF19B13EFCD6F339EDBAAAFCD2F7B3"], "coins": [ @@ -95,7 +95,7 @@ Now we can make a `genesis.json` file and add an account with our public key: ``` Here we've granted ourselves `1000000000` units of the `gold` token. -Note that we've also set the `base/chainID` to be `example-chain`. +Note that we've also set the `base/chain_id` to be `example-chain`. All transactions must therefore include the `--chain_id example-chain` in order to make sure they are valid for this chain. Previously, we didn't need this flag because we were using the default chain ID ("test_chain_id"). Now that we're using a custom chain, we need to specify the chain explicitly on the command line. diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index 833b18f86df2..9c76544bc54f 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -20,7 +20,7 @@ func TestCounterPlugin(t *testing.T) { eyesCli := eyescli.NewLocalClient("", 0) chainID := "test_chain_id" bcApp := app.NewBasecoin(eyesCli) - bcApp.SetOption("base/chainID", chainID) + bcApp.SetOption("base/chain_id", chainID) // t.Log(bcApp.Info()) // Add Counter plugin diff --git a/tests/tmsp/tmsp_test.go b/tests/tmsp/tmsp_test.go index 309af1a69708..eec105deda15 100644 --- a/tests/tmsp/tmsp_test.go +++ b/tests/tmsp/tmsp_test.go @@ -18,7 +18,7 @@ func TestSendTx(t *testing.T) { eyesCli := eyescli.NewLocalClient("", 0) chainID := "test_chain_id" bcApp := app.NewBasecoin(eyesCli) - bcApp.SetOption("base/chainID", chainID) + bcApp.SetOption("base/chain_id", chainID) // t.Log(bcApp.Info()) test1PrivAcc := types.PrivAccountFromSecret("test1") @@ -64,7 +64,7 @@ func TestSequence(t *testing.T) { eyesCli := eyescli.NewLocalClient("", 0) chainID := "test_chain_id" bcApp := app.NewBasecoin(eyesCli) - bcApp.SetOption("base/chainID", chainID) + bcApp.SetOption("base/chain_id", chainID) // t.Log(bcApp.Info()) // Get the test account