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

@@ -68,46 +68,6 @@ func getAccountCreationAuth(c *gin.Context) {
c.JSON(http.StatusOK, apiAuth)
}
func postPoolTx(c *gin.Context) {
// Parse body
var receivedTx receivedPoolTx
if err := c.ShouldBindJSON(&receivedTx); err != nil {
retBadReq(err, c)
return
}
// Transform from received to insert format and validate
writeTx, err := receivedTx.toDBWritePoolL2Tx()
if err != nil {
retBadReq(err, c)
return
}
// Insert to DB
if err := l2.AddTx(writeTx); err != nil {
retSQLErr(err, c)
return
}
// Return TxID
c.JSON(http.StatusOK, writeTx.TxID.String())
}
func getPoolTx(c *gin.Context) {
// Get TxID
txID, err := parseParamTxID(c)
if err != nil {
retBadReq(err, c)
return
}
// Fetch tx from l2DB
dbTx, err := l2.GetTx(txID)
if err != nil {
retSQLErr(err, c)
return
}
apiTx := poolL2TxReadToSend(dbTx)
// Build succesfull response
c.JSON(http.StatusOK, apiTx)
}
func getAccounts(c *gin.Context) {
}
@@ -177,24 +137,6 @@ func getExit(c *gin.Context) {
c.JSON(http.StatusOK, apiExits[0])
}
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
}
apiTxs := historyTxsToAPI([]historydb.HistoryTx{*tx})
// Build succesfull response
c.JSON(http.StatusOK, apiTxs[0])
}
func getSlots(c *gin.Context) {
}