aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/exchangedb/exchangedb_transactions.c20
-rw-r--r--src/exchangedb/pg_get_coin_transactions.c77
-rw-r--r--src/exchangedb/plugin_exchangedb_common.c8
-rw-r--r--src/include/taler_exchangedb_plugin.h38
4 files changed, 142 insertions, 1 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;
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index 0df32241c..a12c2ac3f 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -1789,6 +1789,31 @@ struct TALER_EXCHANGEDB_PurseDepositListEntry
/**
+ * @brief Specification for a purse refund operation in a coin's transaction list.
+ */
+struct TALER_EXCHANGEDB_PurseRefundListEntry
+{
+
+ /**
+ * Public key of the purse.
+ */
+ struct TALER_PurseContractPublicKeyP purse_pub;
+
+ /**
+ * Fraction of the original deposit's value to be refunded, including
+ * refund fee (if any). The coin is identified by @e coin_pub.
+ */
+ struct TALER_Amount refund_amount;
+
+ /**
+ * Refund fee to be covered by the customer.
+ */
+ struct TALER_Amount refund_fee;
+
+};
+
+
+/**
* Information about a /reserves/$RID/open operation in a coin transaction history.
*/
struct TALER_EXCHANGEDB_ReserveOpenListEntry
@@ -1975,9 +2000,14 @@ enum TALER_EXCHANGEDB_TransactionType
TALER_EXCHANGEDB_TT_PURSE_DEPOSIT = 6,
/**
+ * Purse deposit operation.
+ */
+ TALER_EXCHANGEDB_TT_PURSE_REFUND = 7,
+
+ /**
* Reserve open deposit operation.
*/
- TALER_EXCHANGEDB_TT_RESERVE_OPEN = 7
+ TALER_EXCHANGEDB_TT_RESERVE_OPEN = 8
};
@@ -2054,6 +2084,12 @@ struct TALER_EXCHANGEDB_TransactionList
struct TALER_EXCHANGEDB_PurseDepositListEntry *purse_deposit;
/**
+ * Coin was refunded upon purse expiration
+ * (#TALER_EXCHANGEDB_TT_PURSE_REFUND)
+ */
+ struct TALER_EXCHANGEDB_PurseRefundListEntry *purse_refund;
+
+ /**
* Coin was used to pay to open a reserve.
* (#TALER_EXCHANGEDB_TT_RESERVE_OPEN)
*/