Allow genesis file

This commit is contained in:
Jae Kwon 2016-03-22 15:44:58 -07:00
parent b4b5d7b6c9
commit c134fa7efd
2 changed files with 40 additions and 4 deletions

View File

@ -1,7 +1,9 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/tendermint/basecoin/app"
. "github.com/tendermint/go-common"
@ -13,6 +15,7 @@ func main() {
addrPtr := flag.String("address", "tcp://0.0.0.0:46658", "Listen address")
eyesPtr := flag.String("eyes", "tcp://0.0.0.0:46659", "MerkleEyes address")
genFilePath := flag.String("genesis", "", "Genesis file, if any")
flag.Parse()
// Connect to MerkleEyes
@ -24,6 +27,15 @@ func main() {
// Create Basecoin app
app := app.NewBasecoin(eyesCli)
// If genesis file was specified, set key-value options
if *genFilePath != "" {
kvz := loadGenesis(*genFilePath)
for _, kv := range kvz {
log := app.SetOption(kv.Key, kv.Value)
fmt.Println(Fmt("Set %v=%v. Log: %v", kv.Key, kv.Value, log))
}
}
// Start the listener
svr, err := server.NewServer(*addrPtr, app)
if err != nil {
@ -37,3 +49,23 @@ func main() {
})
}
//----------------------------------------
type KeyValue struct {
Key string `json:"key"`
Value string `json:"value"`
}
func loadGenesis(filePath string) (kvz []KeyValue) {
bytes, err := ReadFile(filePath)
if err != nil {
Exit("loading genesis file: " + err.Error())
}
fmt.Println(">>", string(bytes))
err = json.Unmarshal(bytes, &kvz)
if err != nil {
Exit("parsing genesis file: " + err.Error())
}
return
}

View File

@ -1,6 +1,10 @@
{"Accounts":[
[
{
"PubKey":[1,"31F4BF201D3606E33707B098B1EEA7D03A4BB9E9795F0116ED1A038D7B5A6BDE"],
"Account":{"Sequence":0,"Balance":2100000000000000}
"key": "chainID",
"value": "test_chain_id"
},
{
"key": "account",
"value": "{\"pub_key\":[1,\"3E8A80E5412FD1711995D5888F5FA2EFB26EDD0970F1E27CE0B55CD237439E18\"],\"balance\":1000}"
}
]}
]