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.
 
 
 

71 lines
1.4 KiB

package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/hermeznetwork/hermez-node/db/historydb"
)
func (a *API) getHistoryTxs(c *gin.Context) {
// Get query parameters
tokenID, addr, bjj, fromIdx, toIdx, err := parseTxsHistoryFilters(c)
if err != nil {
retBadReq(err, c)
return
}
// BatchNum
batchNum, err := parseQueryUint("batchNum", nil, 0, maxUint32, c)
if err != nil {
retBadReq(err, c)
return
}
// TxType
txType, err := parseQueryTxType(c)
if err != nil {
retBadReq(err, c)
return
}
// Pagination
fromItem, order, limit, err := parsePagination(c)
if err != nil {
retBadReq(err, c)
return
}
// Fetch txs from historyDB
txs, pendingItems, err := a.h.GetTxsAPI(
addr, bjj, tokenID, fromIdx, toIdx, batchNum, txType, fromItem, limit, order,
)
if err != nil {
retSQLErr(err, c)
return
}
// Build successful response
type txsResponse struct {
Txs []historydb.TxAPI `json:"transactions"`
PendingItems uint64 `json:"pendingItems"`
}
c.JSON(http.StatusOK, &txsResponse{
Txs: txs,
PendingItems: pendingItems,
})
}
func (a *API) getHistoryTx(c *gin.Context) {
// Get TxID
txID, err := parseParamTxID(c)
if err != nil {
retBadReq(err, c)
return
}
// Fetch tx from historyDB
tx, err := a.h.GetTxAPI(txID)
if err != nil {
retSQLErr(err, c)
return
}
// Build successful response
c.JSON(http.StatusOK, tx)
}