aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-04-02 18:17:29 +0200
committerChristian Grothoff <christian@grothoff.org>2017-04-02 18:17:29 +0200
commitb95522c1ddf6e32a35dbec2123c24363316a9514 (patch)
tree280cd02d1b555271f62101376c93d515eb1dde08 /src/exchangedb
parentd8542d729ab8e285176bc29beb42ae7a19afa7e7 (diff)
expand DB plugin to return payback information as part of coin/reserve histories
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c95
1 files changed, 89 insertions, 6 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index d69cb4180..3095529d9 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1432,10 +1432,28 @@ postgres_prepare (PGconn *db_conn)
",denom.denom_pub"
",denom.denom_sig"
" FROM payback"
- " JOIN reserves_out denom USING (h_blind_ev)"
+ " JOIN reserves_out denom USING (reserve_pub,h_blind_ev)"
" WHERE payback.reserve_pub=$1",
1, NULL);
+ /* Used in #postgres_get_coin_transactions() to obtain payback transactions
+ for a coin */
+ PREPARE ("payback_by_coin",
+ "SELECT"
+ " payback.reserve_pub"
+ ",coin_sig"
+ ",coin_blind"
+ ",amount_val"
+ ",amount_frac"
+ ",amount_curr"
+ ",timestamp"
+ ",denom.denom_pub"
+ ",denom.denom_sig"
+ " FROM payback"
+ " JOIN reserves_out denom USING (reserve_pub,h_blind_ev)"
+ " WHERE payback.coin_pub=$1",
+ 1, NULL);
+
/* Used in #postgres_get_reserve_by_h_blind() */
@@ -3923,10 +3941,10 @@ postgres_get_coin_transactions (void *cls,
struct TALER_EXCHANGEDB_TransactionList *head;
head = NULL;
- /* check deposits */
+ /** #TALER_EXCHANGEDB_TT_DEPOSIT */
{
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&coin_pub->eddsa_pub),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
GNUNET_PQ_query_param_end
};
int nrows;
@@ -4003,7 +4021,7 @@ postgres_get_coin_transactions (void *cls,
}
PQclear (result);
}
- /* Handle refreshing */
+ /** #TALER_EXCHANGEDB_TT_REFRESH_MELT */
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (&coin_pub->eddsa_pub),
@@ -4074,10 +4092,10 @@ postgres_get_coin_transactions (void *cls,
}
PQclear (result);
}
- /* handle refunds */
+ /** #TALER_EXCHANGEDB_TT_REFUND */
{
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&coin_pub->eddsa_pub),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
GNUNET_PQ_query_param_end
};
int nrows;
@@ -4149,6 +4167,71 @@ postgres_get_coin_transactions (void *cls,
}
PQclear (result);
}
+ /** #TALER_EXCHANGEDB_TT_PAYBACK */
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ int nrows;
+ int i;
+ PGresult *result;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+
+ /* check if a refund records exist and get them */
+ result = GNUNET_PQ_exec_prepared (session->conn,
+ "payback_by_coin",
+ params);
+ if (PGRES_TUPLES_OK != PQresultStatus (result))
+ {
+ BREAK_DB_ERR (result, session->conn);
+ PQclear (result);
+ goto cleanup;
+ }
+ nrows = PQntuples (result);
+ for (i=0;i<nrows;i++)
+ {
+ struct TALER_EXCHANGEDB_Payback *payback;
+
+ payback = GNUNET_new (struct TALER_EXCHANGEDB_Payback);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_amount ("amount",
+ &payback->value),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &payback->reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &payback->coin_blind),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &payback->coin_sig),
+ GNUNET_PQ_result_spec_absolute_time ("timestamp",
+ &payback->timestamp),
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
+ &payback->denom_pub.rsa_public_key),
+ GNUNET_PQ_result_spec_end
+ };
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (payback);
+ PQclear (result);
+ goto cleanup;
+ }
+ payback->coin_pub = *coin_pub;
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = head;
+ tl->type = TALER_EXCHANGEDB_TT_PAYBACK;
+ tl->details.payback = payback;
+ head = tl;
+ continue;
+ }
+ PQclear (result);
+ }
+
return head;
cleanup:
if (NULL != head)