arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/api/txshistory.go
api/txshistory.goRaw
 1package api
 2
 3import (
 4	"net/http"
 5
 6	"github.com/gin-gonic/gin"
 7)
 8
 9func getHistoryTxs(c *gin.Context) {
10	// Get query parameters
11	tokenID, addr, bjj, idx, err := parseAccountFilters(c)
12	if err != nil {
13		retBadReq(err, c)
14		return
15	}
16	// BatchNum
17	batchNum, err := parseQueryUint("batchNum", nil, 0, maxUint32, c)
18	if err != nil {
19		retBadReq(err, c)
20		return
21	}
22	// TxType
23	txType, err := parseQueryTxType(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
35	// Fetch txs from historyDB
36	txs, pagination, err := h.GetHistoryTxs(
37		addr, bjj, tokenID, idx, batchNum, txType, fromItem, limit, order,
38	)
39	if err != nil {
40		retSQLErr(err, c)
41		return
42	}
43
44	// Build succesfull response
45	apiTxs := historyTxsToAPI(txs)
46	c.JSON(http.StatusOK, &historyTxsAPI{
47		Txs:        apiTxs,
48		Pagination: pagination,
49	})
50}