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.

48 lines
1.2 KiB

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