diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2023-12-05 22:34:32 +0900 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2023-12-05 22:34:32 +0900 |
commit | efafdf44d91779d89ebd86c3d0454493bc2603f4 (patch) | |
tree | 7c64dd5c0a68779dc1b4e384d74f512e295c32de | |
parent | d324d7c1873bfcde63563e7a10d16b480627abbc (diff) | |
parent | 4347393e44ca59e305514eeb0d11638c8c38f07d (diff) |
Merge branch 'master' of git+ssh://git.taler.net/exchange
-rw-r--r-- | src/exchange/taler-exchange-httpd_batch-deposit.c | 17 | ||||
-rw-r--r-- | src/extensions/extensions.c | 15 | ||||
-rw-r--r-- | src/include/taler_extensions.h | 2 | ||||
-rw-r--r-- | src/include/taler_extensions_policy.h | 15 | ||||
-rw-r--r-- | src/util/currencies.conf | 9 |
5 files changed, 46 insertions, 12 deletions
diff --git a/src/exchange/taler-exchange-httpd_batch-deposit.c b/src/exchange/taler-exchange-httpd_batch-deposit.c index baf2b964d..9f66a99a4 100644 --- a/src/exchange/taler-exchange-httpd_batch-deposit.c +++ b/src/exchange/taler-exchange-httpd_batch-deposit.c @@ -28,6 +28,7 @@ #include <jansson.h> #include <microhttpd.h> #include <pthread.h> +#include "taler_extensions_policy.h" #include "taler_json_lib.h" #include "taler_mhd_lib.h" #include "taler-exchange-httpd_batch-deposit.h" @@ -168,7 +169,7 @@ batch_deposit_transaction (void *cls, { struct BatchDepositContext *dc = cls; const struct TALER_EXCHANGEDB_BatchDeposit *bd = &dc->bd; - enum GNUNET_DB_QueryStatus qs = GNUNET_SYSERR; + enum GNUNET_DB_QueryStatus qs = GNUNET_DB_STATUS_HARD_ERROR; uint32_t bad_balance_coin_index = UINT32_MAX; bool balance_ok; bool in_conflict; @@ -185,8 +186,9 @@ batch_deposit_transaction (void *cls, &dc->policy_details.fulfillment_state); if (qs < 0) return qs; - /* FIXME-Oec: dc->bd.policy_blocked not initialized, - likely should be set based on fulfillment_state!?*/ + + dc->bd.policy_blocked = + dc->policy_details.fulfillment_state != TALER_PolicyFulfillmentSuccess; } /* FIXME: replace by batch insert! */ @@ -523,9 +525,7 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc, return MHD_YES; /* failure */ } } - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (TEH_currency, - &dc.policy_details.accumulated_total)); + /* validate merchant's wire details (as far as we can) */ { char *emsg; @@ -578,13 +578,18 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc, if (GNUNET_OK != TALER_extensions_create_policy_details ( + TEH_currency, dc.policy_json, &dc.policy_details, &error_hint)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED, error_hint); + } TALER_deposit_policy_hash (dc.policy_json, &dc.h_policy); diff --git a/src/extensions/extensions.c b/src/extensions/extensions.c index fbbe874fb..999e9317a 100644 --- a/src/extensions/extensions.c +++ b/src/extensions/extensions.c @@ -19,6 +19,7 @@ * @author Özgür Kesim */ #include "platform.h" +#include "taler_extensions_policy.h" #include "taler_util.h" #include "taler_signatures.h" #include "taler_extensions.h" @@ -366,6 +367,7 @@ TALER_extensions_load_manifests ( */ static char *fulfillment2str[] = { + [TALER_PolicyFulfillmentInitial] = "<init>", [TALER_PolicyFulfillmentReady] = "Ready", [TALER_PolicyFulfillmentSuccess] = "Success", [TALER_PolicyFulfillmentFailure] = "Failure", @@ -384,6 +386,7 @@ TALER_policy_fulfillment_state_str ( enum GNUNET_GenericReturnValue TALER_extensions_create_policy_details ( + const char *currency, const json_t *policy_options, struct TALER_PolicyDetails *details, const char **error_hint) @@ -427,8 +430,18 @@ TALER_extensions_create_policy_details ( return GNUNET_NO; } + /* Set state fields in the policy details to initial values. */ + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero (currency, + &details->accumulated_total)); + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero (currency, + &details->policy_fee)); details->deadline = GNUNET_TIME_UNIT_FOREVER_TS; - ret = extension->create_policy_details (policy_options, + details->fulfillment_state = TALER_PolicyFulfillmentInitial; + details->no_policy_fulfillment_id = true; + ret = extension->create_policy_details (currency, + policy_options, details, error_hint); return ret; diff --git a/src/include/taler_extensions.h b/src/include/taler_extensions.h index fe1eac276..1eb567f72 100644 --- a/src/include/taler_extensions.h +++ b/src/include/taler_extensions.h @@ -162,6 +162,7 @@ struct TALER_Extension * (see https://docs.taler.net/core/api-exchange.html#deposit), this handler * will be called before the deposit transaction. * + * @param[in] currency Currency used in the exchange * @param[in] policy_json Details about the policy, provided by the client * during a deposit request. * @param[out] details On success, will contain the details to the policy, @@ -170,6 +171,7 @@ struct TALER_Extension * @return GNUNET_OK if the data was accepted by the extension. */ enum GNUNET_GenericReturnValue (*create_policy_details)( + const char *currency, const json_t *policy_json, struct TALER_PolicyDetails *details, const char **error_hint); diff --git a/src/include/taler_extensions_policy.h b/src/include/taler_extensions_policy.h index 97fc509b4..7750f58f1 100644 --- a/src/include/taler_extensions_policy.h +++ b/src/include/taler_extensions_policy.h @@ -31,21 +31,24 @@ */ enum TALER_PolicyFulfillmentState { + /* Initial state of an fulfillment, before any other state. */ + TALER_PolicyFulfillmentInitial = 0, + /* General error state of an fulfillment. */ - TALER_PolicyFulfillmentFailure = 0, + TALER_PolicyFulfillmentFailure = 1, /* The policy is not yet ready due to insufficient funding. More deposits are * necessary for it to become ready . */ - TALER_PolicyFulfillmentInsufficient = 1, + TALER_PolicyFulfillmentInsufficient = 2, /* The policy is funded and ready, pending */ - TALER_PolicyFulfillmentReady = 2, + TALER_PolicyFulfillmentReady = 3, /* Policy is provably fulfilled. */ - TALER_PolicyFulfillmentSuccess = 3, + TALER_PolicyFulfillmentSuccess = 4, /* Policy fulfillment has timed out */ - TALER_PolicyFulfillmentTimeout = 4, + TALER_PolicyFulfillmentTimeout = 5, TALER_PolicyFulfillmentStateCount = TALER_PolicyFulfillmentTimeout + 1 }; @@ -143,6 +146,7 @@ struct TALER_PolicyFulfillmentTransactionData /* * @brief Extracts policy details from the deposit's policy options and the policy extensions * + * @param[in] currency Currency used in the exchange * @param[in] policy_options JSON of the policy options from a deposit request * @param[out] details On GNUNET_OK, the parsed details * @param[out] error_hint On GNUNET_SYSERR, will contain a hint for the reason why it failed @@ -151,6 +155,7 @@ struct TALER_PolicyFulfillmentTransactionData */ enum GNUNET_GenericReturnValue TALER_extensions_create_policy_details ( + const char *currency, const json_t *policy_options, struct TALER_PolicyDetails *details, const char **error_hint); diff --git a/src/util/currencies.conf b/src/util/currencies.conf index 5f4fcbe60..0fa831bf3 100644 --- a/src/util/currencies.conf +++ b/src/util/currencies.conf @@ -78,3 +78,12 @@ fractional_input_digits = 0 fractional_normal_digits = 0 fractional_trailing_zero_digits = 0 alt_unit_names = {"0":"WAI","3":"KWAI","6":"MWAI","9":"GWAI","12":"Szabo","15":"Finney","18":"Ether","21":"KEther","24":"MEther"} + +[currency-netzbon] +ENABLED=YES +name=NetzBon +code=NETZBON +fractional_input_digits=2 +fractional_normal_digits=2 +fractional_trailing_zero_digits=2 +alt_unit_names = {"0":"NETZBON"} |