summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-05-23 16:02:55 +0200
committerChristian Grothoff <christian@grothoff.org>2022-05-23 16:02:55 +0200
commit76b8a2a8de551db8801bd42111bd959a28517cb3 (patch)
tree979340c340161640843371c02bf00cfec7554a0d /src/exchangedb
parenta509a91f924cad3b5f0336f78e5c80e3621ad52b (diff)
downloadexchange-76b8a2a8de551db8801bd42111bd959a28517cb3.tar.gz
exchange-76b8a2a8de551db8801bd42111bd959a28517cb3.tar.bz2
exchange-76b8a2a8de551db8801bd42111bd959a28517cb3.zip
include purse deposits in coin history
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/exchangedb_transactions.c12
-rw-r--r--src/exchangedb/plugin_exchangedb_common.c9
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c97
3 files changed, 117 insertions, 1 deletions
diff --git a/src/exchangedb/exchangedb_transactions.c b/src/exchangedb/exchangedb_transactions.c
index 81a33b172..ef46bace6 100644
--- a/src/exchangedb/exchangedb_transactions.c
+++ b/src/exchangedb/exchangedb_transactions.c
@@ -119,6 +119,18 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (
return GNUNET_SYSERR;
}
break;
+ case TALER_EXCHANGEDB_TT_PURSE_DEPOSIT:
+ /* spent += pos->amount_with_fee */
+ if (0 >
+ TALER_amount_add (&spent,
+ &spent,
+ &pos->details.purse_deposit->amount))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ deposit_fee = pos->details.purse_deposit->deposit_fee;
+ break;
}
}
if (have_refund)
diff --git a/src/exchangedb/plugin_exchangedb_common.c b/src/exchangedb/plugin_exchangedb_common.c
index e36074e32..ca5903501 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -150,6 +150,15 @@ common_free_coin_transaction_list (void *cls,
GNUNET_free (rr);
break;
}
+ case TALER_EXCHANGEDB_TT_PURSE_DEPOSIT:
+ {
+ struct TALER_EXCHANGEDB_PurseDepositListEntry *deposit;
+
+ deposit = tl->details.purse_deposit;
+ GNUNET_free (deposit->exchange_base_url);
+ GNUNET_free (deposit);
+ break;
+ }
}
{
struct TALER_EXCHANGEDB_TransactionList *next;
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 0db3d4df0..273cffa09 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1235,7 +1235,8 @@ prepare_statements (struct PostgresClosure *pg)
" WHERE melt_serial_id>=$1"
" ORDER BY melt_serial_id ASC;",
1),
- /* Query the 'refresh_commitments' by coin public key */
+ /* Query the 'refresh_commitments' by coin public key,
+ used in #postgres_get_coin_transactions() */
GNUNET_PQ_make_prepare (
"get_refresh_session_by_coin",
"SELECT"
@@ -1255,6 +1256,30 @@ prepare_statements (struct PostgresClosure *pg)
" USING (denominations_serial)"
" WHERE old_coin_pub=$1;",
1),
+ /* Find purse deposits by coin,
+ used in #postgres_get_coin_transactions() */
+ GNUNET_PQ_make_prepare (
+ "get_purse_deposit_by_coin_pub",
+ "SELECT"
+ " partner_url"
+ ",amount_with_fee_val"
+ ",amount_with_fee_frac"
+ ",denoms.fee_deposit_val"
+ ",denoms.fee_deposit_frac"
+ ",purse_pub"
+ ",coin_sig"
+ ",purse_deposit_serial_id"
+ " FROM purse_deposits pd"
+ " LEFT JOIN partners"
+ " USING (partner_serial_id)"
+ " JOIN known_coins kc"
+ " ON (refresh_commitments.old_coin_pub = kc.coin_pub)"
+ " JOIN denominations denoms"
+ " USING (denominations_serial)"
+ // FIXME: use to-be-created materialized index
+ // on coin_pub (query crosses partitions!)
+ " WHERE coin_pub=$1;",
+ 1),
/* Store information about the desired denominations for a
refresh operation, used in #postgres_insert_refresh_reveal() */
GNUNET_PQ_make_prepare (
@@ -7950,6 +7975,70 @@ add_coin_deposit (void *cls,
* @param num_results the number of results in @a result
*/
static void
+add_coin_purse_deposit (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_PurseDepositListEntry *deposit;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ chc->have_deposit_or_melt = true;
+ deposit = GNUNET_new (struct TALER_EXCHANGEDB_PurseDepositListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit->amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &deposit->deposit_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &deposit->purse_pub),
+ GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_url",
+ &deposit->exchange_base_url),
+ NULL),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &deposit->coin_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (deposit);
+ chc->failed = true;
+ return;
+ }
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_PURSE_DEPOSIT;
+ tl->details.purse_deposit = deposit;
+ 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_coin_melt (void *cls,
PGresult *result,
unsigned int num_results)
@@ -8309,6 +8398,9 @@ postgres_get_coin_transactions (
/** #TALER_EXCHANGEDB_TT_MELT */
{ "get_refresh_session_by_coin",
&add_coin_melt },
+ /** #TALER_EXCHANGEDB_TT_PURSE_DEPOSIT */
+ { "get_purse_deposit_by_coin_pub",
+ &add_coin_purse_deposit },
/** #TALER_EXCHANGEDB_TT_REFUND */
{ "get_refunds_by_coin",
&add_coin_refund },
@@ -8321,6 +8413,9 @@ postgres_get_coin_transactions (
/** #TALER_EXCHANGEDB_TT_MELT */
{ "get_refresh_session_by_coin",
&add_coin_melt },
+ /** #TALER_EXCHANGEDB_TT_PURSE_DEPOSIT */
+ { "get_purse_deposit_by_coin_pub",
+ &add_coin_purse_deposit },
/** #TALER_EXCHANGEDB_TT_REFUND */
{ "get_refunds_by_coin",
&add_coin_refund },