diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index ddf67b98..e99b8609 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -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 } diff --git a/types/genesis.go b/types/genesis.go index 721bc098..8698dacb 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -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 +}