Browse Source

ParseGenesisFile -> types.GenesisDocFromFile

pull/563/head
Ethan Buchman 7 years ago
parent
commit
12c084c8c0
2 changed files with 21 additions and 18 deletions
  1. +1
    -18
      cmd/tendermint/commands/run_node.go
  2. +20
    -0
      types/genesis.go

+ 1
- 18
cmd/tendermint/commands/run_node.go View File

@ -2,10 +2,8 @@ package commands
import (
"fmt"
"io/ioutil"
"time"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/node"
@ -49,21 +47,6 @@ func AddNodeFlags(cmd *cobra.Command) {
cmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange (dev feature)")
}
func ParseGenesisFile(genDocFile string) (*types.GenesisDoc, error) {
jsonBlob, err := ioutil.ReadFile(genDocFile)
if err != nil {
return nil, errors.Wrap(err, "Couldn't read GenesisDoc file")
}
genDoc, err := types.GenesisDocFromJSON(jsonBlob)
if err != nil {
return nil, errors.Wrap(err, "Error reading GenesisDoc")
}
if genDoc.ChainID == "" {
return nil, errors.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile)
}
return genDoc, nil
}
// Users wishing to:
// * Use an external signer for their validators
// * Supply an in-proc abci app
@ -82,7 +65,7 @@ func runNode(cmd *cobra.Command, args []string) error {
time.Sleep(time.Second)
}
genDoc, err := ParseGenesisFile(genDocFile)
genDoc, err := types.GenesisDocFromFile(genDocFile)
if err != nil {
return err
}


+ 20
- 0
types/genesis.go View File

@ -2,8 +2,11 @@ package types
import (
"encoding/json"
"io/ioutil"
"time"
"github.com/pkg/errors"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
@ -51,8 +54,25 @@ func (genDoc *GenesisDoc) ValidatorHash() []byte {
//------------------------------------------------------------
// Make genesis state from file
// GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc.
func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
genDoc := GenesisDoc{}
err := json.Unmarshal(jsonBlob, &genDoc)
return &genDoc, err
}
// GenesisDocFromFile reads JSON data from a file and unmarshalls it into a GenesisDoc.
func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) {
jsonBlob, err := ioutil.ReadFile(genDocFile)
if err != nil {
return nil, errors.Wrap(err, "Couldn't read GenesisDoc file")
}
genDoc, err := GenesisDocFromJSON(jsonBlob)
if err != nil {
return nil, errors.Wrap(err, "Error reading GenesisDoc")
}
if genDoc.ChainID == "" {
return nil, errors.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile)
}
return genDoc, nil
}

Loading…
Cancel
Save