add plugin_options and fix tests
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
+33
-20
@@ -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) {
|
||||
|
||||
Vendored
+20
-17
@@ -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"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user