mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
ParseGenesisFile -> types.GenesisDocFromFile
This commit is contained in:
parent
e4caf96bcb
commit
12c084c8c0
@ -2,10 +2,8 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/node"
|
"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)")
|
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:
|
// Users wishing to:
|
||||||
// * Use an external signer for their validators
|
// * Use an external signer for their validators
|
||||||
// * Supply an in-proc abci app
|
// * Supply an in-proc abci app
|
||||||
@ -82,7 +65,7 @@ func runNode(cmd *cobra.Command, args []string) error {
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
genDoc, err := ParseGenesisFile(genDocFile)
|
genDoc, err := types.GenesisDocFromFile(genDocFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,11 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/go-wire/data"
|
"github.com/tendermint/go-wire/data"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
@ -51,8 +54,25 @@ func (genDoc *GenesisDoc) ValidatorHash() []byte {
|
|||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
// Make genesis state from file
|
// Make genesis state from file
|
||||||
|
|
||||||
|
// GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc.
|
||||||
func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
|
func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
|
||||||
genDoc := GenesisDoc{}
|
genDoc := GenesisDoc{}
|
||||||
err := json.Unmarshal(jsonBlob, &genDoc)
|
err := json.Unmarshal(jsonBlob, &genDoc)
|
||||||
return &genDoc, err
|
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…
x
Reference in New Issue
Block a user