This commit is contained in:
Christian Grothoff 2015-06-11 13:38:47 +02:00
parent edc6d38082
commit dc23f290ee
6 changed files with 58 additions and 30 deletions

View File

@ -42,6 +42,13 @@ struct TALER_MINTDB_BankTransfer
*/ */
struct TALER_Amount amount; 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. * Detailed wire information about the transaction.
*/ */
@ -724,7 +731,7 @@ struct TALER_MINTDB_Plugin
struct TALER_MINTDB_Session *db, struct TALER_MINTDB_Session *db,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *balance, const struct TALER_Amount *balance,
const char *details); const json_t *details);
/** /**

View File

@ -41,7 +41,7 @@ taler_mint_reservemod_LDADD = \
$(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/pq/libtalerpq.la \ $(top_builddir)/src/pq/libtalerpq.la \
$(top_builddir)/src/mintdb/libtalermintdb.la \ $(top_builddir)/src/mintdb/libtalermintdb.la \
-lgnunetutil $(XLIB) -lgnunetutil -ljansson $(XLIB)
taler_mint_reservemod_LDFLAGS = \ taler_mint_reservemod_LDFLAGS = \
$(POSTGRESQL_LDFLAGS) $(POSTGRESQL_LDFLAGS)
taler_mint_reservemod_CPPFLAGS = \ taler_mint_reservemod_CPPFLAGS = \

View File

@ -22,6 +22,7 @@
#include "platform.h" #include "platform.h"
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include <libpq-fe.h> #include <libpq-fe.h>
#include <jansson.h>
#include "taler_mintdb_plugin.h" #include "taler_mintdb_plugin.h"
/** /**
@ -54,6 +55,8 @@ main (int argc, char *const *argv)
char *add_str = NULL; char *add_str = NULL;
struct TALER_Amount add_value; struct TALER_Amount add_value;
char *details = NULL; char *details = NULL;
json_t *jdetails;
json_error_t error;
struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReservePublicKeyP reserve_pub;
struct TALER_MINTDB_Session *session; struct TALER_MINTDB_Session *session;
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
@ -157,11 +160,24 @@ main (int argc, char *const *argv)
"Failed to initialize DB session\n"); "Failed to initialize DB session\n");
goto cleanup; 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, ret = plugin->reserves_in_insert (plugin->cls,
session, session,
&reserve_pub, &reserve_pub,
&add_value, &add_value,
details); jdetails);
json_decref (jdetails);
if (GNUNET_SYSERR == ret) if (GNUNET_SYSERR == ret)
{ {
fprintf (stderr, fprintf (stderr,

View File

@ -510,8 +510,8 @@ postgres_prepare (PGconn *db_conn)
" balance_val" " balance_val"
",balance_frac" ",balance_frac"
",balance_curr" ",balance_curr"
",execution_date" /* NOTE: not used (yet), #3817 */ ",execution_date"
",details" /* NOTE: not used (yet), #3817 */ ",details"
" FROM reserves_in" " FROM reserves_in"
" WHERE reserve_pub=$1", " WHERE reserve_pub=$1",
1, NULL); 1, NULL);
@ -1150,7 +1150,7 @@ postgres_reserves_in_insert (void *cls,
struct TALER_MINTDB_Session *session, struct TALER_MINTDB_Session *session,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *balance, const struct TALER_Amount *balance,
const char *details) const json_t *details)
{ {
PGresult *result; PGresult *result;
int reserve_exists; int reserve_exists;
@ -1212,7 +1212,7 @@ postgres_reserves_in_insert (void *cls,
struct TALER_PQ_QueryParam params[] = { struct TALER_PQ_QueryParam params[] = {
TALER_PQ_query_param_auto_from_type (&reserve.pub), TALER_PQ_query_param_auto_from_type (&reserve.pub),
TALER_PQ_query_param_amount (balance), 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_absolute_time (&now),
TALER_PQ_query_param_end TALER_PQ_query_param_end
}; };
@ -1490,29 +1490,29 @@ postgres_get_reserve_history (void *cls,
"Asked to fetch history for an unknown reserve.\n"); "Asked to fetch history for an unknown reserve.\n");
goto cleanup; 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) while (0 < rows)
{ {
bt = GNUNET_new (struct TALER_MINTDB_BankTransfer); 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); struct TALER_PQ_ResultSpec rs[] = {
GNUNET_break (0); TALER_PQ_result_spec_amount ("balance",
goto cleanup; &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; bt->reserve_pub = *reserve_pub;
/* FIXME: bt->wire not initialized! (#3817) */
if (NULL != rh_tail) if (NULL != rh_tail)
{ {
rh_tail->next = GNUNET_new (struct TALER_MINTDB_ReserveHistory); rh_tail->next = GNUNET_new (struct TALER_MINTDB_ReserveHistory);

View File

@ -243,7 +243,8 @@ run (void *cls,
struct TALER_MINTDB_CollectableBlindcoin *withdraw; struct TALER_MINTDB_CollectableBlindcoin *withdraw;
struct TALER_MINTDB_Deposit deposit; struct TALER_MINTDB_Deposit deposit;
struct TALER_MINTDB_Deposit deposit2; struct TALER_MINTDB_Deposit deposit2;
struct json_t *wire; json_t *wire;
json_t *just;
const char * const json_wire_str = const char * const json_wire_str =
"{ \"type\":\"SEPA\", \ "{ \"type\":\"SEPA\", \
\"IBAN\":\"DE67830654080004822650\", \ \"IBAN\":\"DE67830654080004822650\", \
@ -285,24 +286,28 @@ run (void *cls,
amount.fraction = 1; amount.fraction = 1;
strcpy (amount.currency, CURRENCY); strcpy (amount.currency, CURRENCY);
result = 4; result = 4;
just = json_loads ("{ \"justification\":\"1\" }", 0, NULL);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->reserves_in_insert (plugin->cls, plugin->reserves_in_insert (plugin->cls,
session, session,
&reserve_pub, &reserve_pub,
&amount, &amount,
"justification 1")); just));
json_decref (just);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (session,
&reserve_pub, &reserve_pub,
amount.value, amount.value,
amount.fraction, amount.fraction,
amount.currency)); amount.currency));
just = json_loads ("{ \"justification\":\"2\" }", 0, NULL);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->reserves_in_insert (plugin->cls, plugin->reserves_in_insert (plugin->cls,
session, session,
&reserve_pub, &reserve_pub,
&amount, &amount,
"justification 2")); just));
json_decref (just);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (session,
&reserve_pub, &reserve_pub,
@ -368,7 +373,7 @@ run (void *cls,
FAILIF (1 != bt->amount.value); FAILIF (1 != bt->amount.value);
FAILIF (1 != bt->amount.fraction); FAILIF (1 != bt->amount.fraction);
FAILIF (0 != strcmp (CURRENCY, bt->amount.currency)); FAILIF (0 != strcmp (CURRENCY, bt->amount.currency));
FAILIF (NULL != bt->wire); /* FIXME: write wire details to db */ FAILIF (NULL == bt->wire);
break; break;
case TALER_MINTDB_RO_WITHDRAW_COIN: case TALER_MINTDB_RO_WITHDRAW_COIN:
withdraw = rh_head->details.withdraw; withdraw = rh_head->details.withdraw;

View File

@ -174,8 +174,8 @@ TALER_PQ_query_param_json (const json_t *x)
*/ */
struct TALER_PQ_ResultSpec struct TALER_PQ_ResultSpec
TALER_PQ_result_spec_variable_size (const char *name, TALER_PQ_result_spec_variable_size (const char *name,
void **dst, void **dst,
size_t *sptr) size_t *sptr)
{ {
struct TALER_PQ_ResultSpec res = struct TALER_PQ_ResultSpec res =
{ TALER_PQ_RF_VARSIZE_BLOB, (void *) (dst), 0, name, sptr }; { TALER_PQ_RF_VARSIZE_BLOB, (void *) (dst), 0, name, sptr };