From dcbd1a01050142f2a0a6357a51e80184850ca52e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 26 Aug 2021 20:54:51 +0200 Subject: handle currency mismatch --- .../anastasis_authorization_plugin_iban.c | 16 ++++----- src/reducer/anastasis_api_backup_redux.c | 42 +++++++++++++++++----- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/authorization/anastasis_authorization_plugin_iban.c b/src/authorization/anastasis_authorization_plugin_iban.c index 648902a..50fff8d 100644 --- a/src/authorization/anastasis_authorization_plugin_iban.c +++ b/src/authorization/anastasis_authorization_plugin_iban.c @@ -410,19 +410,19 @@ check_payment_ok (void *cls, const struct ANASTASIS_AUTHORIZATION_State *as = cls; struct IBAN_Context *ctx = as->ctx; uint64_t code; + struct TALER_Amount camount; if (GNUNET_OK != extract_code (wire_subject, &code)) return false; - if (GNUNET_OK != - TALER_amount_cmp_currency (&ctx->expected_amount, - amount)) - { - /* currency wrong!? */ - GNUNET_break (0); - return false; - } + /* Database uses 'default' currency, but this + plugin may use a different currency (and the + same goes for the bank). So we fix this by + forcing the currency to be 'right'. */ + camount = *amount; + strcpy (camount.currency, + ctx->expected_amount.currency); if (1 == TALER_amount_cmp (&ctx->expected_amount, amount)) diff --git a/src/reducer/anastasis_api_backup_redux.c b/src/reducer/anastasis_api_backup_redux.c index de6537e..d0268c9 100644 --- a/src/reducer/anastasis_api_backup_redux.c +++ b/src/reducer/anastasis_api_backup_redux.c @@ -102,6 +102,26 @@ add_cost (struct Costs **my_cost, } +/** + * Add amount from @a cost to @a my_cost list. + * + * @param[in,out] my_cost pointer to list to modify + * @param cost amount to add + */ +static void +add_costs (struct Costs **my_cost, + const struct Costs *costs) +{ + for (const struct Costs *pos = costs; + NULL != pos; + pos = pos->next) + { + add_cost (my_cost, + &pos->cost); + } +} + + enum ANASTASIS_BackupState ANASTASIS_backup_state_from_string_ (const char *state_string) { @@ -459,7 +479,7 @@ struct PolicyEntry /** * Recovery fee. */ - struct TALER_Amount usage_fee; + struct Costs *usage_fee; }; @@ -907,10 +927,11 @@ eval_provider_selection (struct PolicyBuilder *pb, challenge_size) ) ) { found = true; - GNUNET_break (0 <= - TALER_amount_add (&policy_ent[i].usage_fee, - &method_cost, - &upload_cost)); + + add_cost (&policy_ent[i].usage_fee, + &method_cost); + add_cost (&policy_ent[i].usage_fee, + &upload_cost); } } if (! found) @@ -962,6 +983,8 @@ eval_provider_selection (struct PolicyBuilder *pb, GNUNET_CONTAINER_DLL_remove (pb->current_policy->pm_head, pb->current_policy->pm_tail, m); + for (unsigned int i = 0; ireq_methods; i++) + free_costs (m->providers[i].usage_fee); GNUNET_free (m->providers); GNUNET_free (m); } @@ -1317,10 +1340,11 @@ evaluate_map (struct PolicyBuilder *pb, duplicates++; /* penalty for same challenge at two providers */ } } - if (found) - continue; /* cost already included, do not add */ - add_cost (&my_cost, - &pe->usage_fee); + if (! found) + { + add_costs (&my_cost, + pe->usage_fee); + } } } -- cgit v1.2.3