2015-11-01 11:34:08 -08:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2017-03-21 14:46:15 -07:00
|
|
|
"encoding/json"
|
2015-11-01 11:34:08 -08:00
|
|
|
"time"
|
|
|
|
|
2017-04-21 15:12:54 -07:00
|
|
|
. "github.com/tendermint/tmlibs/common"
|
2015-11-01 11:34:08 -08:00
|
|
|
"github.com/tendermint/go-crypto"
|
|
|
|
)
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
// we store the gendoc in the db
|
|
|
|
|
|
|
|
var GenDocKey = []byte("GenDocKey")
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
// core types for a genesis definition
|
|
|
|
|
|
|
|
type GenesisValidator struct {
|
2015-12-21 14:48:44 -08:00
|
|
|
PubKey crypto.PubKey `json:"pub_key"`
|
|
|
|
Amount int64 `json:"amount"`
|
|
|
|
Name string `json:"name"`
|
2015-11-01 11:34:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type GenesisDoc struct {
|
|
|
|
GenesisTime time.Time `json:"genesis_time"`
|
|
|
|
ChainID string `json:"chain_id"`
|
|
|
|
Validators []GenesisValidator `json:"validators"`
|
2015-12-01 20:12:01 -08:00
|
|
|
AppHash []byte `json:"app_hash"`
|
2015-11-01 11:34:08 -08:00
|
|
|
}
|
|
|
|
|
2015-12-03 09:51:10 -08:00
|
|
|
// Utility method for saving GenensisDoc as JSON file.
|
|
|
|
func (genDoc *GenesisDoc) SaveAs(file string) error {
|
2017-03-21 14:46:15 -07:00
|
|
|
genDocBytes, err := json.Marshal(genDoc)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-12-04 00:03:09 -08:00
|
|
|
return WriteFile(file, genDocBytes, 0644)
|
2015-12-03 09:51:10 -08:00
|
|
|
}
|
|
|
|
|
2015-11-01 11:34:08 -08:00
|
|
|
//------------------------------------------------------------
|
|
|
|
// Make genesis state from file
|
|
|
|
|
2017-03-21 14:46:15 -07:00
|
|
|
func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
|
|
|
|
genDoc := GenesisDoc{}
|
|
|
|
err := json.Unmarshal(jsonBlob, &genDoc)
|
|
|
|
return &genDoc, err
|
2015-11-01 11:34:08 -08:00
|
|
|
}
|