diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-01-15 13:27:19 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-01-15 13:27:19 +0100 |
commit | 9fffeee4ef8bc4d1c42cb0bd7ece49555ab97ea2 (patch) | |
tree | c4f4d1f9b0c8714776530d7a8b627ca04b91bd46 /src/exchange/taler-exchange-aggregator.c | |
parent | 08e0d56614c5c930239e0947ce8fe64f6a56ad8b (diff) | |
parent | acc3a41df812b59a1775d3fc0697a0b73d847963 (diff) | |
download | exchange-9fffeee4ef8bc4d1c42cb0bd7ece49555ab97ea2.tar.gz exchange-9fffeee4ef8bc4d1c42cb0bd7ece49555ab97ea2.tar.bz2 exchange-9fffeee4ef8bc4d1c42cb0bd7ece49555ab97ea2.zip |
merge changelog
Diffstat (limited to 'src/exchange/taler-exchange-aggregator.c')
-rw-r--r-- | src/exchange/taler-exchange-aggregator.c | 81 |
1 files changed, 81 insertions, 0 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! */ |