Refactor api txs

This commit is contained in:
Arnau B
2020-10-26 16:47:16 +01:00
parent decc4996ee
commit a329d894d2
18 changed files with 1452 additions and 1272 deletions

View File

@@ -4,6 +4,8 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/hermeznetwork/hermez-node/db"
"github.com/hermeznetwork/hermez-node/db/historydb"
)
func getHistoryTxs(c *gin.Context) {
@@ -42,9 +44,29 @@ func getHistoryTxs(c *gin.Context) {
}
// Build succesfull response
apiTxs := historyTxsToAPI(txs)
c.JSON(http.StatusOK, &historyTxsAPI{
Txs: apiTxs,
type txsResponse struct {
Txs []historydb.TxAPI `json:"transactions"`
Pagination *db.Pagination `json:"pagination"`
}
c.JSON(http.StatusOK, &txsResponse{
Txs: txs,
Pagination: pagination,
})
}
func getHistoryTx(c *gin.Context) {
// Get TxID
txID, err := parseParamTxID(c)
if err != nil {
retBadReq(err, c)
return
}
// Fetch tx from historyDB
tx, err := h.GetHistoryTx(txID)
if err != nil {
retSQLErr(err, c)
return
}
// Build succesfull response
c.JSON(http.StatusOK, tx)
}