[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: add multi-currency support
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: add multi-currency support |
Date: |
Fri, 02 Apr 2021 21:25:46 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 8330c4d add multi-currency support
8330c4d is described below
commit 8330c4db9b8e22e60678d2a4a198e1bab420bb17
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Apr 2 21:25:40 2021 +0200
add multi-currency support
---
src/cli/anastasis-cli-redux.c | 4 +-
src/cli/resources/02-backup.json | 2 +-
src/cli/resources/02-recovery.json | 2 +-
src/cli/resources/03-backup.json | 2 +-
src/cli/resources/04-backup.json | 2 +-
src/cli/resources/05-backup.json | 2 +-
src/cli/resources/06-backup.json | 2 +-
...astasis_reducer_backup_enter_user_attributes.sh | 7 --
...tasis_reducer_recovery_enter_user_attributes.sh | 4 +-
src/cli/test_anastasis_reducer_select_country.sh | 8 +-
src/reducer/anastasis_api_backup_redux.c | 102 +--------------------
src/reducer/anastasis_api_redux.c | 49 +++++++---
12 files changed, 50 insertions(+), 136 deletions(-)
diff --git a/src/cli/anastasis-cli-redux.c b/src/cli/anastasis-cli-redux.c
index bab0afe..6ac40b7 100644
--- a/src/cli/anastasis-cli-redux.c
+++ b/src/cli/anastasis-cli-redux.c
@@ -145,8 +145,8 @@ action_cb (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Redux failed with error %d: %s\n",
- TALER_JSON_get_error_code (result_state),
- TALER_JSON_get_error_hint (result_state));
+ error_code,
+ TALER_ErrorCode_get_hint (error_code));
}
GNUNET_SCHEDULER_shutdown ();
global_ret = (TALER_EC_NONE != error_code) ? 1 : 0;
diff --git a/src/cli/resources/02-backup.json b/src/cli/resources/02-backup.json
index be35cdc..c9bba16 100644
--- a/src/cli/resources/02-backup.json
+++ b/src/cli/resources/02-backup.json
@@ -45,7 +45,7 @@
"http://localhost:8089/": {}
},
"selected_country": "xx",
- "currency": "TESTKUDOS",
+ "currencies": [ "TESTKUDOS" ],
"required_attributes": [
{
"type": "string",
diff --git a/src/cli/resources/02-recovery.json
b/src/cli/resources/02-recovery.json
index 93804e6..79cfd6d 100644
--- a/src/cli/resources/02-recovery.json
+++ b/src/cli/resources/02-recovery.json
@@ -45,7 +45,7 @@
"http://localhost:8089/": {}
},
"selected_country": "xx",
- "currency": "TESTKUDOS",
+ "currencies": [ "TESTKUDOS" ],
"required_attributes": [
{
"type": "string",
diff --git a/src/cli/resources/03-backup.json b/src/cli/resources/03-backup.json
index c69126f..9d599d7 100644
--- a/src/cli/resources/03-backup.json
+++ b/src/cli/resources/03-backup.json
@@ -113,7 +113,7 @@
}
},
"selected_country": "xx",
- "currency": "TESTKUDOS",
+ "currencies": ["TESTKUDOS"],
"required_attributes": [
{
"type": "string",
diff --git a/src/cli/resources/04-backup.json b/src/cli/resources/04-backup.json
index 7e42311..38ac95f 100644
--- a/src/cli/resources/04-backup.json
+++ b/src/cli/resources/04-backup.json
@@ -113,7 +113,7 @@
}
},
"selected_country": "xx",
- "currency": "TESTKUDOS",
+ "currencies": [ "TESTKUDOS" ],
"required_attributes": [
{
"type": "string",
diff --git a/src/cli/resources/05-backup.json b/src/cli/resources/05-backup.json
index a55a608..5ec235c 100644
--- a/src/cli/resources/05-backup.json
+++ b/src/cli/resources/05-backup.json
@@ -113,7 +113,7 @@
}
},
"selected_country": "xx",
- "currency": "TESTKUDOS",
+ "currencies": [ "TESTKUDOS" ],
"required_attributes": [
{
"type": "string",
diff --git a/src/cli/resources/06-backup.json b/src/cli/resources/06-backup.json
index 81a2e9f..4553a8b 100644
--- a/src/cli/resources/06-backup.json
+++ b/src/cli/resources/06-backup.json
@@ -113,7 +113,7 @@
}
},
"selected_country": "xx",
- "currency": "TESTKUDOS",
+ "currencies": ["TESTKUDOS"],
"required_attributes": [
{
"type": "string",
diff --git a/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
b/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
index 7db0dae..c68894d 100755
--- a/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_backup_enter_user_attributes.sh
@@ -124,7 +124,6 @@ fi
echo "OK"
-
echo -n "Test user attributes collection in a recovery state ..."
anastasis-reducer -a \
'{"identity_attributes": {
@@ -133,12 +132,6 @@ anastasis-reducer -a \
"birthdate": "2000-01-01"}}' \
enter_user_attributes resources/02-recovery.json $TFILE 2> /dev/null &&
exit_fail "Expected recovery to fail due to lacking policy data"
-CODE=`jq -r -e .code < $TFILE`
-if test "$CODE" != "8410"
-then
- exit_fail "Expected error code to be '8410', got '$CODE'"
-fi
-
echo "OK"
rm -f $TFILE
diff --git a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
index 771f974..1a7ba7b 100755
--- a/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_recovery_enter_user_attributes.sh
@@ -277,7 +277,7 @@ anastasis-reducer -a \
echo -n "."
anastasis-reducer -a \
'{"country_code": "xx",
- "currency":"TESTKUDOS"}' \
+ "currencies":["TESTKUDOS"]}' \
select_country < $B2FILE > $B1FILE
echo -n "."
anastasis-reducer -a \
@@ -400,7 +400,7 @@ anastasis-reducer -a \
select_continent < $R1FILE > $R2FILE
anastasis-reducer -a \
'{"country_code": "xx",
- "currency":"TESTKUDOS"}' \
+ "currencies":["TESTKUDOS"]}' \
select_country < $R2FILE > $R1FILE
anastasis-reducer -a '{"identity_attributes": { "full_name": "Max Musterman",
"sq_number": "4", "birthdate": "2000-01-01" }}' enter_user_attributes < $R1FILE
> $R2FILE
diff --git a/src/cli/test_anastasis_reducer_select_country.sh
b/src/cli/test_anastasis_reducer_select_country.sh
index 42d0e23..db17052 100755
--- a/src/cli/test_anastasis_reducer_select_country.sh
+++ b/src/cli/test_anastasis_reducer_select_country.sh
@@ -84,7 +84,7 @@ echo -n "Test NX country selection ..."
anastasis-reducer -a \
'{"country_code": "zz",
- "currency":"EUR"}' \
+ "currencies": ["EUR" ]}' \
select_country \
resources/01-backup.json $TFILE 2> /dev/null \
&& exit_fail "Expected selection to fail. Check '$TFILE'"
@@ -95,7 +95,7 @@ echo -n "Test invalid country selection for continent ..."
anastasis-reducer -a \
'{"country_code": "de",
- "currency":"EUR"}' \
+ "currencies":["EUR"]}' \
select_country \
resources/01-backup.json $TFILE 2> /dev/null \
&& exit_fail "Expected selection to fail. Check '$TFILE'"
@@ -106,7 +106,7 @@ echo -n "Test country selection ..."
anastasis-reducer -a \
'{"country_code": "xx",
- "currency":"TESTKUDOS"}' \
+ "currencies":["TESTKUDOS"]}' \
select_country resources/01-backup.json $TFILE
STATE=`jq -r -e .backup_state < $TFILE`
@@ -121,7 +121,7 @@ then
exit_fail "Expected selected country to be 'xx', got '$SELECTED_COUNTRY'"
fi
echo -n "."
-SELECTED_CURRENCY=`jq -r -e .currency < $TFILE`
+SELECTED_CURRENCY=`jq -r -e .currencies[0] < $TFILE`
if test "$SELECTED_CURRENCY" != "TESTKUDOS"
then
exit_fail "Expected selected currency to be 'TESTKUDOS', got
'$SELECTED_CURRENCY'"
diff --git a/src/reducer/anastasis_api_backup_redux.c
b/src/reducer/anastasis_api_backup_redux.c
index b1c2543..ec80434 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -317,12 +317,6 @@ del_authentication (json_t *state,
*/
struct PolicyBuilder
{
- /**
- * Financial cost of the providers selected in @e best_sel.
- * Only valid during the go_with() function.
- */
- struct TALER_Amount best_cost;
-
/**
* Authentication providers available overall, from our state.
*/
@@ -338,11 +332,6 @@ struct PolicyBuilder
*/
json_t *policies;
- /**
- * Currency we are using.
- */
- const char *currency;
-
/**
* Array of length @e req_methods.
*/
@@ -397,14 +386,8 @@ static void
eval_provider_selection (struct PolicyBuilder *pb,
const char *prov_sel[])
{
- struct TALER_Amount curr_cost;
unsigned int curr_diversity;
- /* most hold here, as invariant passed earlier in go_with() */
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_get_zero (pb->currency,
- &curr_cost));
-
/* calculate cost */
for (unsigned int i = 0; i < pb->req_methods; i++)
{
@@ -450,19 +433,6 @@ eval_provider_selection (struct PolicyBuilder *pb,
if (0 == strcmp (type,
method_type))
{
- if ( (GNUNET_YES !=
- TALER_amount_cmp_currency (&curr_cost,
- &method_cost)) ||
- (0 >
- TALER_amount_add (&curr_cost,
- &curr_cost,
- &method_cost)) )
- {
- GNUNET_break (0);
- pb->ec = TALER_EC_ANASTASIS_REDUCER_STATE_INVALID;
- pb->hint = "'usage_fee' addition failure";
- return;
- }
found = true;
}
}
@@ -493,17 +463,10 @@ eval_provider_selection (struct PolicyBuilder *pb,
}
if (curr_diversity < pb->best_diversity)
return;
- if ( (GNUNET_YES ==
- TALER_amount_cmp_currency (&curr_cost,
- &pb->best_cost)) &&
- (0 < TALER_amount_cmp (&curr_cost,
- &pb->best_cost)) )
- return;
memcpy (pb->best_sel,
prov_sel,
sizeof (const char *) * pb->req_methods);
pb->best_diversity = curr_diversity;
- pb->best_cost = curr_cost;
}
@@ -554,7 +517,6 @@ static void
go_with (struct PolicyBuilder *pb)
{
const unsigned int *m_idx = pb->m_idx;
- struct TALER_Amount recovery_cost;
const char *best_sel[pb->req_methods];
const char *prov_sel[pb->req_methods];
json_t *method_arr;
@@ -562,28 +524,9 @@ go_with (struct PolicyBuilder *pb)
/* compute best provider selection (store in best_sel) */
pb->best_diversity = 0;
pb->best_sel = best_sel;
- memset (&pb->best_cost,
- 0,
- sizeof (struct TALER_Amount));
provider_candidate (pb,
prov_sel,
0);
- if (GNUNET_OK !=
- TALER_amount_get_zero (pb->currency,
- &recovery_cost))
- {
- pb->ec = TALER_EC_ANASTASIS_REDUCER_STATE_INVALID;
- pb->hint = "'currency' invalid";
- return;
- }
- if (GNUNET_OK !=
- TALER_amount_is_valid (&pb->best_cost))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Did not find providers supporting requested authorization
methods\n");
- return;
- }
-
/* Convert best_sel to entry in 'policies' array */
method_arr = json_array ();
GNUNET_assert (NULL != method_arr);
@@ -599,9 +542,7 @@ go_with (struct PolicyBuilder *pb)
policy_method));
}
{
- json_t *policy = json_pack ("{s:o, s:o}",
- "recovery_cost",
- TALER_JSON_from_amount (&pb->best_cost),
+ json_t *policy = json_pack ("{s:o}",
"methods",
method_arr);
GNUNET_assert (NULL != policy);
@@ -667,16 +608,6 @@ done_authentication (json_t *state,
.ec = TALER_EC_NONE
};
- pb.currency = json_string_value (json_object_get (state,
- "currency"));
- if (NULL == pb.currency)
- {
- ANASTASIS_redux_fail_ (cb,
- cb_cls,
- TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
- "'currency' must be provided");
- return NULL;
- }
pb.providers = json_object_get (state,
"authentication_providers");
if ( (NULL == pb.providers) ||
@@ -815,8 +746,6 @@ add_policy (json_t *state,
const json_t *auth_providers;
const json_t *auth_methods;
json_t *methods;
- struct TALER_Amount recovery_cost;
- const char *currency;
if (NULL == arguments)
{
@@ -846,19 +775,6 @@ add_policy (json_t *state,
"'policies' not an array");
return NULL;
}
- currency = json_string_value (json_object_get (state,
- "currency"));
- if ( (NULL == currency) ||
- (GNUNET_OK !=
- TALER_amount_get_zero (currency,
- &recovery_cost)) )
- {
- ANASTASIS_redux_fail_ (cb,
- cb_cls,
- TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
- "'currency' must be a vaild currency");
- return NULL;
- }
auth_providers = json_object_get (state,
"authentication_providers");
if (! json_is_object (auth_providers))
@@ -999,18 +915,6 @@ add_policy (json_t *state,
if (0 != strcmp (type,
method_type))
continue;
- if (0 >
- TALER_amount_add (&recovery_cost,
- &recovery_cost,
- &method_cost))
- {
- GNUNET_break (0);
- ANASTASIS_redux_fail_ (cb,
- cb_cls,
- TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
- "cost addition failed");
- return NULL;
- }
found = true;
break;
}
@@ -1034,9 +938,7 @@ add_policy (json_t *state,
{
json_t *policy;
- policy = json_pack ("{s:o, s:o}",
- "recovery_cost",
- TALER_JSON_from_amount (&recovery_cost),
+ policy = json_pack ("{s:o}",
"methods",
methods);
GNUNET_assert (NULL != policy);
diff --git a/src/reducer/anastasis_api_redux.c
b/src/reducer/anastasis_api_redux.c
index 1b449fc..73b781f 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -660,12 +660,12 @@ check_config (const char *url)
/**
* Begin asynchronous check for provider configurations.
*
- * @param currency the currency to initiate the provider checks for
+ * @param currencies the currencies to initiate the provider checks for
* @param[in,out] state to set provider list for
* @return #TALER_EC_NONE on success
*/
static enum TALER_ErrorCode
-begin_provider_config_check (const char *currency,
+begin_provider_config_check (const json_t *currencies,
json_t *state)
{
if (NULL == provider_list)
@@ -732,9 +732,27 @@ begin_provider_config_check (const char *currency,
return TALER_EC_ANASTASIS_REDUCER_RESOURCE_MALFORMED;
}
- if (0 != strcasecmp (currency,
- cur))
- continue;
+ {
+ bool found = false;
+ json_t *cu;
+ size_t off;
+
+ json_array_foreach (currencies, off, cu)
+ {
+ const char *currency;
+
+ currency = json_string_value (cu);
+ if (NULL == currency)
+ {
+ json_decref (pl);
+ return TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID;
+ }
+ found = (0 == strcasecmp (currency,
+ cur));
+ }
+ if (! found)
+ continue;
+ }
GNUNET_assert (0 ==
json_object_set_new (pl,
url,
@@ -966,7 +984,7 @@ select_country (json_t *state,
{
const json_t *required_attrs;
const json_t *country_code;
- const char *currency;
+ const json_t *currencies;
const json_t *redux_id_attr;
if (NULL == arguments)
@@ -1016,14 +1034,15 @@ select_country (json_t *state,
}
}
- currency = json_string_value (json_object_get (arguments,
- "currency"));
- if (NULL == currency)
+ currencies = json_object_get (arguments,
+ "currencies");
+ if ( (NULL == currencies) ||
+ (! json_is_array (currencies)) )
{
ANASTASIS_redux_fail_ (cb,
cb_cls,
TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
- "'currency' missing");
+ "'currencies' missing");
return NULL;
}
/* We now have an idea of the currency, begin fetching
@@ -1031,7 +1050,7 @@ select_country (json_t *state,
{
enum TALER_ErrorCode ec;
- ec = begin_provider_config_check (currency,
+ ec = begin_provider_config_check (currencies,
state);
if (TALER_EC_NONE != ec)
{
@@ -1039,7 +1058,7 @@ select_country (json_t *state,
ANASTASIS_redux_fail_ (cb,
cb_cls,
ec,
- currency);
+ NULL);
return NULL;
}
}
@@ -1070,9 +1089,9 @@ select_country (json_t *state,
"selected_country",
(json_t *) country_code));
GNUNET_assert (0 ==
- json_object_set_new (state,
- "currency",
- json_string (currency)));
+ json_object_set (state,
+ "currencies",
+ (json_t *) currencies));
GNUNET_assert (0 ==
json_object_set (state,
"required_attributes",
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: add multi-currency support,
gnunet <=