summaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/taler-exchange-aggregator.c81
-rw-r--r--src/exchange/taler-exchange-httpd_deposit.c6
-rw-r--r--src/exchange/taler-exchange-httpd_refund.c1
-rw-r--r--src/exchange/taler-exchange-httpd_track_transfer.c2
4 files changed, 88 insertions, 2 deletions
diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c
index 3de5630d4..d5d43052d 100644
--- a/src/exchange/taler-exchange-aggregator.c
+++ b/src/exchange/taler-exchange-aggregator.c
@@ -124,6 +124,11 @@ struct AggregationUnit
struct GNUNET_HashCode h_wire;
/**
+ * Hash code of contract we are currently looking into.
+ */
+ const struct GNUNET_HashCode *h_contract;
+
+ /**
* Wire transfer identifier we use.
*/
struct TALER_WireTransferIdentifierRawP wtid;
@@ -374,6 +379,7 @@ update_fees (struct WirePlugin *wp,
p->start_date,
p->end_date,
&p->wire_fee,
+ &p->closing_fee,
&p->master_sig);
if (qs < 0)
{
@@ -568,6 +574,53 @@ exchange_serve_process_config ()
/**
+ * Callback invoked with information about refunds applicable
+ * to a particular coin. Subtract refunded amount(s) from
+ * the aggregation unit's total amount.
+ *
+ * @param cls closure with a `struct AggregationUnit *`
+ * @param merchant_pub public key of merchant who authorized refund
+ * @param merchant_sig signature of merchant authorizing refund
+ * @param h_contract hash of contract being refunded
+ * @param rtransaction_id refund transaction ID
+ * @param amount_with_fee amount being refunded
+ * @param refund_fee fee the exchange keeps for the refund processing
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static int
+refund_by_coin_cb (void *cls,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_MerchantSignatureP *merchant_sig,
+ const struct GNUNET_HashCode *h_contract,
+ uint64_t rtransaction_id,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_Amount *refund_fee)
+{
+ struct AggregationUnit *au = cls;
+
+ /* TODO: potential optimization: include these conditions
+ in the SELECT! */
+ if (0 != memcmp (merchant_pub,
+ &au->merchant_pub,
+ sizeof (struct TALER_MerchantPublicKeyP)))
+ return GNUNET_OK; /* different merchant */
+ if (0 != memcmp (h_contract,
+ au->h_contract,
+ sizeof (struct GNUNET_HashCode)))
+ return GNUNET_OK; /* different contract */
+ if (GNUNET_OK !=
+ TALER_amount_subtract (&au->total_amount,
+ &au->total_amount,
+ amount_with_fee))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
* Function called with details about deposits that have been made,
* with the goal of executing the corresponding wire transaction.
*
@@ -609,6 +662,20 @@ deposit_cb (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
au->row_id = row_id;
+
+ au->h_contract = h_contract_terms;
+ qs = db_plugin->select_refunds_by_coin (db_plugin->cls,
+ au->session,
+ coin_pub,
+ &refund_by_coin_cb,
+ au);
+ au->h_contract = NULL;
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+
GNUNET_assert (NULL == au->wire);
au->wire = json_incref ((json_t *) wire);
if (GNUNET_OK !=
@@ -730,6 +797,20 @@ aggregate_cb (void *cls,
/* Skip this one, but keep going! */
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
+
+ au->h_contract = h_contract_terms;
+ qs = db_plugin->select_refunds_by_coin (db_plugin->cls,
+ au->session,
+ coin_pub,
+ &refund_by_coin_cb,
+ au);
+ au->h_contract = NULL;
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+
if (au->rows_offset >= aggregation_limit)
{
/* Bug: we asked for at most #aggregation_limit results! */
diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c
index b7fb3452c..542c56c9c 100644
--- a/src/exchange/taler-exchange-httpd_deposit.c
+++ b/src/exchange/taler-exchange-httpd_deposit.c
@@ -149,6 +149,8 @@ deposit_transaction (void *cls,
{
struct TALER_Amount amount_without_fee;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "/deposit replay, accepting again!\n");
GNUNET_assert (GNUNET_OK ==
TALER_amount_subtract (&amount_without_fee,
&deposit->amount_with_fee,
@@ -191,6 +193,8 @@ deposit_transaction (void *cls,
if (0 < TALER_amount_cmp (&spent,
&dc->value))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Deposited coin has insufficient funds left!\n");
*mhd_ret = TEH_RESPONSE_reply_coin_insufficient_funds (connection,
TALER_EC_DEPOSIT_INSUFFICIENT_FUNDS,
tl);
@@ -376,7 +380,7 @@ TEH_DEPOSIT_handler_deposit (struct TEH_RequestHandler *rh,
struct GNUNET_HashCode my_h_wire;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_json ("wire", &wire),
- TALER_JSON_spec_amount ("f", &deposit.amount_with_fee),
+ TALER_JSON_spec_amount ("contribution", &deposit.amount_with_fee),
TALER_JSON_spec_denomination_public_key ("denom_pub", &deposit.coin.denom_pub),
TALER_JSON_spec_denomination_signature ("ub_sig", &deposit.coin.denom_sig),
GNUNET_JSON_spec_fixed_auto ("coin_pub", &deposit.coin.coin_pub),
diff --git a/src/exchange/taler-exchange-httpd_refund.c b/src/exchange/taler-exchange-httpd_refund.c
index f0aaa65c0..986c9d312 100644
--- a/src/exchange/taler-exchange-httpd_refund.c
+++ b/src/exchange/taler-exchange-httpd_refund.c
@@ -285,7 +285,6 @@ refund_transaction (void *cls,
}
/* check if we already send the money for the /deposit */
- // FIXME: DB API...
qs = TEH_plugin->test_deposit_done (TEH_plugin->cls,
session,
dep);
diff --git a/src/exchange/taler-exchange-httpd_track_transfer.c b/src/exchange/taler-exchange-httpd_track_transfer.c
index 4d28096be..38c6c29e3 100644
--- a/src/exchange/taler-exchange-httpd_track_transfer.c
+++ b/src/exchange/taler-exchange-httpd_track_transfer.c
@@ -352,6 +352,7 @@ track_transfer_transaction (void *cls,
struct GNUNET_TIME_Absolute wire_fee_start_date;
struct GNUNET_TIME_Absolute wire_fee_end_date;
struct TALER_MasterSignatureP wire_fee_master_sig;
+ struct TALER_Amount closing_fee;
ctx->is_valid = GNUNET_NO;
ctx->wdd_head = NULL;
@@ -393,6 +394,7 @@ track_transfer_transaction (void *cls,
&wire_fee_start_date,
&wire_fee_end_date,
&ctx->wire_fee,
+ &closing_fee,
&wire_fee_master_sig);
if (0 >= qs)
{