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.

94 lines
3.3 KiB

  1. // Copyright 2017-2018 DERO Project. All rights reserved.
  2. // Use of this source code in any form is governed by RESEARCH license.
  3. // license can be found in the LICENSE file.
  4. // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
  5. //
  6. //
  7. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  8. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  10. // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  13. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  14. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  15. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. package rpcserver
  17. // get block template handler not implemented
  18. //import "fmt"
  19. import "context"
  20. //import "log"
  21. //import "net/http"
  22. import "github.com/intel-go/fastjson"
  23. import "github.com/osamingo/jsonrpc"
  24. import "github.com/arnaucode/derosuite/config"
  25. import "github.com/arnaucode/derosuite/globals"
  26. /*
  27. {
  28. "id": "0",
  29. "jsonrpc": "2.0",
  30. "result": {
  31. "alt_blocks_count": 5,
  32. "difficulty": 972165250,
  33. "grey_peerlist_size": 2280,
  34. "height": 993145,
  35. "incoming_connections_count": 0,
  36. "outgoing_connections_count": 8,
  37. "status": "OK",
  38. "target": 60,
  39. "target_height": 993137,
  40. "testnet": false,
  41. "top_block_hash": "",
  42. "tx_count": 564287,
  43. "tx_pool_size": 45,
  44. "white_peerlist_size": 529
  45. }
  46. }*/
  47. type (
  48. GetInfo_Handler struct{}
  49. GetInfo_Params struct{} // no params
  50. GetInfo_Result struct {
  51. Alt_Blocks_Count uint64 `json:"alt_blocks_count"`
  52. Difficulty uint64 `json:"difficulty"`
  53. Grey_PeerList_Size uint64 `json:"grey_peerlist_size"`
  54. Height uint64 `json:"height"`
  55. Incoming_connections_count uint64 `json:"incoming_connections_count"`
  56. Outgoing_connections_count uint64 `json:"outgoing_connections_count"`
  57. Target uint64 `json:"target"`
  58. Target_Height uint64 `json:"target_height"`
  59. Testnet bool `json:"testnet"`
  60. Top_block_hash string `json:"top_block_hash"`
  61. Tx_count uint64 `json:"tx_count"`
  62. Tx_pool_size uint64 `json:"tx_pool_size"`
  63. White_peerlist_size uint64 `json:"white_peerlist_size"`
  64. Status string `json:"status"`
  65. }
  66. )
  67. // TODO
  68. func (h GetInfo_Handler) ServeJSONRPC(c context.Context, params *fastjson.RawMessage) (interface{}, *jsonrpc.Error) {
  69. var result GetInfo_Result
  70. top_id := chain.Get_Top_ID()
  71. result.Difficulty = chain.Get_Difficulty_At_Block(top_id)
  72. result.Height = chain.Get_Height() - 1
  73. result.Status = "OK"
  74. result.Top_block_hash = top_id.String()
  75. result.Target = config.BLOCK_TIME
  76. result.Target_Height = chain.Get_Height()
  77. result.Tx_pool_size = uint64(len(chain.Mempool.Mempool_List_TX()))
  78. if globals.Config.Name != config.Mainnet.Name { // anything other than mainnet is testnet at this point in time
  79. result.Testnet = true
  80. }
  81. return result, nil
  82. }