summaryrefslogtreecommitdiff
path: root/src/exchange-lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange-lib')
-rw-r--r--src/exchange-lib/exchange_api_admin.c23
-rw-r--r--src/exchange-lib/exchange_api_reserve.c30
-rw-r--r--src/exchange-lib/test_exchange_api.c50
3 files changed, 74 insertions, 29 deletions
diff --git a/src/exchange-lib/exchange_api_admin.c b/src/exchange-lib/exchange_api_admin.c
index 3c87be5a3..0452a9546 100644
--- a/src/exchange-lib/exchange_api_admin.c
+++ b/src/exchange-lib/exchange_api_admin.c
@@ -144,7 +144,10 @@ handle_admin_add_incoming_finished (void *cls,
* @param reserve_pub public key of the reserve
* @param amount amount that was deposited
* @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_cls closure for the above callback
* @return NULL
@@ -153,12 +156,13 @@ handle_admin_add_incoming_finished (void *cls,
*/
struct TALER_EXCHANGE_AdminAddIncomingHandle *
TALER_EXCHANGE_admin_add_incoming (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *amount,
- struct GNUNET_TIME_Absolute execution_date,
- const json_t *wire,
- TALER_EXCHANGE_AdminAddIncomingResultCallback res_cb,
- void *res_cb_cls)
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Absolute execution_date,
+ const json_t *sender_account_details,
+ const json_t *transfer_details,
+ TALER_EXCHANGE_AdminAddIncomingResultCallback res_cb,
+ void *res_cb_cls)
{
struct TALER_EXCHANGE_AdminAddIncomingHandle *aai;
struct GNUNET_CURL_Context *ctx;
@@ -174,11 +178,12 @@ TALER_EXCHANGE_admin_add_incoming (struct TALER_EXCHANGE_Handle *exchange,
return NULL;
}
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),
"amount", TALER_JSON_from_amount (amount),
"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->exchange = exchange;
aai->cb = res_cb;
diff --git a/src/exchange-lib/exchange_api_reserve.c b/src/exchange-lib/exchange_api_reserve.c
index 9c0314d0f..ab8733dbb 100644
--- a/src/exchange-lib/exchange_api_reserve.c
+++ b/src/exchange-lib/exchange_api_reserve.c
@@ -135,7 +135,8 @@ parse_reserve_history (const json_t *history,
if (0 == strcasecmp (type,
"DEPOSIT"))
{
- json_t *wire;
+ json_t *wire_account;
+ json_t *transfer;
rhistory[off].type = TALER_EXCHANGE_RTT_DEPOSIT;
if (GNUNET_OK !=
@@ -147,18 +148,33 @@ parse_reserve_history (const json_t *history,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- wire = json_object_get (transaction,
- "wire");
- /* check 'wire' is a JSON object (no need to check wireformat,
+ wire_account = json_object_get (transaction,
+ "sender_account_details");
+ /* check 'wire_account' is a JSON object (no need to check wireformat,
but we do at least expect "some" JSON object here) */
- if ( (NULL == wire) ||
- (! json_is_object (wire)) )
+ if ( (NULL == wire_account) ||
+ (! json_is_object (wire_account)) )
{
/* not even a JSON 'wire' specification, not acceptable */
GNUNET_break_op (0);
+ if (NULL != wire_account)
+ json_decref (wire_account);
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 */
}
else if (0 == strcasecmp (type,
diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c
index c9140b3fb..75a9cfbd9 100644
--- a/src/exchange-lib/test_exchange_api.c
+++ b/src/exchange-lib/test_exchange_api.c
@@ -248,9 +248,14 @@ struct Command
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
@@ -1660,7 +1665,8 @@ interpreter_run (void *cls)
struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_Amount amount;
struct GNUNET_TIME_Absolute execution_date;
- json_t *wire;
+ json_t *sender_details;
+ json_t *transfer_details;
const struct GNUNET_SCHEDULER_TaskContext *tc;
is->task = NULL;
@@ -1710,14 +1716,26 @@ interpreter_run (void *cls)
fail (is);
return;
}
- wire = json_loads (cmd->details.admin_add_incoming.wire,
- JSON_REJECT_DUPLICATES,
- NULL);
- if (NULL == wire)
+ sender_details = json_loads (cmd->details.admin_add_incoming.sender_details,
+ JSON_REJECT_DUPLICATES,
+ NULL);
+ if (NULL == sender_details)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse sender details `%s' at %u\n",
+ 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 wire details `%s' at %u\n",
- cmd->details.admin_add_incoming.wire,
+ "Failed to parse transfer details `%s' at %u\n",
+ cmd->details.admin_add_incoming.transfer_details,
is->ip);
fail (is);
return;
@@ -1729,9 +1747,12 @@ interpreter_run (void *cls)
&reserve_pub,
&amount,
execution_date,
- wire,
+ sender_details,
+ transfer_details,
&add_incoming_cb,
is);
+ json_decref (sender_details);
+ json_decref (transfer_details);
if (NULL == cmd->details.admin_add_incoming.aih)
{
GNUNET_break (0);
@@ -2669,7 +2690,8 @@ run (void *cls)
{ .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-1",
.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" },
/* Withdraw a 5 EUR coin, at fee of 1 ct */
{ .oc = OC_WITHDRAW_SIGN,
@@ -2737,7 +2759,8 @@ run (void *cls)
{ .oc = OC_ADMIN_ADD_INCOMING,
.label = "refresh-create-reserve-1",
.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" },
/* Withdraw a 5 EUR coin, at fee of 1 ct */
{ .oc = OC_WITHDRAW_SIGN,
@@ -2900,7 +2923,8 @@ run (void *cls)
{ .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-r1",
.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" },
/* Withdraw a 5 EUR coin, at fee of 1 ct */
{ .oc = OC_WITHDRAW_SIGN,