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

package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/hermeznetwork/hermez-node/db/historydb"
)
func (a *API) getAccount(c *gin.Context) {
// Get Addr
idx, err := parseParamIdx(c)
if err != nil {
retBadReq(err, c)
return
}
apiAccount, err := a.h.GetAccountAPI(*idx)
if err != nil {
retSQLErr(err, c)
return
}
c.JSON(http.StatusOK, apiAccount)
}
func (a *API) getAccounts(c *gin.Context) {
// Account filters
tokenIDs, addr, bjj, err := parseAccountFilters(c)
if err != nil {
retBadReq(err, c)
return
}
// Pagination
fromItem, order, limit, err := parsePagination(c)
if err != nil {
retBadReq(err, c)
return
}
// Fetch Accounts from historyDB
apiAccounts, pendingItems, err := a.h.GetAccountsAPI(tokenIDs, addr, bjj, fromItem, limit, order)
if err != nil {
retSQLErr(err, c)
return
}
// Build successful response
type accountResponse struct {
Accounts []historydb.AccountAPI `json:"accounts"`
PendingItems uint64 `json:"pendingItems"`
}
c.JSON(http.StatusOK, &accountResponse{
Accounts: apiAccounts,
PendingItems: pendingItems,
})
}