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. "time"
  4. . "github.com/tendermint/go-common"
  5. "github.com/tendermint/go-crypto"
  6. "github.com/tendermint/go-wire"
  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 := wire.JSONBytes(genDoc)
  27. return WriteFile(file, genDocBytes, 0644)
  28. }
  29. //------------------------------------------------------------
  30. // Make genesis state from file
  31. func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) {
  32. var err error
  33. wire.ReadJSONPtr(&genState, jsonBlob, &err)
  34. if err != nil {
  35. Exit(Fmt("Couldn't read GenesisDoc: %v", err))
  36. }
  37. return
  38. }