mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
API add pending withdraws filter on GET /exits
This commit is contained in:
@@ -22,6 +22,12 @@ func getExits(c *gin.Context) {
|
|||||||
retBadReq(err, c)
|
retBadReq(err, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// OnlyPendingWithdraws
|
||||||
|
onlyPendingWithdraws, err := parseQueryBool("onlyPendingWithdraws", nil, c)
|
||||||
|
if err != nil {
|
||||||
|
retBadReq(err, c)
|
||||||
|
return
|
||||||
|
}
|
||||||
// Pagination
|
// Pagination
|
||||||
fromItem, order, limit, err := parsePagination(c)
|
fromItem, order, limit, err := parsePagination(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -31,7 +37,7 @@ func getExits(c *gin.Context) {
|
|||||||
|
|
||||||
// Fetch exits from historyDB
|
// Fetch exits from historyDB
|
||||||
exits, pagination, err := h.GetExitsAPI(
|
exits, pagination, err := h.GetExitsAPI(
|
||||||
addr, bjj, tokenID, idx, batchNum, fromItem, limit, order,
|
addr, bjj, tokenID, idx, batchNum, onlyPendingWithdraws, fromItem, limit, order,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
retSQLErr(err, c)
|
retSQLErr(err, c)
|
||||||
|
|||||||
@@ -190,6 +190,22 @@ func TestGetExits(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertExitAPIs(t, batchNumExits, fetchedExits)
|
assertExitAPIs(t, batchNumExits, fetchedExits)
|
||||||
|
// OnlyPendingWithdraws
|
||||||
|
fetchedExits = []testExit{}
|
||||||
|
limit = 7
|
||||||
|
path = fmt.Sprintf(
|
||||||
|
"%s?&onlyPendingWithdraws=%t&limit=%d&fromItem=",
|
||||||
|
endpoint, true, limit,
|
||||||
|
)
|
||||||
|
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
pendingExits := []testExit{}
|
||||||
|
for i := 0; i < len(tc.exits); i++ {
|
||||||
|
if tc.exits[i].InstantWithdrawn == nil && tc.exits[i].DelayedWithdrawn == nil {
|
||||||
|
pendingExits = append(pendingExits, tc.exits[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertExitAPIs(t, pendingExits, fetchedExits)
|
||||||
// Multiple filters
|
// Multiple filters
|
||||||
fetchedExits = []testExit{}
|
fetchedExits = []testExit{}
|
||||||
limit = 1
|
limit = 1
|
||||||
|
|||||||
@@ -286,6 +286,12 @@ paths:
|
|||||||
required: false
|
required: false
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/BatchNum'
|
$ref: '#/components/schemas/BatchNum'
|
||||||
|
- name: onlyPendingWithdraws
|
||||||
|
in: query
|
||||||
|
description: Get exits with pending withdrawals.
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: boolean
|
||||||
- name: fromItem
|
- name: fromItem
|
||||||
in: query
|
in: query
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@@ -911,8 +911,8 @@ func (hdb *HistoryDB) GetExitAPI(batchNum *uint, idx *common.Idx) (*ExitAPI, err
|
|||||||
|
|
||||||
// GetExitsAPI returns a list of exits from the DB and pagination info
|
// GetExitsAPI returns a list of exits from the DB and pagination info
|
||||||
func (hdb *HistoryDB) GetExitsAPI(
|
func (hdb *HistoryDB) GetExitsAPI(
|
||||||
ethAddr *ethCommon.Address, bjj *babyjub.PublicKey,
|
ethAddr *ethCommon.Address, bjj *babyjub.PublicKey, tokenID *common.TokenID,
|
||||||
tokenID *common.TokenID, idx *common.Idx, batchNum *uint,
|
idx *common.Idx, batchNum *uint, onlyPendingWithdraws *bool,
|
||||||
fromItem, limit *uint, order string,
|
fromItem, limit *uint, order string,
|
||||||
) ([]ExitAPI, *db.Pagination, error) {
|
) ([]ExitAPI, *db.Pagination, error) {
|
||||||
if ethAddr != nil && bjj != nil {
|
if ethAddr != nil && bjj != nil {
|
||||||
@@ -975,6 +975,18 @@ func (hdb *HistoryDB) GetExitsAPI(
|
|||||||
args = append(args, batchNum)
|
args = append(args, batchNum)
|
||||||
nextIsAnd = true
|
nextIsAnd = true
|
||||||
}
|
}
|
||||||
|
// onlyPendingWithdraws
|
||||||
|
if onlyPendingWithdraws != nil {
|
||||||
|
if *onlyPendingWithdraws {
|
||||||
|
if nextIsAnd {
|
||||||
|
queryStr += "AND "
|
||||||
|
} else {
|
||||||
|
queryStr += "WHERE "
|
||||||
|
}
|
||||||
|
queryStr += "(exit_tree.instant_withdrawn IS NULL AND exit_tree.delayed_withdrawn IS NULL) "
|
||||||
|
nextIsAnd = true
|
||||||
|
}
|
||||||
|
}
|
||||||
if fromItem != nil {
|
if fromItem != nil {
|
||||||
if nextIsAnd {
|
if nextIsAnd {
|
||||||
queryStr += "AND "
|
queryStr += "AND "
|
||||||
|
|||||||
Reference in New Issue
Block a user