aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/exchange_api_common.c44
-rw-r--r--src/lib/exchange_api_reserves_history.c7
-rw-r--r--src/lib/exchange_api_reserves_status.c3
-rw-r--r--src/lib/exchange_api_withdraw2.c14
4 files changed, 21 insertions, 47 deletions
diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c
index c9bff71f1..1da36fe8b 100644
--- a/src/lib/exchange_api_common.c
+++ b/src/lib/exchange_api_common.c
@@ -32,21 +32,20 @@ TALER_EXCHANGE_parse_reserve_history (
const json_t *history,
const struct TALER_ReservePublicKeyP *reserve_pub,
const char *currency,
- struct TALER_Amount *balance,
+ struct TALER_Amount *total_in,
+ struct TALER_Amount *total_out,
unsigned int history_length,
struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory)
{
struct GNUNET_HashCode uuid[history_length];
unsigned int uuid_off;
- struct TALER_Amount total_in;
- struct TALER_Amount total_out;
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (currency,
- &total_in));
+ total_in));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (currency,
- &total_out));
+ total_out));
uuid_off = 0;
for (unsigned int off = 0; off<history_length; off++)
{
@@ -76,7 +75,7 @@ TALER_EXCHANGE_parse_reserve_history (
rhistory[off].amount = amount;
if (GNUNET_YES !=
TALER_amount_cmp_currency (&amount,
- &total_in))
+ total_in))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -99,8 +98,8 @@ TALER_EXCHANGE_parse_reserve_history (
rh->type = TALER_EXCHANGE_RTT_CREDIT;
if (0 >
- TALER_amount_add (&total_in,
- &total_in,
+ TALER_amount_add (total_in,
+ total_in,
&amount))
{
/* overflow in history already!? inconceivable! Bad exchange! */
@@ -206,8 +205,8 @@ TALER_EXCHANGE_parse_reserve_history (
uuid_off++;
if (0 >
- TALER_amount_add (&total_out,
- &total_out,
+ TALER_amount_add (total_out,
+ total_out,
&amount))
{
/* overflow in history already!? inconceivable! Bad exchange! */
@@ -274,8 +273,8 @@ TALER_EXCHANGE_parse_reserve_history (
return GNUNET_SYSERR;
}
if (0 >
- TALER_amount_add (&total_in,
- &total_in,
+ TALER_amount_add (total_in,
+ total_in,
&rh->amount))
{
/* overflow in history already!? inconceivable! Bad exchange! */
@@ -349,8 +348,8 @@ TALER_EXCHANGE_parse_reserve_history (
return GNUNET_SYSERR;
}
if (0 >
- TALER_amount_add (&total_out,
- &total_out,
+ TALER_amount_add (total_out,
+ total_out,
&rh->amount))
{
/* overflow in history already!? inconceivable! Bad exchange! */
@@ -366,23 +365,6 @@ TALER_EXCHANGE_parse_reserve_history (
return GNUNET_SYSERR;
}
}
-
- /* check balance = total_in - total_out < withdraw-amount */
- if (NULL != balance)
- {
- /* if balance is NULL, we may have a partial history
- in which case the subtraction may fail, so we do
- not even check that invariant in this case. */
- if (0 >
- TALER_amount_subtract (balance,
- &total_in,
- &total_out))
- {
- /* total_in < total_out, why did the exchange ever allow this!? */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
return GNUNET_OK;
}
diff --git a/src/lib/exchange_api_reserves_history.c b/src/lib/exchange_api_reserves_history.c
index c0f6c42d2..d9c42d691 100644
--- a/src/lib/exchange_api_reserves_history.c
+++ b/src/lib/exchange_api_reserves_history.c
@@ -91,7 +91,6 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh,
{
json_t *history;
unsigned int len;
- struct TALER_Amount history_balance;
struct TALER_EXCHANGE_ReserveHistory rs = {
.hr.reply = j,
.hr.http_status = MHD_HTTP_OK
@@ -123,15 +122,13 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh,
rhistory = GNUNET_new_array (len,
struct TALER_EXCHANGE_ReserveHistoryEntry);
- // FIXME: even this history could be partial
- // (if the reserve is too old!); update API
- // and return incoming & outgoing totals separately?
if (GNUNET_OK !=
TALER_EXCHANGE_parse_reserve_history (rsh->exchange,
history,
&rsh->reserve_pub,
rs.details.ok.balance.currency,
- &history_balance,
+ &rs.details.ok.total_in,
+ &rs.details.ok.total_out,
len,
rhistory))
{
diff --git a/src/lib/exchange_api_reserves_status.c b/src/lib/exchange_api_reserves_status.c
index a99a080bc..eecd40b9c 100644
--- a/src/lib/exchange_api_reserves_status.c
+++ b/src/lib/exchange_api_reserves_status.c
@@ -127,7 +127,8 @@ handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh,
history,
&rsh->reserve_pub,
rs.details.ok.balance.currency,
- NULL,
+ &rs.details.ok.total_in,
+ &rs.details.ok.total_out,
len,
rhistory))
{
diff --git a/src/lib/exchange_api_withdraw2.c b/src/lib/exchange_api_withdraw2.c
index bc138db0f..a5371442f 100644
--- a/src/lib/exchange_api_withdraw2.c
+++ b/src/lib/exchange_api_withdraw2.c
@@ -148,7 +148,8 @@ reserve_withdraw_payment_required (
const json_t *json)
{
struct TALER_Amount balance;
- struct TALER_Amount balance_from_history;
+ struct TALER_Amount total_in_from_history;
+ struct TALER_Amount total_out_from_history;
json_t *history;
size_t len;
struct GNUNET_JSON_Specification spec[] = {
@@ -197,7 +198,8 @@ reserve_withdraw_payment_required (
history,
&wh->reserve_pub,
balance.currency,
- &balance_from_history,
+ &total_in_from_history,
+ &total_out_from_history,
len,
rhistory))
{
@@ -210,14 +212,6 @@ reserve_withdraw_payment_required (
len);
}
- if (0 !=
- TALER_amount_cmp (&balance_from_history,
- &balance))
- {
- /* exchange cannot add up balances!? */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
/* Check that funds were really insufficient */
if (0 >= TALER_amount_cmp (&wh->requested_amount,
&balance))