diff --git a/src/include/taler_mintdb_plugin.h b/src/include/taler_mintdb_plugin.h index 2d1671335..f5e61a7c3 100644 --- a/src/include/taler_mintdb_plugin.h +++ b/src/include/taler_mintdb_plugin.h @@ -42,6 +42,13 @@ struct TALER_MINTDB_BankTransfer */ struct TALER_Amount amount; + /** + * When did the mint receive the incoming transaction? + * (This is the execution date of the mint's database, + * the execution date of the bank should be in @e wire). + */ + struct GNUNET_TIME_Absolute execution_date; + /** * Detailed wire information about the transaction. */ @@ -724,7 +731,7 @@ struct TALER_MINTDB_Plugin struct TALER_MINTDB_Session *db, const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_Amount *balance, - const char *details); + const json_t *details); /** diff --git a/src/mint-tools/Makefile.am b/src/mint-tools/Makefile.am index e22df1ed7..9849bbc54 100644 --- a/src/mint-tools/Makefile.am +++ b/src/mint-tools/Makefile.am @@ -41,7 +41,7 @@ taler_mint_reservemod_LDADD = \ $(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/pq/libtalerpq.la \ $(top_builddir)/src/mintdb/libtalermintdb.la \ - -lgnunetutil $(XLIB) + -lgnunetutil -ljansson $(XLIB) taler_mint_reservemod_LDFLAGS = \ $(POSTGRESQL_LDFLAGS) taler_mint_reservemod_CPPFLAGS = \ diff --git a/src/mint-tools/taler-mint-reservemod.c b/src/mint-tools/taler-mint-reservemod.c index 75093fc75..888b34baa 100644 --- a/src/mint-tools/taler-mint-reservemod.c +++ b/src/mint-tools/taler-mint-reservemod.c @@ -22,6 +22,7 @@ #include "platform.h" #include #include +#include #include "taler_mintdb_plugin.h" /** @@ -54,6 +55,8 @@ main (int argc, char *const *argv) char *add_str = NULL; struct TALER_Amount add_value; char *details = NULL; + json_t *jdetails; + json_error_t error; struct TALER_ReservePublicKeyP reserve_pub; struct TALER_MINTDB_Session *session; const struct GNUNET_GETOPT_CommandLineOption options[] = { @@ -157,11 +160,24 @@ main (int argc, char *const *argv) "Failed to initialize DB session\n"); goto cleanup; } + jdetails = json_loads (details, + JSON_REJECT_DUPLICATES, + &error); + if (NULL == jdetails) + { + fprintf (stderr, + "Failed to parse JSON transaction details `%s': %s (%s)\n", + details, + error.text, + error.source); + goto cleanup; + } ret = plugin->reserves_in_insert (plugin->cls, session, &reserve_pub, &add_value, - details); + jdetails); + json_decref (jdetails); if (GNUNET_SYSERR == ret) { fprintf (stderr, diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c index fe2f2a49c..e4d0f4d50 100644 --- a/src/mintdb/plugin_mintdb_postgres.c +++ b/src/mintdb/plugin_mintdb_postgres.c @@ -510,8 +510,8 @@ postgres_prepare (PGconn *db_conn) " balance_val" ",balance_frac" ",balance_curr" - ",execution_date" /* NOTE: not used (yet), #3817 */ - ",details" /* NOTE: not used (yet), #3817 */ + ",execution_date" + ",details" " FROM reserves_in" " WHERE reserve_pub=$1", 1, NULL); @@ -1150,7 +1150,7 @@ postgres_reserves_in_insert (void *cls, struct TALER_MINTDB_Session *session, const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_Amount *balance, - const char *details) + const json_t *details) { PGresult *result; int reserve_exists; @@ -1212,7 +1212,7 @@ postgres_reserves_in_insert (void *cls, struct TALER_PQ_QueryParam params[] = { TALER_PQ_query_param_auto_from_type (&reserve.pub), TALER_PQ_query_param_amount (balance), - TALER_PQ_query_param_fixed_size (details, strlen (details)), + TALER_PQ_query_param_json (details), TALER_PQ_query_param_absolute_time (&now), TALER_PQ_query_param_end }; @@ -1490,29 +1490,29 @@ postgres_get_reserve_history (void *cls, "Asked to fetch history for an unknown reserve.\n"); goto cleanup; } - /* FIXME: maybe also use the 'expiration_date' and 'details' - values and return those as well? While right now they - are unnecessary, the 'expiration_date' should become the - original transfer date, and then it will be useful; - similarly, 'details' might become useful for reserve refunds - in the future. (#3817) */ while (0 < rows) { bt = GNUNET_new (struct TALER_MINTDB_BankTransfer); - /* FIXME: use higher-level libtalerpq API here? */ - if (GNUNET_OK != TALER_PQ_extract_amount (result, - --rows, - "balance_val", - "balance_frac", - "balance_curr", - &bt->amount)) { - GNUNET_free (bt); - GNUNET_break (0); - goto cleanup; + struct TALER_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_amount ("balance", + &bt->amount), + TALER_PQ_result_spec_absolute_time ("execution_date", + &bt->execution_date), + TALER_PQ_result_spec_json ("details", + &bt->wire), + TALER_PQ_result_spec_end + }; + if (GNUNET_YES != + TALER_PQ_extract_result (result, rs, --rows)) + { + GNUNET_break (0); + GNUNET_free (bt); + PQclear (result); + goto cleanup; + } } bt->reserve_pub = *reserve_pub; - /* FIXME: bt->wire not initialized! (#3817) */ if (NULL != rh_tail) { rh_tail->next = GNUNET_new (struct TALER_MINTDB_ReserveHistory); diff --git a/src/mintdb/test_mintdb.c b/src/mintdb/test_mintdb.c index 74c1f66fe..56f5636d0 100644 --- a/src/mintdb/test_mintdb.c +++ b/src/mintdb/test_mintdb.c @@ -243,7 +243,8 @@ run (void *cls, struct TALER_MINTDB_CollectableBlindcoin *withdraw; struct TALER_MINTDB_Deposit deposit; struct TALER_MINTDB_Deposit deposit2; - struct json_t *wire; + json_t *wire; + json_t *just; const char * const json_wire_str = "{ \"type\":\"SEPA\", \ \"IBAN\":\"DE67830654080004822650\", \ @@ -285,24 +286,28 @@ run (void *cls, amount.fraction = 1; strcpy (amount.currency, CURRENCY); result = 4; + just = json_loads ("{ \"justification\":\"1\" }", 0, NULL); FAILIF (GNUNET_OK != plugin->reserves_in_insert (plugin->cls, session, &reserve_pub, &amount, - "justification 1")); + just)); + json_decref (just); FAILIF (GNUNET_OK != check_reserve (session, &reserve_pub, amount.value, amount.fraction, amount.currency)); + just = json_loads ("{ \"justification\":\"2\" }", 0, NULL); FAILIF (GNUNET_OK != plugin->reserves_in_insert (plugin->cls, session, &reserve_pub, &amount, - "justification 2")); + just)); + json_decref (just); FAILIF (GNUNET_OK != check_reserve (session, &reserve_pub, @@ -368,7 +373,7 @@ run (void *cls, FAILIF (1 != bt->amount.value); FAILIF (1 != bt->amount.fraction); FAILIF (0 != strcmp (CURRENCY, bt->amount.currency)); - FAILIF (NULL != bt->wire); /* FIXME: write wire details to db */ + FAILIF (NULL == bt->wire); break; case TALER_MINTDB_RO_WITHDRAW_COIN: withdraw = rh_head->details.withdraw; diff --git a/src/pq/pq_helper.c b/src/pq/pq_helper.c index f4b0c0109..8fd7e207b 100644 --- a/src/pq/pq_helper.c +++ b/src/pq/pq_helper.c @@ -174,8 +174,8 @@ TALER_PQ_query_param_json (const json_t *x) */ struct TALER_PQ_ResultSpec TALER_PQ_result_spec_variable_size (const char *name, - void **dst, - size_t *sptr) + void **dst, + size_t *sptr) { struct TALER_PQ_ResultSpec res = { TALER_PQ_RF_VARSIZE_BLOB, (void *) (dst), 0, name, sptr };