OSDN Git Service

Revert "update master (#487)" (#518)
[bytom/bytom.git] / types / genesis.go
1 package types
2
3 import (
4         "encoding/json"
5         "time"
6
7         "github.com/tendermint/go-wire/data"
8         cmn "github.com/tendermint/tmlibs/common"
9 )
10
11 //------------------------------------------------------------
12 // we store the gendoc in the db
13
14 var GenDocKey = []byte("GenDocKey")
15
16 //------------------------------------------------------------
17 // core types for a genesis definition
18 type GenesisDoc struct {
19         GenesisTime time.Time  `json:"genesis_time"`
20         ChainID     string     `json:"chain_id"`
21         PrivateKey  string     `json:"private_key"`
22         AppHash     data.Bytes `json:"app_hash"`
23 }
24
25 // Utility method for saving GenensisDoc as JSON file.
26 func (genDoc *GenesisDoc) SaveAs(file string) error {
27         genDocBytes, err := json.Marshal(genDoc)
28         if err != nil {
29                 return err
30         }
31         return cmn.WriteFile(file, genDocBytes, 0644)
32 }
33
34 //------------------------------------------------------------
35 // Make genesis state from file
36
37 func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
38         genDoc := GenesisDoc{}
39         err := json.Unmarshal(jsonBlob, &genDoc)
40         return &genDoc, err
41 }