cashless2ecash

cashless2ecash: pay with cards for digital cash (experimental)
Log | Files | Refs | README

commit 199b5b08d75f9b2538baed1a7cf2a640b02e6940
parent d99f17c546b2ba144b6ce9f2abfff5254af5b16e
Author: Joel-Haeberli <haebu@rubigen.ch>
Date:   Wed,  5 Jun 2024 07:38:10 +0200

fix: wire-gateway-api

Diffstat:
Mc2ec/api-wire-gateway.go | 2+-
Mc2ec/db-postgres.go | 23+++++++++++++++++------
2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/c2ec/api-wire-gateway.go b/c2ec/api-wire-gateway.go @@ -308,7 +308,7 @@ func historyIncoming(res http.ResponseWriter, req *http.Request) { } } - var start = -1 // read most recent entries by default + var start = 0 // read most recent entries by default if startPtr, accepted := AcceptOptionalParamOrWriteResponse( "start", strconv.Atoi, req, res, ); accepted { diff --git a/c2ec/db-postgres.go b/c2ec/db-postgres.go @@ -498,15 +498,22 @@ func (db *C2ECPostgres) SetRetryCounter(withdrawalId int, retryCounter int) erro // wire gateway api. func (db *C2ECPostgres) GetConfirmedWithdrawals(start int, delta int, since time.Time) ([]*Withdrawal, error) { - query := PS_CONFIRMED_TRANSACTIONS_ASC + // +d / +s + query := "SELECT * FROM c2ec.withdrawal WHERE confirmed_row_id > $1 ORDER BY confirmed_row_id ASC LIMIT $2" // PS_CONFIRMED_TRANSACTIONS_ASC if delta < 0 { - query = PS_CONFIRMED_TRANSACTIONS_DESC + // d negatives indicates DESC ordering and backwards reading + // -d / +s + query = "SELECT * FROM c2ec.withdrawal WHERE confirmed_row_id < $1 ORDER BY confirmed_row_id DESC LIMIT $2" // PS_CONFIRMED_TRANSACTIONS_DESC if start < 0 { - query = PS_CONFIRMED_TRANSACTIONS_DESC_MAX + // start negative indicates not explicitly given + // since -d is the case here we try reading the latest entries + // -d / -s + query = "SELECT * FROM c2ec.withdrawal WHERE confirmed_row_id < (SELECT MAX(confirmed_row_id) FROM c2ec.withdrawal) ORDER BY confirmed_row_id DESC LIMIT $2" // PS_CONFIRMED_TRANSACTIONS_DESC_MAX } } else { if start < 0 { - query = PS_CONFIRMED_TRANSACTIONS_ASC_MAX + // +d / -s + query = "SELECT * FROM c2ec.withdrawal WHERE confirmed_row_id > $1 ORDER BY confirmed_row_id ASC LIMIT $2" // PS_CONFIRMED_TRANSACTIONS_ASC_MAX } } @@ -519,6 +526,10 @@ func (db *C2ECPostgres) GetConfirmedWithdrawals(start int, delta int, since time offset = 0 } + if start < 0 { + start = 0 + } + LogInfo("postgres", fmt.Sprintf("selected query=%s (\nparameters:\n delta=%d,\n start=%d, limit=%d,\n offset=%d,\n since=%d\n)", query, delta, start, limit, offset, since.Unix())) var row pgx.Rows @@ -530,15 +541,15 @@ func (db *C2ECPostgres) GetConfirmedWithdrawals(start int, delta int, since time row, err = db.pool.Query( db.ctx, query, - limit, offset, + limit, ) } else { row, err = db.pool.Query( db.ctx, query, - limit, offset, + limit, ) }