commit c162b07f9dfe70b1b94de19657899d7ad921d413
parent 91f7ed518e0e44911e54cc2a12b1e8b185dd3e31
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 8 Apr 2025 13:59:07 +0200
kyc-related fixes
Diffstat:
7 files changed, 68 insertions(+), 65 deletions(-)
diff --git a/src/kyclogic/kyclogic_api.c b/src/kyclogic/kyclogic_api.c
@@ -712,65 +712,67 @@ TALER_KYCLOGIC_rules_parse (const json_t *jlrs)
}
}
}
-
- lrs->custom_measures
- = GNUNET_new_array (lrs->num_custom_measures,
- struct TALER_KYCLOGIC_Measure);
-
+ if (0 != lrs->num_custom_measures)
{
- const json_t *jmeasure;
- const char *measure_name;
- unsigned int off = 0;
+ lrs->custom_measures
+ = GNUNET_new_array (lrs->num_custom_measures,
+ struct TALER_KYCLOGIC_Measure);
- json_object_foreach ((json_t *) jcustom_measures,
- measure_name,
- jmeasure)
{
- const char *check_name;
- const char *prog_name;
- const json_t *context = NULL;
- bool voluntary = false;
- struct TALER_KYCLOGIC_Measure *measure
- = &lrs->custom_measures[off++];
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_string ("check_name",
- &check_name),
- GNUNET_JSON_spec_string ("prog_name",
- &prog_name),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_object_const ("context",
- &context),
- NULL),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_bool ("voluntary",
- &voluntary),
- NULL),
- GNUNET_JSON_spec_end ()
- };
+ const json_t *jmeasure;
+ const char *measure_name;
+ unsigned int off = 0;
- if (GNUNET_OK !=
- GNUNET_JSON_parse (jmeasure,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- goto cleanup;
- }
- measure->measure_name
- = GNUNET_strdup (measure_name);
- measure->check_name
- = GNUNET_strdup (check_name);
- measure->prog_name
- = GNUNET_strdup (prog_name);
- measure->voluntary
- = voluntary;
- if (NULL != context)
- measure->context
- = json_incref ((json_t*) context);
- if (! check_measure (measure))
+ json_object_foreach ((json_t *) jcustom_measures,
+ measure_name,
+ jmeasure)
{
- GNUNET_break_op (0);
- goto cleanup;
+ const char *check_name;
+ const char *prog_name;
+ const json_t *context = NULL;
+ bool voluntary = false;
+ struct TALER_KYCLOGIC_Measure *measure
+ = &lrs->custom_measures[off++];
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_string ("check_name",
+ &check_name),
+ GNUNET_JSON_spec_string ("prog_name",
+ &prog_name),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_object_const ("context",
+ &context),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_bool ("voluntary",
+ &voluntary),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (jmeasure,
+ ispec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
+ measure->measure_name
+ = GNUNET_strdup (measure_name);
+ measure->check_name
+ = GNUNET_strdup (check_name);
+ measure->prog_name
+ = GNUNET_strdup (prog_name);
+ measure->voluntary
+ = voluntary;
+ if (NULL != context)
+ measure->context
+ = json_incref ((json_t*) context);
+ if (! check_measure (measure))
+ {
+ GNUNET_break_op (0);
+ goto cleanup;
+ }
}
}
}
diff --git a/src/kyclogic/taler-exchange-helper-measure-enable-deposits b/src/kyclogic/taler-exchange-helper-measure-enable-deposits
@@ -63,7 +63,7 @@ do
;;
r)
# What to do next?
- echo "expiration_time"
+ echo "validity_years"
echo "successor_measure"
exit 0
;;
@@ -96,7 +96,12 @@ TOS_ACCEPTED=$(echo "$INPUTS" | jq '.attributes.ACCEPTED_TERMS_OF_SERVICE // nul
# Get current rules.
CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null')
# Get context values.
-EXPIRATION_TIME=$(echo "$INPUTS" | jq '.context.expiration_time // .current_rules.expiration_time // null')
+VALIDITY_YEARS=$(echo "$INPUTS" | jq '.context.validity_years)
+# Convert to seconds after epoch
+EXPIRATION_STAMP=$(($VALIDITY_YEARS * 365 * 24 * 60 * 60 + $(date +%s)))
+# Convert to GNUnet-style JSON timestamp
+EXPIRATION_TIME=$(jq -n --argjson es "$EXPIRATION_STAMP" '{"t_s":$es}')
+
SUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.context.successor_measure // .current_rules.successor_measure // null')
# Validate accepted ToS version
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-3rdparty-check b/src/kyclogic/taler-exchange-helper-measure-tops-3rdparty-check
@@ -140,7 +140,7 @@ jq -n \
--argjson sm "$SUCCESSOR_MEASURE" \
--argjson cm "$CUSTOM_MEASURES" \
--argjson nr "$NEW_RULES" \
- '{"to_investigate":$inv,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":($nr.custom_measures+$cm)})}|del(..|nulls)'
+ '{"to_investigate":$inv,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cm)})}|del(..|nulls)'
# FIXME: If we keep nr.custom_measures in "custom_measures", should we not ".del()" them from "new_rules"?
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-address-check b/src/kyclogic/taler-exchange-helper-measure-tops-address-check
@@ -890,6 +890,6 @@ jq \
--argjson sm "$SUCCESSOR_MEASURE" \
--argjson cm "$CUSTOM_MEASURES" \
--argjson nr "$NEW_RULES" \
- '{"new_rules":$nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":($nr.custom_measures+$cm)}}|del(..|nulls)'
+ '{"new_rules":$nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cm)}}|del(..|nulls)'
exit 0
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-postal-check b/src/kyclogic/taler-exchange-helper-measure-tops-postal-check
@@ -65,8 +65,6 @@ do
exit 0
;;
r)
- # When does the check expire?
- echo "expiration_time"
exit 0
;;
v)
@@ -125,7 +123,7 @@ jq -n \
--argjson sm "$SUCCESSOR_MEASURE" \
--argjson cm "$CUSTOM_MEASURES" \
--argjson nr "$NEW_RULES" \
- '{"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":($nr.custom_measures+$cm)})}|del(..|nulls)'
+ '{"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cm)})}|del(..|nulls)'
# FIXME: If we keep nr.custom_measures in "custom_measures", should we not ".del()" them from "new_rules"?
exit 0
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-sms-check b/src/kyclogic/taler-exchange-helper-measure-tops-sms-check
@@ -61,8 +61,6 @@ do
exit 0
;;
r)
- # When does the check expire?
- echo "expiration_time"
exit 0
;;
v)
@@ -122,7 +120,7 @@ jq -n \
--argjson sm "$SUCCESSOR_MEASURE" \
--argjson cm "$CUSTOM_MEASURES" \
--argjson nr "$NEW_RULES" \
- '{"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":($nr.custom_measures+$cm)})}|del(..|nulls)'
+ '{"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cm)})}|del(..|nulls)'
# FIXME: If we keep nr.custom_measures in "custom_measures", should we not ".del()" them from "new_rules"?
exit 0
diff --git a/src/kyclogic/taler-exchange-helper-measure-update-from-context b/src/kyclogic/taler-exchange-helper-measure-update-from-context
@@ -108,6 +108,6 @@ echo "$INPUTS" \
--argjson sm "$SUCCESSOR_MEASURE" \
--argjson cm "$CUSTOM_MEASURES" \
--argjson nr "$NEW_RULES" \
- '.current_rules+{"new_rules":(.current_rules.new_rules+{"expiration_time":$et,"successor_measure":$sm,"rules":(.current_rules.new_rules.rules+$nr),"custom_measures":(.current_rules.custom_measures+$cm)})}|del(..|nulls)'
+ '.current_rules+{"new_rules":(.current_rules.new_rules+{"expiration_time":$et,"successor_measure":$sm,"rules":(.current_rules.new_rules.rules+$nr),"custom_measures":({}+.current_rules.custom_measures+$cm)})}|del(..|nulls)'
exit 0