fix new ag logic
This commit is contained in:
parent
f8095d7297
commit
d7cfb11fc6
@ -1 +1 @@
|
|||||||
Subproject commit ca53235ccfa0458ebf11c204888ca370e20ec3f5
|
Subproject commit 934a6a18301e81c4fd1b3a8cda2dc13dca4741cc
|
@ -523,8 +523,9 @@ aggregate_cb (void *cls,
|
|||||||
const json_t *wire)
|
const json_t *wire)
|
||||||
{
|
{
|
||||||
struct AggregationUnit *au = cls;
|
struct AggregationUnit *au = cls;
|
||||||
struct TALER_Amount delta;
|
struct TALER_Amount old;
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
|
struct TALER_Amount delta;
|
||||||
|
|
||||||
/* NOTE: potential optimization: use custom SQL API to not
|
/* NOTE: potential optimization: use custom SQL API to not
|
||||||
fetch these: */
|
fetch these: */
|
||||||
@ -541,12 +542,16 @@ aggregate_cb (void *cls,
|
|||||||
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
|
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute contribution of this coin after fees */
|
|
||||||
/* add to total */
|
/* add to total */
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"Adding transaction amount %s from row %llu to aggregation\n",
|
"Adding transaction amount %s from row %llu to aggregation\n",
|
||||||
TALER_amount2s (amount_with_fee),
|
TALER_amount2s (amount_with_fee),
|
||||||
(unsigned long long) row_id);
|
(unsigned long long) row_id);
|
||||||
|
/* save the existing total aggregate in 'old', for later */
|
||||||
|
old = au->total_amount;
|
||||||
|
/* we begin with the total contribution of the current coin */
|
||||||
|
au->total_amount = *amount_with_fee;
|
||||||
|
/* compute contribution of this coin (after fees) */
|
||||||
au->have_refund = GNUNET_NO;
|
au->have_refund = GNUNET_NO;
|
||||||
qs = db_plugin->select_refunds_by_coin (db_plugin->cls,
|
qs = db_plugin->select_refunds_by_coin (db_plugin->cls,
|
||||||
au->session,
|
au->session,
|
||||||
@ -562,43 +567,45 @@ aggregate_cb (void *cls,
|
|||||||
}
|
}
|
||||||
if (GNUNET_NO == au->have_refund)
|
if (GNUNET_NO == au->have_refund)
|
||||||
{
|
{
|
||||||
|
struct TALER_Amount tmp;
|
||||||
|
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"Subtracting deposit fee %s for non-refunded coin\n",
|
"Subtracting deposit fee %s for non-refunded coin\n",
|
||||||
TALER_amount2s (deposit_fee));
|
TALER_amount2s (deposit_fee));
|
||||||
if (GNUNET_SYSERR ==
|
if (GNUNET_SYSERR ==
|
||||||
TALER_amount_subtract (&delta,
|
TALER_amount_subtract (&tmp,
|
||||||
amount_with_fee,
|
&au->total_amount,
|
||||||
deposit_fee))
|
deposit_fee))
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"Fatally malformed record at %llu over amount %s (deposit fee exceeds deposited value)\n",
|
"Fatally malformed record at %llu over amount %s (deposit fee exceeds deposited value)\n",
|
||||||
(unsigned long long) row_id,
|
(unsigned long long) row_id,
|
||||||
TALER_amount2s (&au->total_amount));
|
TALER_amount2s (&au->total_amount));
|
||||||
|
GNUNET_assert (GNUNET_OK ==
|
||||||
|
TALER_amount_get_zero (old.currency,
|
||||||
|
&au->total_amount));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GNUNET_assert (GNUNET_OK ==
|
au->total_amount = tmp;
|
||||||
TALER_amount_get_zero (au->total_amount.currency,
|
|
||||||
&delta));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
delta = *amount_with_fee;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* now add the au->total_amount with the (remaining) contribution of
|
||||||
|
the current coin to the 'old' value with the current aggregate value */
|
||||||
{
|
{
|
||||||
struct TALER_Amount tmp;
|
struct TALER_Amount tmp;
|
||||||
|
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_amount_add (&tmp,
|
TALER_amount_add (&tmp,
|
||||||
&au->total_amount,
|
&au->total_amount,
|
||||||
&delta))
|
&old))
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"Overflow or currency incompatibility during aggregation at %llu\n",
|
"Overflow or currency incompatibility during aggregation at %llu\n",
|
||||||
(unsigned long long) row_id);
|
(unsigned long long) row_id);
|
||||||
/* Skip this one, but keep going! */
|
/* Skip this one, but keep going! */
|
||||||
|
au->total_amount = old;
|
||||||
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
|
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
|
||||||
}
|
}
|
||||||
au->total_amount = tmp;
|
au->total_amount = tmp;
|
||||||
|
Loading…
Reference in New Issue
Block a user