diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-10-15 10:43:26 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-10-15 10:43:26 +0200 |
commit | eebc030f6cf61d36b80e3273709fd9f254b155c3 (patch) | |
tree | f7e8c80b8aeabdc9067841da0b7be32a367a51f2 /src/exchangedb | |
parent | 5f333f817c0fe4d66d1223833f8b8f7f22ad174c (diff) | |
download | exchange-eebc030f6cf61d36b80e3273709fd9f254b155c3.tar.xz |
add logic to return information about purse refunds in coin histories
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchangedb_transactions.c | 20 | ||||
-rw-r--r-- | src/exchangedb/pg_get_coin_transactions.c | 77 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_common.c | 8 |
3 files changed, 105 insertions, 0 deletions
diff --git a/src/exchangedb/exchangedb_transactions.c b/src/exchangedb/exchangedb_transactions.c index 60b95d6f6..f78393776 100644 --- a/src/exchangedb/exchangedb_transactions.c +++ b/src/exchangedb/exchangedb_transactions.c @@ -131,6 +131,26 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals ( } deposit_fee = pos->details.purse_deposit->deposit_fee; break; + case TALER_EXCHANGEDB_TT_PURSE_REFUND: + /* refunded += pos->refund_amount - pos->refund_fee */ + if (0 > + TALER_amount_add (&refunded, + &refunded, + &pos->details.purse_refund->refund_amount)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (0 > + TALER_amount_add (&spent, + &spent, + &pos->details.purse_refund->refund_fee)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + have_refund = true; + break; case TALER_EXCHANGEDB_TT_RESERVE_OPEN: /* spent += pos->amount_with_fee */ if (0 > diff --git a/src/exchangedb/pg_get_coin_transactions.c b/src/exchangedb/pg_get_coin_transactions.c index 54dce7f6f..b6b892e56 100644 --- a/src/exchangedb/pg_get_coin_transactions.c +++ b/src/exchangedb/pg_get_coin_transactions.c @@ -352,6 +352,63 @@ add_coin_refund (void *cls, * @param num_results the number of results in @a result */ static void +add_coin_purse_refund (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct CoinHistoryContext *chc = cls; + struct PostgresClosure *pg = chc->pg; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund; + struct TALER_EXCHANGEDB_TransactionList *tl; + uint64_t serial_id; + + prefund = GNUNET_new (struct TALER_EXCHANGEDB_PurseRefundListEntry); + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("purse_pub", + &prefund->purse_pub), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", + &prefund->refund_amount), + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund", + &prefund->refund_fee), + GNUNET_PQ_result_spec_uint64 ("purse_refunds_serial_id", + &serial_id), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + GNUNET_free (prefund); + chc->failed = true; + return; + } + } + tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList); + tl->next = chc->head; + tl->type = TALER_EXCHANGEDB_TT_PURSE_REFUND; + tl->details.purse_refund = prefund; + tl->serial_id = serial_id; + chc->head = tl; + } +} + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct CoinHistoryContext` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void add_old_coin_recoup (void *cls, PGresult *result, unsigned int num_results) @@ -629,6 +686,9 @@ TEH_PG_get_coin_transactions ( /** #TALER_EXCHANGEDB_TT_PURSE_DEPOSIT */ { "get_purse_deposit_by_coin_pub", &add_coin_purse_deposit }, + /** #TALER_EXCHANGEDB_TT_PURSE_REFUND */ + { "get_purse_refund_by_coin_pub", + &add_coin_purse_refund }, /** #TALER_EXCHANGEDB_TT_REFUND */ { "get_refunds_by_coin", &add_coin_refund }, @@ -749,6 +809,23 @@ TEH_PG_get_coin_transactions ( " USING (denominations_serial)" " WHERE ref.coin_pub=$1;"); PREPARE (pg, + "get_purse_refund_by_coin", + "SELECT" + " pr.purse_pub" + ",pd.amount_with_fee_val" + ",pd.amount_with_fee_frac" + ",denom.fee_refund_val " + ",denom.fee_refund_frac " + ",pr.purse_refunds_serial_id" + " FROM purse_deposits pd" + " JOIN purse_refunds pr" + " USING (purse_pub)" + " JOIN known_coins kc" + " ON (pd.coin_pub = kc.coin_pub)" + " JOIN denominations denom" + " USING (denominations_serial)" + " WHERE pd.coin_pub=$1;"); + PREPARE (pg, "recoup_by_old_coin", "SELECT" " coins.coin_pub" diff --git a/src/exchangedb/plugin_exchangedb_common.c b/src/exchangedb/plugin_exchangedb_common.c index 84198dddf..a0159fb86 100644 --- a/src/exchangedb/plugin_exchangedb_common.c +++ b/src/exchangedb/plugin_exchangedb_common.c @@ -152,6 +152,14 @@ TEH_COMMON_free_coin_transaction_list ( GNUNET_free (deposit); break; } + case TALER_EXCHANGEDB_TT_PURSE_REFUND: + { + struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund; + + prefund = tl->details.purse_refund; + GNUNET_free (prefund); + break; + } case TALER_EXCHANGEDB_TT_RESERVE_OPEN: { struct TALER_EXCHANGEDB_ReserveOpenListEntry *role; |