implementing/fixing #4933: check total_amount matches aggregated transactions

This commit is contained in:
Christian Grothoff 2017-03-04 17:51:50 +01:00
parent 6ab67a3a76
commit e3dcc27b68
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -87,6 +87,7 @@ check_track_transfer_response_ok (struct TALER_EXCHANGE_TrackTransferHandle *wdh
struct GNUNET_HashCode h_wire; struct GNUNET_HashCode h_wire;
struct GNUNET_TIME_Absolute exec_time; struct GNUNET_TIME_Absolute exec_time;
struct TALER_Amount total_amount; struct TALER_Amount total_amount;
struct TALER_Amount total_expected;
struct TALER_Amount wire_fee; struct TALER_Amount wire_fee;
struct TALER_MerchantPublicKeyP merchant_pub; struct TALER_MerchantPublicKeyP merchant_pub;
unsigned int num_details; unsigned int num_details;
@ -112,6 +113,13 @@ check_track_transfer_response_ok (struct TALER_EXCHANGE_TrackTransferHandle *wdh
GNUNET_break_op (0); GNUNET_break_op (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (GNUNET_OK !=
TALER_amount_get_zero (total_amount.currency,
&total_expected))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
num_details = json_array_size (details_j); num_details = json_array_size (details_j);
{ {
struct TALER_TrackTransferDetails details[num_details]; struct TALER_TrackTransferDetails details[num_details];
@ -151,6 +159,20 @@ check_track_transfer_response_ok (struct TALER_EXCHANGE_TrackTransferHandle *wdh
&detail->coin_value); &detail->coin_value);
TALER_amount_hton (&dd.deposit_fee, TALER_amount_hton (&dd.deposit_fee,
&detail->coin_fee); &detail->coin_fee);
if ( (GNUNET_OK !=
TALER_amount_add (&total_expected,
&total_expected,
&detail->coin_value)) ||
(GNUNET_OK !=
TALER_amount_subtract (&total_expected,
&total_expected,
&detail->coin_fee)) )
{
GNUNET_break_op (0);
GNUNET_CRYPTO_hash_context_abort (hash_context);
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
GNUNET_CRYPTO_hash_context_read (hash_context, GNUNET_CRYPTO_hash_context_read (hash_context,
&dd, &dd,
sizeof (struct TALER_WireDepositDetailP)); sizeof (struct TALER_WireDepositDetailP));
@ -182,6 +204,23 @@ check_track_transfer_response_ok (struct TALER_EXCHANGE_TrackTransferHandle *wdh
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (GNUNET_OK !=
TALER_amount_subtract (&total_expected,
&total_expected,
&wire_fee))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
if (0 !=
TALER_amount_cmp (&total_expected,
&total_amount))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
wdh->cb (wdh->cb_cls, wdh->cb (wdh->cb_cls,
MHD_HTTP_OK, MHD_HTTP_OK,
TALER_EC_NONE, TALER_EC_NONE,