You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

  1. package types
  2. import (
  3. "encoding/json"
  4. "time"
  5. "github.com/tendermint/go-crypto"
  6. "github.com/tendermint/go-wire/data"
  7. cmn "github.com/tendermint/tmlibs/common"
  8. )
  9. //------------------------------------------------------------
  10. // we store the gendoc in the db
  11. var GenDocKey = []byte("GenDocKey")
  12. //------------------------------------------------------------
  13. // core types for a genesis definition
  14. type GenesisValidator struct {
  15. PubKey crypto.PubKey `json:"pub_key"`
  16. Amount int64 `json:"amount"`
  17. Name string `json:"name"`
  18. }
  19. type GenesisDoc struct {
  20. GenesisTime time.Time `json:"genesis_time"`
  21. ChainID string `json:"chain_id"`
  22. Validators []GenesisValidator `json:"validators"`
  23. AppHash data.Bytes `json:"app_hash"`
  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. // Make genesis state from file
  35. func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
  36. genDoc := GenesisDoc{}
  37. err := json.Unmarshal(jsonBlob, &genDoc)
  38. return &genDoc, err
  39. }