fix #4533 for exchange (breaks interaction with bank for /admin/add/incoming)

This commit is contained in:
Christian Grothoff 2016-05-26 16:38:59 +02:00
parent 3f468773e7
commit c0451f0982
18 changed files with 253 additions and 117 deletions

View File

@ -22,6 +22,12 @@ Use the configuration and other resources for the exchange to operate from DIRNA
.IP "\-h, \-\-help" .IP "\-h, \-\-help"
Print short help on options. Print short help on options.
.B .B
.IP "\-s JSON, \-\-sender=JSON"
JSON-formatted acount details of the sender of the wire transfer.
.B
.IP "\-t JSON, \-\-transfer=JSON"
JSON-formatted details that uniquely identify the wire transfer.
.B
.IP "\-R KEY, \-\-reserve=KEY" .IP "\-R KEY, \-\-reserve=KEY"
Public EdDSA key of the reserve to modify. Public EdDSA key of the reserve to modify.
.B .B

View File

@ -144,7 +144,10 @@ handle_admin_add_incoming_finished (void *cls,
* @param reserve_pub public key of the reserve * @param reserve_pub public key of the reserve
* @param amount amount that was deposited * @param amount amount that was deposited
* @param execution_date when did we receive the amount * @param execution_date when did we receive the amount
* @param wire wire details * @param sender_account_details account information of the sender of the money;
* the receiver is always the exchange.
* @param transfer_details details that uniquely identify the transfer;
* used to check for duplicate operations by the exchange
* @param res_cb the callback to call when the final result for this request is available * @param res_cb the callback to call when the final result for this request is available
* @param res_cb_cls closure for the above callback * @param res_cb_cls closure for the above callback
* @return NULL * @return NULL
@ -156,7 +159,8 @@ TALER_EXCHANGE_admin_add_incoming (struct TALER_EXCHANGE_Handle *exchange,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *amount, const struct TALER_Amount *amount,
struct GNUNET_TIME_Absolute execution_date, struct GNUNET_TIME_Absolute execution_date,
const json_t *wire, const json_t *sender_account_details,
const json_t *transfer_details,
TALER_EXCHANGE_AdminAddIncomingResultCallback res_cb, TALER_EXCHANGE_AdminAddIncomingResultCallback res_cb,
void *res_cb_cls) void *res_cb_cls)
{ {
@ -174,11 +178,12 @@ TALER_EXCHANGE_admin_add_incoming (struct TALER_EXCHANGE_Handle *exchange,
return NULL; return NULL;
} }
admin_obj = json_pack ("{s:o, s:o," /* reserve_pub/amount */ admin_obj = json_pack ("{s:o, s:o," /* reserve_pub/amount */
" s:o, s:O}", /* execution_Date/wire */ " s:o, s:O, s:O}", /* execution_Date/sender/transfer */
"reserve_pub", GNUNET_JSON_from_data_auto (reserve_pub), "reserve_pub", GNUNET_JSON_from_data_auto (reserve_pub),
"amount", TALER_JSON_from_amount (amount), "amount", TALER_JSON_from_amount (amount),
"execution_date", GNUNET_JSON_from_time_abs (execution_date), "execution_date", GNUNET_JSON_from_time_abs (execution_date),
"wire", wire); "sender_account_details", sender_account_details,
"transfer_details", transfer_details);
aai = GNUNET_new (struct TALER_EXCHANGE_AdminAddIncomingHandle); aai = GNUNET_new (struct TALER_EXCHANGE_AdminAddIncomingHandle);
aai->exchange = exchange; aai->exchange = exchange;
aai->cb = res_cb; aai->cb = res_cb;

View File

@ -135,7 +135,8 @@ parse_reserve_history (const json_t *history,
if (0 == strcasecmp (type, if (0 == strcasecmp (type,
"DEPOSIT")) "DEPOSIT"))
{ {
json_t *wire; json_t *wire_account;
json_t *transfer;
rhistory[off].type = TALER_EXCHANGE_RTT_DEPOSIT; rhistory[off].type = TALER_EXCHANGE_RTT_DEPOSIT;
if (GNUNET_OK != if (GNUNET_OK !=
@ -147,18 +148,33 @@ parse_reserve_history (const json_t *history,
GNUNET_break_op (0); GNUNET_break_op (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
wire = json_object_get (transaction, wire_account = json_object_get (transaction,
"wire"); "sender_account_details");
/* check 'wire' is a JSON object (no need to check wireformat, /* check 'wire_account' is a JSON object (no need to check wireformat,
but we do at least expect "some" JSON object here) */ but we do at least expect "some" JSON object here) */
if ( (NULL == wire) || if ( (NULL == wire_account) ||
(! json_is_object (wire)) ) (! json_is_object (wire_account)) )
{ {
/* not even a JSON 'wire' specification, not acceptable */ /* not even a JSON 'wire' specification, not acceptable */
GNUNET_break_op (0); GNUNET_break_op (0);
if (NULL != wire_account)
json_decref (wire_account);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
rhistory[off].details.wire_in_details = wire; transfer = json_object_get (transaction,
"transfer_details");
/* check 'transfer' is a JSON object */
if ( (NULL == transfer) ||
(! json_is_object (transfer)) )
{
GNUNET_break_op (0);
json_decref (wire_account);
if (NULL != transfer)
json_decref (transfer);
return GNUNET_SYSERR;
}
rhistory[off].details.in_details.sender_account_details = wire_account;
rhistory[off].details.in_details.transfer_details = transfer;
/* end type==DEPOSIT */ /* end type==DEPOSIT */
} }
else if (0 == strcasecmp (type, else if (0 == strcasecmp (type,

View File

@ -248,9 +248,14 @@ struct Command
const char *amount; const char *amount;
/** /**
* Wire details (JSON). * Sender account details (JSON).
*/ */
const char *wire; const char *sender_details;
/**
* Transfer information identifier (JSON).
*/
const char *transfer_details;
/** /**
* Set (by the interpreter) to the reserve's private key * Set (by the interpreter) to the reserve's private key
@ -1660,7 +1665,8 @@ interpreter_run (void *cls)
struct TALER_CoinSpendPublicKeyP coin_pub; struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_Amount amount; struct TALER_Amount amount;
struct GNUNET_TIME_Absolute execution_date; struct GNUNET_TIME_Absolute execution_date;
json_t *wire; json_t *sender_details;
json_t *transfer_details;
const struct GNUNET_SCHEDULER_TaskContext *tc; const struct GNUNET_SCHEDULER_TaskContext *tc;
is->task = NULL; is->task = NULL;
@ -1710,14 +1716,26 @@ interpreter_run (void *cls)
fail (is); fail (is);
return; return;
} }
wire = json_loads (cmd->details.admin_add_incoming.wire, sender_details = json_loads (cmd->details.admin_add_incoming.sender_details,
JSON_REJECT_DUPLICATES, JSON_REJECT_DUPLICATES,
NULL); NULL);
if (NULL == wire) if (NULL == sender_details)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to parse wire details `%s' at %u\n", "Failed to parse sender details `%s' at %u\n",
cmd->details.admin_add_incoming.wire, cmd->details.admin_add_incoming.sender_details,
is->ip);
fail (is);
return;
}
transfer_details = json_loads (cmd->details.admin_add_incoming.transfer_details,
JSON_REJECT_DUPLICATES,
NULL);
if (NULL == transfer_details)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to parse transfer details `%s' at %u\n",
cmd->details.admin_add_incoming.transfer_details,
is->ip); is->ip);
fail (is); fail (is);
return; return;
@ -1729,9 +1747,12 @@ interpreter_run (void *cls)
&reserve_pub, &reserve_pub,
&amount, &amount,
execution_date, execution_date,
wire, sender_details,
transfer_details,
&add_incoming_cb, &add_incoming_cb,
is); is);
json_decref (sender_details);
json_decref (transfer_details);
if (NULL == cmd->details.admin_add_incoming.aih) if (NULL == cmd->details.admin_add_incoming.aih)
{ {
GNUNET_break (0); GNUNET_break (0);
@ -2669,7 +2690,8 @@ run (void *cls)
{ .oc = OC_ADMIN_ADD_INCOMING, { .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-1", .label = "create-reserve-1",
.expected_response_code = MHD_HTTP_OK, .expected_response_code = MHD_HTTP_OK,
.details.admin_add_incoming.wire = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42, \"uuid\":1 }", .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42}",
.details.admin_add_incoming.transfer_details = "{ \"uuid\":1 }",
.details.admin_add_incoming.amount = "EUR:5.01" }, .details.admin_add_incoming.amount = "EUR:5.01" },
/* Withdraw a 5 EUR coin, at fee of 1 ct */ /* Withdraw a 5 EUR coin, at fee of 1 ct */
{ .oc = OC_WITHDRAW_SIGN, { .oc = OC_WITHDRAW_SIGN,
@ -2737,7 +2759,8 @@ run (void *cls)
{ .oc = OC_ADMIN_ADD_INCOMING, { .oc = OC_ADMIN_ADD_INCOMING,
.label = "refresh-create-reserve-1", .label = "refresh-create-reserve-1",
.expected_response_code = MHD_HTTP_OK, .expected_response_code = MHD_HTTP_OK,
.details.admin_add_incoming.wire = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":424 }", .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":424 }",
.details.admin_add_incoming.transfer_details = "{ \"uuid\":2 }",
.details.admin_add_incoming.amount = "EUR:5.01" }, .details.admin_add_incoming.amount = "EUR:5.01" },
/* Withdraw a 5 EUR coin, at fee of 1 ct */ /* Withdraw a 5 EUR coin, at fee of 1 ct */
{ .oc = OC_WITHDRAW_SIGN, { .oc = OC_WITHDRAW_SIGN,
@ -2900,7 +2923,8 @@ run (void *cls)
{ .oc = OC_ADMIN_ADD_INCOMING, { .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-r1", .label = "create-reserve-r1",
.expected_response_code = MHD_HTTP_OK, .expected_response_code = MHD_HTTP_OK,
.details.admin_add_incoming.wire = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42, \"uuid\":2 }", .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42 }",
.details.admin_add_incoming.transfer_details = "{ \"uuid\":3 }",
.details.admin_add_incoming.amount = "EUR:5.01" }, .details.admin_add_incoming.amount = "EUR:5.01" },
/* Withdraw a 5 EUR coin, at fee of 1 ct */ /* Withdraw a 5 EUR coin, at fee of 1 ct */
{ .oc = OC_WITHDRAW_SIGN, { .oc = OC_WITHDRAW_SIGN,

View File

@ -45,10 +45,15 @@ static char *reserve_pub_str;
*/ */
static char *add_str; static char *add_str;
/**
* Details about the sender account in JSON format.
*/
static char *sender_details;
/** /**
* Details about the wire transfer in JSON format. * Details about the wire transfer in JSON format.
*/ */
static char *details; static char *transfer_details;
/** /**
* Return value from main(). * Return value from main().
@ -61,14 +66,16 @@ static int global_ret;
* *
* @param reserve_pub public key of the reserve to use * @param reserve_pub public key of the reserve to use
* @param add_value value to add * @param add_value value to add
* @param jdetails JSON details * @param jdetails JSON details about sender
* @param tdetails JSON details about transfer
* @return #GNUNET_OK on success, #GNUNET_SYSERR on hard error, * @return #GNUNET_OK on success, #GNUNET_SYSERR on hard error,
* #GNUNET_NO if record exists * #GNUNET_NO if record exists
*/ */
static int static int
run_transaction (const struct TALER_ReservePublicKeyP *reserve_pub, run_transaction (const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *add_value, const struct TALER_Amount *add_value,
json_t *jdetails) json_t *jdetails,
json_t *tdetails)
{ {
int ret; int ret;
struct TALER_EXCHANGEDB_Session *session; struct TALER_EXCHANGEDB_Session *session;
@ -86,7 +93,8 @@ run_transaction (const struct TALER_ReservePublicKeyP *reserve_pub,
reserve_pub, reserve_pub,
add_value, add_value,
GNUNET_TIME_absolute_get (), GNUNET_TIME_absolute_get (),
jdetails); jdetails,
tdetails);
if (GNUNET_SYSERR == ret) if (GNUNET_SYSERR == ret)
{ {
fprintf (stderr, fprintf (stderr,
@ -117,6 +125,7 @@ run (void *cls,
{ {
struct TALER_Amount add_value; struct TALER_Amount add_value;
json_t *jdetails; json_t *jdetails;
json_t *tdetails;
json_error_t error; json_error_t error;
struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReservePublicKeyP reserve_pub;
@ -155,26 +164,48 @@ run (void *cls,
global_ret = 1; global_ret = 1;
return; return;
} }
if (NULL == details) if (NULL == sender_details)
{ {
fprintf (stderr, fprintf (stderr,
"No wiring details given (justification required)\n"); "No sender details given (sender required)\n");
global_ret = 1; global_ret = 1;
return; return;
} }
jdetails = json_loads (details, jdetails = json_loads (sender_details,
JSON_REJECT_DUPLICATES, JSON_REJECT_DUPLICATES,
&error); &error);
if (NULL == jdetails) if (NULL == jdetails)
{ {
fprintf (stderr, fprintf (stderr,
"Failed to parse JSON transaction details `%s': %s (%s)\n", "Failed to parse JSON transaction details `%s': %s (%s)\n",
details, sender_details,
error.text, error.text,
error.source); error.source);
global_ret = 1; global_ret = 1;
return; return;
} }
if (NULL == transfer_details)
{
fprintf (stderr,
"No transfer details given (justification required)\n");
global_ret = 1;
json_decref (jdetails);
return;
}
tdetails = json_loads (transfer_details,
JSON_REJECT_DUPLICATES,
&error);
if (NULL == tdetails)
{
fprintf (stderr,
"Failed to parse JSON transaction details `%s': %s (%s)\n",
transfer_details,
error.text,
error.source);
global_ret = 1;
json_decref (jdetails);
return;
}
if (NULL == if (NULL ==
(plugin = TALER_EXCHANGEDB_plugin_load (cfg))) (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
@ -187,10 +218,12 @@ run (void *cls,
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
run_transaction (&reserve_pub, run_transaction (&reserve_pub,
&add_value, &add_value,
jdetails)) jdetails,
tdetails))
global_ret = 1; global_ret = 1;
TALER_EXCHANGEDB_plugin_unload (plugin); TALER_EXCHANGEDB_plugin_unload (plugin);
json_decref (jdetails); json_decref (jdetails);
json_decref (tdetails);
} }
@ -208,9 +241,12 @@ main (int argc, char *const *argv)
{'a', "add", "DENOM", {'a', "add", "DENOM",
"value to add", 1, "value to add", 1,
&GNUNET_GETOPT_set_string, &add_str}, &GNUNET_GETOPT_set_string, &add_str},
{'d', "details", "JSON", {'s', "sender", "JSON",
"details about the bank transaction which justify why we add this amount", 1, "details about the sender's bank account", 1,
&GNUNET_GETOPT_set_string, &details}, &GNUNET_GETOPT_set_string, &sender_details},
{'t', "transfer", "JSON",
"details that uniquely identify the bank transfer", 1,
&GNUNET_GETOPT_set_string, &transfer_details},
GNUNET_GETOPT_OPTION_HELP ("Deposit funds into a Taler reserve"), GNUNET_GETOPT_OPTION_HELP ("Deposit funds into a Taler reserve"),
{'R', "reserve", "KEY", {'R', "reserve", "KEY",
"reserve (public key) to modify", 1, "reserve (public key) to modify", 1,

View File

@ -114,13 +114,15 @@ TMH_ADMIN_handler_admin_add_incoming (struct TMH_RequestHandler *rh,
struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReservePublicKeyP reserve_pub;
struct TALER_Amount amount; struct TALER_Amount amount;
struct GNUNET_TIME_Absolute at; struct GNUNET_TIME_Absolute at;
json_t *wire; json_t *sender_account_details;
json_t *transfer_details;
json_t *root; json_t *root;
struct GNUNET_JSON_Specification spec[] = { struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("reserve_pub", &reserve_pub), GNUNET_JSON_spec_fixed_auto ("reserve_pub", &reserve_pub),
TALER_JSON_spec_amount ("amount", &amount), TALER_JSON_spec_amount ("amount", &amount),
GNUNET_JSON_spec_absolute_time ("execution_date", &at), GNUNET_JSON_spec_absolute_time ("execution_date", &at),
GNUNET_JSON_spec_json ("wire", &wire), GNUNET_JSON_spec_json ("sender_account_details", &sender_account_details),
GNUNET_JSON_spec_json ("transfer_details", &transfer_details),
GNUNET_JSON_spec_end () GNUNET_JSON_spec_end ()
}; };
int res; int res;
@ -148,19 +150,20 @@ TMH_ADMIN_handler_admin_add_incoming (struct TMH_RequestHandler *rh,
return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
} }
if (GNUNET_YES != if (GNUNET_YES !=
TMH_json_validate_wireformat (wire, TMH_json_validate_wireformat (sender_account_details,
GNUNET_NO)) GNUNET_NO))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
return TMH_RESPONSE_reply_arg_unknown (connection, return TMH_RESPONSE_reply_arg_unknown (connection,
"wire"); "sender_account_details");
} }
res = TMH_DB_execute_admin_add_incoming (connection, res = TMH_DB_execute_admin_add_incoming (connection,
&reserve_pub, &reserve_pub,
&amount, &amount,
at, at,
wire); sender_account_details,
transfer_details);
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
return res; return res;
} }

View File

@ -1690,7 +1690,8 @@ TMH_DB_execute_refresh_link (struct MHD_Connection *connection,
* @param reserve_pub public key of the reserve * @param reserve_pub public key of the reserve
* @param amount amount to add to the reserve * @param amount amount to add to the reserve
* @param execution_time when did we receive the wire transfer * @param execution_time when did we receive the wire transfer
* @param wire details about the wire transfer * @param sender_account_details which account send the funds
* @param transfer_details information that uniquely identifies the transfer
* @return MHD result code * @return MHD result code
*/ */
int int
@ -1698,7 +1699,8 @@ TMH_DB_execute_admin_add_incoming (struct MHD_Connection *connection,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *amount, const struct TALER_Amount *amount,
struct GNUNET_TIME_Absolute execution_time, struct GNUNET_TIME_Absolute execution_time,
json_t *wire) const json_t *sender_account_details,
const json_t *transfer_details)
{ {
struct TALER_EXCHANGEDB_Session *session; struct TALER_EXCHANGEDB_Session *session;
int ret; int ret;
@ -1713,7 +1715,8 @@ TMH_DB_execute_admin_add_incoming (struct MHD_Connection *connection,
reserve_pub, reserve_pub,
amount, amount,
execution_time, execution_time,
wire); sender_account_details,
transfer_details);
if (GNUNET_SYSERR == ret) if (GNUNET_SYSERR == ret)
{ {
GNUNET_break (0); GNUNET_break (0);

View File

@ -191,7 +191,8 @@ TMH_DB_execute_refresh_link (struct MHD_Connection *connection,
* @param reserve_pub public key of the reserve * @param reserve_pub public key of the reserve
* @param amount amount to add to the reserve * @param amount amount to add to the reserve
* @param execution_time when did we receive the wire transfer * @param execution_time when did we receive the wire transfer
* @param wire details about the wire transfer * @param sender_account_details which account send the funds
* @param transfer_details information that uniquely identifies the transfer
* @return MHD result code * @return MHD result code
*/ */
int int
@ -199,7 +200,8 @@ TMH_DB_execute_admin_add_incoming (struct MHD_Connection *connection,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *amount, const struct TALER_Amount *amount,
struct GNUNET_TIME_Absolute execution_time, struct GNUNET_TIME_Absolute execution_time,
json_t *wire); const json_t *sender_account_details,
const json_t *transfer_details);
/** /**

View File

@ -228,7 +228,7 @@ TMH_DEPOSIT_handler_deposit (struct TMH_RequestHandler *rh,
TALER_amount_ntoh (&deposit.deposit_fee, TALER_amount_ntoh (&deposit.deposit_fee,
&dki->issue.properties.fee_deposit); &dki->issue.properties.fee_deposit);
TMH_KS_release (ks); TMH_KS_release (ks);
deposit.wire = wire; deposit.receiver_wire_account = wire;
deposit.amount_with_fee = amount; deposit.amount_with_fee = amount;
if (-1 == TALER_amount_cmp (&deposit.amount_with_fee, if (-1 == TALER_amount_cmp (&deposit.amount_with_fee,
&deposit.deposit_fee)) &deposit.deposit_fee))

View File

@ -602,9 +602,10 @@ compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHistory *rh,
} }
ret = 1; ret = 1;
json_array_append_new (json_history, json_array_append_new (json_history,
json_pack ("{s:s, s:O, s:o}", json_pack ("{s:s, s:O, s:O, s:o}",
"type", "DEPOSIT", "type", "DEPOSIT",
"wire", pos->details.bank->wire, "sender_account_details", pos->details.bank->sender_account_details,
"transfer_details", pos->details.bank->transfer_details,
"amount", TALER_JSON_from_amount (&pos->details.bank->amount))); "amount", TALER_JSON_from_amount (&pos->details.bank->amount)));
break; break;
case TALER_EXCHANGEDB_RO_WITHDRAW_COIN: case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:

View File

@ -432,12 +432,12 @@ do_deposit (struct Command *cmd)
} }
fake_coin (&deposit.coin); fake_coin (&deposit.coin);
/* Build JSON for wire details */ /* Build JSON for wire details */
deposit.wire = json_pack ("{s:s, s:s, s:I}", deposit.receiver_wire_account = json_pack ("{s:s, s:s, s:I}",
"type", "test", "type", "test",
"bank_uri", "http://localhost:8082/", "bank_uri", "http://localhost:8082/",
"account_number", (json_int_t) cmd->details.deposit.merchant_account); "account_number", (json_int_t) cmd->details.deposit.merchant_account);
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_JSON_hash (deposit.wire, TALER_JSON_hash (deposit.receiver_wire_account,
&deposit.h_wire)); &deposit.h_wire));
deposit.transaction_id = cmd->details.deposit.transaction_id; deposit.transaction_id = cmd->details.deposit.transaction_id;
deposit.timestamp = GNUNET_TIME_absolute_get (); deposit.timestamp = GNUNET_TIME_absolute_get ();
@ -458,7 +458,7 @@ do_deposit (struct Command *cmd)
else else
ret = GNUNET_OK; ret = GNUNET_OK;
GNUNET_CRYPTO_rsa_signature_free (deposit.coin.denom_sig.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (deposit.coin.denom_sig.rsa_signature);
json_decref (deposit.wire); json_decref (deposit.receiver_wire_account);
return ret; return ret;
} }

View File

@ -276,7 +276,7 @@ PERF_TALER_EXCHANGEDB_deposit_init (const struct PERF_TALER_EXCHANGEDB_Coin *coi
deposit->csig = csig; deposit->csig = csig;
deposit->h_contract = h_contract; deposit->h_contract = h_contract;
deposit->h_wire = h_wire; deposit->h_wire = h_wire;
deposit->wire = json_loads (wire, 0, NULL); deposit->receiver_wire_account = json_loads (wire, 0, NULL);
deposit->transaction_id = transaction_id++; deposit->transaction_id = transaction_id++;
deposit->timestamp = timestamp; deposit->timestamp = timestamp;
deposit->refund_deadline = refund_deadline; deposit->refund_deadline = refund_deadline;
@ -298,7 +298,7 @@ PERF_TALER_EXCHANGEDB_deposit_copy (const struct TALER_EXCHANGEDB_Deposit *depos
copy = GNUNET_new (struct TALER_EXCHANGEDB_Deposit); copy = GNUNET_new (struct TALER_EXCHANGEDB_Deposit);
*copy = *deposit; *copy = *deposit;
json_incref (copy->wire); json_incref (copy->receiver_wire_account);
copy->coin.denom_pub.rsa_public_key = copy->coin.denom_pub.rsa_public_key =
GNUNET_CRYPTO_rsa_public_key_dup (deposit->coin.denom_pub.rsa_public_key); GNUNET_CRYPTO_rsa_public_key_dup (deposit->coin.denom_pub.rsa_public_key);
copy->coin.denom_sig.rsa_signature = copy->coin.denom_sig.rsa_signature =
@ -318,7 +318,7 @@ PERF_TALER_EXCHANGEDB_deposit_free (struct TALER_EXCHANGEDB_Deposit *deposit)
return GNUNET_OK; return GNUNET_OK;
GNUNET_CRYPTO_rsa_public_key_free (deposit->coin.denom_pub.rsa_public_key); GNUNET_CRYPTO_rsa_public_key_free (deposit->coin.denom_pub.rsa_public_key);
GNUNET_CRYPTO_rsa_signature_free (deposit->coin.denom_sig.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (deposit->coin.denom_sig.rsa_signature);
json_decref (deposit->wire); json_decref (deposit->receiver_wire_account);
GNUNET_free (deposit); GNUNET_free (deposit);
return GNUNET_OK; return GNUNET_OK;
} }

View File

@ -1373,23 +1373,31 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
unsigned int reserve_index; unsigned int reserve_index;
int ret; int ret;
struct PERF_TALER_EXCHANGEDB_Reserve *reserve; struct PERF_TALER_EXCHANGEDB_Reserve *reserve;
json_t *details = NULL; json_t *sndr;
json_t *just;
reserve_index = state->cmd[state->i].details.insert_reserve.index_reserve; reserve_index = state->cmd[state->i].details.insert_reserve.index_reserve;
reserve = state->cmd[reserve_index].exposed.data.reserve; reserve = state->cmd[reserve_index].exposed.data.reserve;
details = json_pack ("{s:i}","justification", sndr = json_pack ("{s:i}",
GNUNET_CRYPTO_random_u32 ( "account",
GNUNET_CRYPTO_QUALITY_WEAK, (int) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT32_MAX)); UINT32_MAX));
GNUNET_assert (NULL != details); just = json_pack ("{s:i}",
"justification",
(int) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT32_MAX));
GNUNET_assert (NULL != just);
GNUNET_assert (NULL != sndr);
ret = state->plugin->reserves_in_insert (state->plugin->cls, ret = state->plugin->reserves_in_insert (state->plugin->cls,
state->session, state->session,
&reserve->reserve.pub, &reserve->reserve.pub,
&reserve->reserve.balance, &reserve->reserve.balance,
GNUNET_TIME_absolute_get (), GNUNET_TIME_absolute_get (),
details); sndr,
just);
GNUNET_assert (GNUNET_SYSERR != ret); GNUNET_assert (GNUNET_SYSERR != ret);
json_decref (details); json_decref (sndr);
json_decref (just);
} }
break; break;

View File

@ -40,8 +40,10 @@ common_free_reserve_history (void *cls,
{ {
case TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE: case TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE:
bt = rh->details.bank; bt = rh->details.bank;
if (NULL != bt->wire) if (NULL != bt->sender_account_details)
json_decref (bt->wire); json_decref (bt->sender_account_details);
if (NULL != bt->transfer_details)
json_decref (bt->transfer_details);
GNUNET_free (bt); GNUNET_free (bt);
break; break;
case TALER_EXCHANGEDB_RO_WITHDRAW_COIN: case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
@ -98,7 +100,7 @@ common_free_coin_transaction_list (void *cls,
switch (list->type) switch (list->type)
{ {
case TALER_EXCHANGEDB_TT_DEPOSIT: case TALER_EXCHANGEDB_TT_DEPOSIT:
json_decref (list->details.deposit->wire); json_decref (list->details.deposit->receiver_wire_account);
if (NULL != list->details.deposit->coin.denom_pub.rsa_public_key) if (NULL != list->details.deposit->coin.denom_pub.rsa_public_key)
GNUNET_CRYPTO_rsa_public_key_free (list->details.deposit->coin.denom_pub.rsa_public_key); GNUNET_CRYPTO_rsa_public_key_free (list->details.deposit->coin.denom_pub.rsa_public_key);
if (NULL != list->details.deposit->coin.denom_sig.rsa_signature) if (NULL != list->details.deposit->coin.denom_sig.rsa_signature)

View File

@ -305,9 +305,10 @@ postgres_create_tables (void *cls)
",balance_val INT8 NOT NULL" ",balance_val INT8 NOT NULL"
",balance_frac INT4 NOT NULL" ",balance_frac INT4 NOT NULL"
",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",details TEXT NOT NULL " ",sender_account_details TEXT NOT NULL "
",transfer_details TEXT NOT NULL "
",execution_date INT8 NOT NULL" ",execution_date INT8 NOT NULL"
",PRIMARY KEY (reserve_pub,details)" ",PRIMARY KEY (reserve_pub,transfer_details)"
");"); ");");
/* Create indices on reserves_in */ /* Create indices on reserves_in */
SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_index" SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_index"
@ -627,11 +628,12 @@ postgres_prepare (PGconn *db_conn)
",balance_val" ",balance_val"
",balance_frac" ",balance_frac"
",balance_curr" ",balance_curr"
",details" ",sender_account_details"
",transfer_details"
",execution_date" ",execution_date"
") VALUES " ") VALUES "
"($1, $2, $3, $4, $5, $6);", "($1, $2, $3, $4, $5, $6, $7);",
6, NULL); 7, NULL);
/* Used in #postgres_get_reserve_history() to obtain inbound transactions /* Used in #postgres_get_reserve_history() to obtain inbound transactions
for a reserve */ for a reserve */
@ -641,7 +643,8 @@ postgres_prepare (PGconn *db_conn)
",balance_frac" ",balance_frac"
",balance_curr" ",balance_curr"
",execution_date" ",execution_date"
",details" ",sender_account_details"
",transfer_details"
" FROM reserves_in" " FROM reserves_in"
" WHERE reserve_pub=$1", " WHERE reserve_pub=$1",
1, NULL); 1, NULL);
@ -1634,8 +1637,8 @@ reserves_update (void *cls,
* @param reserve_pub public key of the reserve * @param reserve_pub public key of the reserve
* @param balance the amount that has to be added to the reserve * @param balance the amount that has to be added to the reserve
* @param execution_time when was the amount added * @param execution_time when was the amount added
* @param details bank transaction details justifying the increment, * @param sender_account_details account information for the sender
* must be unique for each incoming transaction * @param transfer_details information that uniquely identifies the transfer
* @return #GNUNET_OK upon success; #GNUNET_NO if the given * @return #GNUNET_OK upon success; #GNUNET_NO if the given
* @a details are already known for this @a reserve_pub, * @a details are already known for this @a reserve_pub,
* #GNUNET_SYSERR upon failures (DB error, incompatible currency) * #GNUNET_SYSERR upon failures (DB error, incompatible currency)
@ -1646,7 +1649,8 @@ postgres_reserves_in_insert (void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *balance, const struct TALER_Amount *balance,
struct GNUNET_TIME_Absolute execution_time, struct GNUNET_TIME_Absolute execution_time,
const json_t *details) const json_t *sender_account_details,
const json_t *transfer_details)
{ {
PGresult *result; PGresult *result;
int reserve_exists; int reserve_exists;
@ -1707,7 +1711,8 @@ postgres_reserves_in_insert (void *cls,
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (&reserve.pub), GNUNET_PQ_query_param_auto_from_type (&reserve.pub),
TALER_PQ_query_param_amount (balance), TALER_PQ_query_param_amount (balance),
TALER_PQ_query_param_json (details), TALER_PQ_query_param_json (sender_account_details),
TALER_PQ_query_param_json (transfer_details),
GNUNET_PQ_query_param_absolute_time (&execution_time), GNUNET_PQ_query_param_absolute_time (&execution_time),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
@ -1989,8 +1994,10 @@ postgres_get_reserve_history (void *cls,
&bt->amount), &bt->amount),
GNUNET_PQ_result_spec_absolute_time ("execution_date", GNUNET_PQ_result_spec_absolute_time ("execution_date",
&bt->execution_date), &bt->execution_date),
TALER_PQ_result_spec_json ("details", TALER_PQ_result_spec_json ("sender_account_details",
&bt->wire), &bt->sender_account_details),
TALER_PQ_result_spec_json ("transfer_details",
&bt->transfer_details),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
if (GNUNET_OK != if (GNUNET_OK !=
@ -2647,7 +2654,7 @@ postgres_insert_deposit (void *cls,
GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract), GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract),
GNUNET_PQ_query_param_auto_from_type (&deposit->h_wire), GNUNET_PQ_query_param_auto_from_type (&deposit->h_wire),
GNUNET_PQ_query_param_auto_from_type (&deposit->csig), GNUNET_PQ_query_param_auto_from_type (&deposit->csig),
TALER_PQ_query_param_json (deposit->wire), TALER_PQ_query_param_json (deposit->receiver_wire_account),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
@ -3643,7 +3650,7 @@ postgres_get_coin_transactions (void *cls,
GNUNET_PQ_result_spec_auto_from_type ("h_wire", GNUNET_PQ_result_spec_auto_from_type ("h_wire",
&deposit->h_wire), &deposit->h_wire),
TALER_PQ_result_spec_json ("wire", TALER_PQ_result_spec_json ("wire",
&deposit->wire), &deposit->receiver_wire_account),
GNUNET_PQ_result_spec_auto_from_type ("coin_sig", GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
&deposit->csig), &deposit->csig),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end

View File

@ -974,9 +974,6 @@ deposit_cb (void *cls,
} }
/** /**
* Main function that will be run by the scheduler. * Main function that will be run by the scheduler.
* *
@ -1003,6 +1000,7 @@ run (void *cls)
struct TALER_WireTransferIdentifierRawP wtid; struct TALER_WireTransferIdentifierRawP wtid;
json_t *wire; json_t *wire;
json_t *just; json_t *just;
json_t *sndr;
unsigned int matched; unsigned int matched;
const char * const json_wire_str = const char * const json_wire_str =
"{ \"type\":\"SEPA\", \ "{ \"type\":\"SEPA\", \
@ -1060,6 +1058,7 @@ run (void *cls)
&amount_with_fee)); &amount_with_fee));
result = 4; result = 4;
sndr = json_loads ("{ \"account\":\"1\" }", 0, NULL);
just = json_loads ("{ \"justification\":\"1\" }", 0, NULL); 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,
@ -1067,6 +1066,7 @@ run (void *cls)
&reserve_pub, &reserve_pub,
&value, &value,
GNUNET_TIME_absolute_get (), GNUNET_TIME_absolute_get (),
sndr,
just)); just));
json_decref (just); json_decref (just);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
@ -1082,8 +1082,10 @@ run (void *cls)
&reserve_pub, &reserve_pub,
&value, &value,
GNUNET_TIME_absolute_get (), GNUNET_TIME_absolute_get (),
sndr,
just)); just));
json_decref (just); json_decref (just);
json_decref (sndr);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (session,
&reserve_pub, &reserve_pub,
@ -1153,7 +1155,8 @@ run (void *cls)
FAILIF (1 != bt->amount.value); FAILIF (1 != bt->amount.value);
FAILIF (10 != bt->amount.fraction); FAILIF (10 != bt->amount.fraction);
FAILIF (0 != strcmp (CURRENCY, bt->amount.currency)); FAILIF (0 != strcmp (CURRENCY, bt->amount.currency));
FAILIF (NULL == bt->wire); FAILIF (NULL == bt->sender_account_details);
FAILIF (NULL == bt->transfer_details);
break; break;
case TALER_EXCHANGEDB_RO_WITHDRAW_COIN: case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
withdraw = rh_head->details.withdraw; withdraw = rh_head->details.withdraw;
@ -1178,7 +1181,7 @@ run (void *cls)
wire = json_loads (json_wire_str, 0, NULL); wire = json_loads (json_wire_str, 0, NULL);
TALER_JSON_hash (wire, TALER_JSON_hash (wire,
&deposit.h_wire); &deposit.h_wire);
deposit.wire = wire; deposit.receiver_wire_account = wire;
deposit.transaction_id = deposit.transaction_id =
GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
deposit.amount_with_fee = value; deposit.amount_with_fee = value;

View File

@ -604,10 +604,19 @@ struct TALER_EXCHANGE_ReserveHistory
*/ */
union { union {
struct {
/** /**
* Transaction details for the incoming transaction. * Sender account information for the incoming transfer.
*/ */
json_t *wire_in_details; json_t *sender_account_details;
/**
* Wire transfer details for the incoming transfer.
*/
json_t *transfer_details;
} in_details;
/** /**
* Signature authorizing the withdrawal for outgoing transaction. * Signature authorizing the withdrawal for outgoing transaction.
@ -1036,7 +1045,10 @@ typedef void
* @param reserve_pub public key of the reserve * @param reserve_pub public key of the reserve
* @param amount amount that was deposited * @param amount amount that was deposited
* @param execution_date when did we receive the amount * @param execution_date when did we receive the amount
* @param wire wire details * @param sender_account_details account information of the sender of the money;
* the receiver is always the exchange.
* @param transfer_details details that uniquely identify the transfer;
* used to check for duplicate operations by the exchange
* @param res_cb the callback to call when the final result for this request is available * @param res_cb the callback to call when the final result for this request is available
* @param res_cb_cls closure for the above callback * @param res_cb_cls closure for the above callback
* @return NULL * @return NULL
@ -1048,7 +1060,8 @@ TALER_EXCHANGE_admin_add_incoming (struct TALER_EXCHANGE_Handle *exchange,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *amount, const struct TALER_Amount *amount,
struct GNUNET_TIME_Absolute execution_date, struct GNUNET_TIME_Absolute execution_date,
const json_t *wire, const json_t *sender_account_details,
const json_t *transfer_details,
TALER_EXCHANGE_AdminAddIncomingResultCallback res_cb, TALER_EXCHANGE_AdminAddIncomingResultCallback res_cb,
void *res_cb_cls); void *res_cb_cls);

View File

@ -51,9 +51,15 @@ struct TALER_EXCHANGEDB_BankTransfer
struct GNUNET_TIME_Absolute execution_date; struct GNUNET_TIME_Absolute execution_date;
/** /**
* Detailed wire information about the transaction. * Detailed wire information about the sending account.
*/ */
json_t *wire; json_t *sender_account_details;
/**
* Detailed wire transfer information that uniquely identifies the
* wire transfer.
*/
json_t *transfer_details;
}; };
@ -243,9 +249,9 @@ struct TALER_EXCHANGEDB_Deposit
struct GNUNET_HashCode h_wire; struct GNUNET_HashCode h_wire;
/** /**
* Detailed wire information for executing the transaction. * Detailed information about the receiver for executing the transaction.
*/ */
json_t *wire; json_t *receiver_wire_account;
/** /**
* Merchant-generated transaction ID to detect duplicate * Merchant-generated transaction ID to detect duplicate
@ -601,7 +607,7 @@ struct TALER_EXCHANGEDB_Session;
* @param h_contract hash of the contract between merchant and customer * @param h_contract hash of the contract between merchant and customer
* @param wire_deadline by which the merchant adviced that he would like the * @param wire_deadline by which the merchant adviced that he would like the
* wire transfer to be executed * wire transfer to be executed
* @param wire wire details for the merchant, NULL from iterate_matching_deposits() * @param receiver_wire_account wire details for the merchant, NULL from iterate_matching_deposits()
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/ */
typedef int typedef int
@ -614,7 +620,7 @@ typedef int
uint64_t transaction_id, uint64_t transaction_id,
const struct GNUNET_HashCode *h_contract, const struct GNUNET_HashCode *h_contract,
struct GNUNET_TIME_Absolute wire_deadline, struct GNUNET_TIME_Absolute wire_deadline,
const json_t *wire); const json_t *receiver_wire_account);
/** /**
@ -842,8 +848,8 @@ struct TALER_EXCHANGEDB_Plugin
* @param reserve_pub public key of the reserve * @param reserve_pub public key of the reserve
* @param balance the amount that has to be added to the reserve * @param balance the amount that has to be added to the reserve
* @param execution_time when was the amount added * @param execution_time when was the amount added
* @param details bank transaction details justifying the increment, * @param sender_account_details information about the sender
* must be unique for each incoming transaction * @param transfer_details information that uniquely identifies the wire transfer
* @return #GNUNET_OK upon success; #GNUNET_NO if the given * @return #GNUNET_OK upon success; #GNUNET_NO if the given
* @a details are already known for this @a reserve_pub, * @a details are already known for this @a reserve_pub,
* #GNUNET_SYSERR upon failures (DB error, incompatible currency) * #GNUNET_SYSERR upon failures (DB error, incompatible currency)
@ -854,7 +860,8 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *balance, const struct TALER_Amount *balance,
struct GNUNET_TIME_Absolute execution_time, struct GNUNET_TIME_Absolute execution_time,
const json_t *details); const json_t *sender_account_details,
const json_t *transfer_details);
/** /**