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.

75 lines
2.2 KiB

  1. package api
  2. import (
  3. "errors"
  4. "github.com/gin-gonic/gin"
  5. "github.com/hermeznetwork/hermez-node/db/historydb"
  6. "github.com/hermeznetwork/hermez-node/db/l2db"
  7. "github.com/hermeznetwork/hermez-node/db/statedb"
  8. )
  9. var h *historydb.HistoryDB
  10. // var s *statedb.StateDB // Not 100% sure if this is needed
  11. // var l2 *l2db.L2DB
  12. // SetAPIEndpoints sets the endpoints and the appropriate handlers, but doesn't start the server
  13. func SetAPIEndpoints(
  14. coordinatorEndpoints, explorerEndpoints bool,
  15. server *gin.Engine,
  16. hdb *historydb.HistoryDB,
  17. sdb *statedb.StateDB,
  18. l2db *l2db.L2DB,
  19. ) error {
  20. // Check input
  21. // TODO: is stateDB only needed for explorer endpoints or for both?
  22. if coordinatorEndpoints && l2db == nil {
  23. return errors.New("cannot serve Coordinator endpoints without L2DB")
  24. }
  25. if explorerEndpoints && hdb == nil {
  26. return errors.New("cannot serve Explorer endpoints without HistoryDB")
  27. }
  28. h = hdb
  29. // s = sdb
  30. // l2 = l2db
  31. // Add coordinator endpoints
  32. if coordinatorEndpoints {
  33. // Account
  34. server.POST("/account-creation-authorization", postAccountCreationAuth)
  35. server.GET("/account-creation-authorization/:hermezEthereumAddress", getAccountCreationAuth)
  36. // Transaction
  37. server.POST("/transactions-pool", postPoolTx)
  38. server.POST("/transactions-pool/:id", getPoolTx)
  39. }
  40. // Add explorer endpoints
  41. if explorerEndpoints {
  42. // Account
  43. server.GET("/accounts", getAccounts)
  44. server.GET("/accounts/:hermezEthereumAddress/:accountIndex", getAccount)
  45. server.GET("/exits", getExits)
  46. server.GET("/exits/:batchNum/:accountIndex", getExit)
  47. // Transaction
  48. server.GET("/transactions-history", getHistoryTxs)
  49. server.GET("/transactions-history/:id", getHistoryTx)
  50. // Status
  51. server.GET("/batches", getBatches)
  52. server.GET("/batches/:batchNum", getBatch)
  53. server.GET("/full-batches/:batchNum", getFullBatch)
  54. server.GET("/slots", getSlots)
  55. server.GET("/bids", getBids)
  56. server.GET("/next-forgers", getNextForgers)
  57. server.GET("/state", getState)
  58. server.GET("/config", getConfig)
  59. server.GET("/tokens", getTokens)
  60. server.GET("/tokens/:id", getToken)
  61. server.GET("/recommendedFee", getRecommendedFee)
  62. server.GET("/coordinators", getCoordinators)
  63. server.GET("/coordinators/:forgerAddr", getCoordinator)
  64. }
  65. return nil
  66. }