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.

58 lines
1.5 KiB

  1. package core
  2. import (
  3. "fmt"
  4. "strconv"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. func Status() (*ctypes.ResultStatus, error) {
  9. latestHeight := blockStore.Height()
  10. var (
  11. latestBlockMeta *types.BlockMeta
  12. latestBlockHash []byte
  13. latestAppHash []byte
  14. latestBlockTime int64
  15. )
  16. if latestHeight != 0 {
  17. latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
  18. latestBlockHash = latestBlockMeta.Hash
  19. latestAppHash = latestBlockMeta.Header.AppHash
  20. latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
  21. }
  22. return &ctypes.ResultStatus{
  23. NodeInfo: p2pSwitch.NodeInfo(),
  24. PubKey: privValidator.PubKey,
  25. LatestBlockHash: latestBlockHash,
  26. LatestAppHash: latestAppHash,
  27. LatestBlockHeight: latestHeight,
  28. LatestBlockTime: latestBlockTime}, nil
  29. }
  30. func UnsafeSetConfig(typ, key, value string) (*ctypes.ResultUnsafeSetConfig, error) {
  31. switch typ {
  32. case "string":
  33. config.Set(key, value)
  34. case "int":
  35. val, err := strconv.Atoi(value)
  36. if err != nil {
  37. return nil, fmt.Errorf("non-integer value found. key:%s; value:%s; err:%v", key, value, err)
  38. }
  39. config.Set(key, val)
  40. case "bool":
  41. switch value {
  42. case "true":
  43. config.Set(key, true)
  44. case "false":
  45. config.Set(key, false)
  46. default:
  47. return nil, fmt.Errorf("bool value must be true or false. got %s", value)
  48. }
  49. default:
  50. return nil, fmt.Errorf("Unknown type %s", typ)
  51. }
  52. return &ctypes.ResultUnsafeSetConfig{}, nil
  53. }