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.

56 lines
1.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package api
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "github.com/hermeznetwork/hermez-node/db/historydb"
  6. )
  7. func (a *API) getAccount(c *gin.Context) {
  8. // Get Addr
  9. idx, err := parseParamIdx(c)
  10. if err != nil {
  11. retBadReq(err, c)
  12. return
  13. }
  14. apiAccount, err := a.h.GetAccountAPI(*idx)
  15. if err != nil {
  16. retSQLErr(err, c)
  17. return
  18. }
  19. c.JSON(http.StatusOK, apiAccount)
  20. }
  21. func (a *API) getAccounts(c *gin.Context) {
  22. // Account filters
  23. tokenIDs, addr, bjj, err := parseAccountFilters(c)
  24. if err != nil {
  25. retBadReq(err, c)
  26. return
  27. }
  28. // Pagination
  29. fromItem, order, limit, err := parsePagination(c)
  30. if err != nil {
  31. retBadReq(err, c)
  32. return
  33. }
  34. // Fetch Accounts from historyDB
  35. apiAccounts, pendingItems, err := a.h.GetAccountsAPI(tokenIDs, addr, bjj, fromItem, limit, order)
  36. if err != nil {
  37. retSQLErr(err, c)
  38. return
  39. }
  40. // Build succesfull response
  41. type accountResponse struct {
  42. Accounts []historydb.AccountAPI `json:"accounts"`
  43. PendingItems uint64 `json:"pendingItems"`
  44. }
  45. c.JSON(http.StatusOK, &accountResponse{
  46. Accounts: apiAccounts,
  47. PendingItems: pendingItems,
  48. })
  49. }