add plugin_options and fix tests
This commit is contained in:
parent
03ea00f1e6
commit
09433299ca
42
CHANGELOG.md
42
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:
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, nil, errors.Wrap(err, "unmarshaling genesis file")
|
||||
return nil, errors.Wrap(err, "unmarshaling genesis file")
|
||||
}
|
||||
return tmGenesis, appGenesis.AppOptions, nil
|
||||
|
||||
pluginOpts, err := parseGenesisList(genDoc.AppOptions.PluginOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
genDoc.AppOptions.pluginOptions = pluginOpts
|
||||
return genDoc, nil
|
||||
}
|
||||
|
||||
func parseGenesisList(kvz_ []json.RawMessage) (kvz []keyValue, err error) {
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
}
|
||||
],
|
||||
"app_options": {
|
||||
"chain_id": "test_chain_1",
|
||||
"accounts": [
|
||||
{
|
||||
"pub_key": {
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
}
|
||||
],
|
||||
"app_options": {
|
||||
"chain_id": "test_chain_2",
|
||||
"accounts": [
|
||||
{
|
||||
"pub_key": {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue