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.

139 lines
3.4 KiB

  1. package core
  2. import (
  3. rpc "github.com/tendermint/go-rpc/server"
  4. "github.com/tendermint/go-rpc/types"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. )
  7. var Routes = map[string]*rpc.RPCFunc{
  8. // subscribe/unsubscribe are reserved for websocket events.
  9. "subscribe": rpc.NewWSRPCFunc(SubscribeResult, "event"),
  10. "unsubscribe": rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
  11. "status": rpc.NewRPCFunc(StatusResult, ""),
  12. "net_info": rpc.NewRPCFunc(NetInfoResult, ""),
  13. "dial_seeds": rpc.NewRPCFunc(DialSeedsResult, "seeds"),
  14. "blockchain": rpc.NewRPCFunc(BlockchainInfoResult, "minHeight,maxHeight"),
  15. "genesis": rpc.NewRPCFunc(GenesisResult, ""),
  16. "block": rpc.NewRPCFunc(BlockResult, "height"),
  17. "validators": rpc.NewRPCFunc(ValidatorsResult, ""),
  18. "dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
  19. "broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
  20. "broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
  21. "unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
  22. "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
  23. }
  24. func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  25. if r, err := Subscribe(wsCtx, event); err != nil {
  26. return nil, err
  27. } else {
  28. return r, nil
  29. }
  30. }
  31. func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  32. if r, err := Unsubscribe(wsCtx, event); err != nil {
  33. return nil, err
  34. } else {
  35. return r, nil
  36. }
  37. }
  38. func StatusResult() (ctypes.TMResult, error) {
  39. if r, err := Status(); err != nil {
  40. return nil, err
  41. } else {
  42. return r, nil
  43. }
  44. }
  45. func NetInfoResult() (ctypes.TMResult, error) {
  46. if r, err := NetInfo(); err != nil {
  47. return nil, err
  48. } else {
  49. return r, nil
  50. }
  51. }
  52. func DialSeedsResult(seeds []string) (ctypes.TMResult, error) {
  53. if r, err := DialSeeds(seeds); err != nil {
  54. return nil, err
  55. } else {
  56. return r, nil
  57. }
  58. }
  59. func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
  60. if r, err := BlockchainInfo(min, max); err != nil {
  61. return nil, err
  62. } else {
  63. return r, nil
  64. }
  65. }
  66. func GenesisResult() (ctypes.TMResult, error) {
  67. if r, err := Genesis(); err != nil {
  68. return nil, err
  69. } else {
  70. return r, nil
  71. }
  72. }
  73. func BlockResult(height int) (ctypes.TMResult, error) {
  74. if r, err := Block(height); err != nil {
  75. return nil, err
  76. } else {
  77. return r, nil
  78. }
  79. }
  80. func ValidatorsResult() (ctypes.TMResult, error) {
  81. if r, err := Validators(); err != nil {
  82. return nil, err
  83. } else {
  84. return r, nil
  85. }
  86. }
  87. func DumpConsensusStateResult() (ctypes.TMResult, error) {
  88. if r, err := DumpConsensusState(); err != nil {
  89. return nil, err
  90. } else {
  91. return r, nil
  92. }
  93. }
  94. func UnconfirmedTxsResult() (ctypes.TMResult, error) {
  95. if r, err := UnconfirmedTxs(); err != nil {
  96. return nil, err
  97. } else {
  98. return r, nil
  99. }
  100. }
  101. func BroadcastTxSyncResult(tx []byte) (ctypes.TMResult, error) {
  102. if r, err := BroadcastTxSync(tx); err != nil {
  103. return nil, err
  104. } else {
  105. return r, nil
  106. }
  107. }
  108. func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
  109. if r, err := BroadcastTxAsync(tx); err != nil {
  110. return nil, err
  111. } else {
  112. return r, nil
  113. }
  114. }
  115. func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
  116. if r, err := UnsafeSetConfig(typ, key, value); err != nil {
  117. return nil, err
  118. } else {
  119. return r, nil
  120. }
  121. }