exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 7015c4e14885fb02c126472a82893f1dc6657d62
parent 6866e1580e7298acb5affb5b768faf3900875f5c
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 10 Sep 2024 15:15:49 +0200

add TALER_amount_min

Diffstat:
Msrc/include/taler_amount_lib.h | 14++++++++++++++
Msrc/include/taler_exchange_service.h | 34++++++++++++++++++++++++++++++++++
Msrc/lib/exchange_api_restrictions.c | 45++++++++++++++++++++++++++++++++++++++++++++-
Msrc/util/amount.c | 23+++++++++++++++++++++++
4 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/src/include/taler_amount_lib.h b/src/include/taler_amount_lib.h @@ -265,6 +265,20 @@ TALER_amount_max (struct TALER_Amount *ma, /** + * Compute minimum of two amounts. + * + * @param[out] mi set to minimum of @a a1 and @a a2 + * @param a1 first amount + * @param a2 second amount + * @return #GNUNET_OK on success + */ +enum GNUNET_GenericReturnValue +TALER_amount_min (struct TALER_Amount *mi, + const struct TALER_Amount *a1, + const struct TALER_Amount *a2); + + +/** * Compare the value/fraction of two amounts. Does not compare the currency. * Comparing amounts of different currencies will cause the program to abort(). * If unsure, check with #TALER_amount_cmp_currency() first to be sure that diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h @@ -1041,6 +1041,40 @@ TALER_EXCHANGE_test_account_allowed ( /** + * Check the hard limits in @a keys for the given + * @a event and lower @a limit to the lowest applicable + * limit independent (!) of the timeframe. Useful + * to determine the absolute transaction limit. + * + * @param keys exchange keys to evaluate + * @param event trigger type to evaluate + * @param[in,out] limit to lower to the minimum limit + * that applies to @a event + */ +void +TALER_EXCHANGE_keys_evaluate_hard_limits ( + const struct TALER_EXCHANGE_Keys *keys, + enum TALER_KYCLOGIC_KycTriggerEvent event, + struct TALER_Amount *limit); + + +/** + * Check if a (soft) limit of zero applies for the + * given @a event under @a keys. + * + * @param keys exchange keys to evaluate + * @param event trigger type to evaluate + * @return true if the operation is soft-limited and + * thus KYC is required before the operation may be + * accepted at the exchange + */ +bool +TALER_EXCHANGE_keys_evaluate_zero_limits ( + const struct TALER_EXCHANGE_Keys *keys, + enum TALER_KYCLOGIC_KycTriggerEvent event); + + +/** * Obtain the denomination key details from the exchange. * * @param keys the exchange's key set diff --git a/src/lib/exchange_api_restrictions.c b/src/lib/exchange_api_restrictions.c @@ -17,7 +17,7 @@ /** * @file lib/exchange_api_restrictions.c * @brief convenience functions related to account restrictions - * @author Christian Grothoff +a * @author Christian Grothoff */ #include "platform.h" #include "taler_exchange_service.h" @@ -96,3 +96,46 @@ TALER_EXCHANGE_test_account_allowed ( } /* end loop over restrictions */ return GNUNET_YES; } + + +void +TALER_EXCHANGE_keys_evaluate_hard_limits ( + const struct TALER_EXCHANGE_Keys *keys, + enum TALER_KYCLOGIC_KycTriggerEvent event, + struct TALER_Amount *limit) +{ + for (unsigned int i = 0; i<keys->hard_limits_length; i++) + { + const struct TALER_EXCHANGE_AccountLimit *al + = &keys->hard_limits[i]; + + if (event != al->operation_type) + continue; + if (al->soft_limit) + continue; + if (! TALER_amount_cmp_currency (limit, + &al->limit)) + continue; + GNUNET_break (GNUNET_OK == + TALER_amount_min (limit, + limit, + &al->limit)); + } +} + + +bool +TALER_EXCHANGE_keys_evaluate_zero_limits ( + const struct TALER_EXCHANGE_Keys *keys, + enum TALER_KYCLOGIC_KycTriggerEvent event) +{ + for (unsigned int i = 0; i<keys->soft_limits_length; i++) + { + const struct TALER_EXCHANGE_ZeroLimitedOperation *zlo + = &keys->zero_limits[i]; + + if (event == zlo->operation_type) + return true; + } + return false; +} diff --git a/src/util/amount.c b/src/util/amount.c @@ -293,6 +293,29 @@ TALER_amount_max (struct TALER_Amount *ma, } +enum GNUNET_GenericReturnValue +TALER_amount_min (struct TALER_Amount *mi, + const struct TALER_Amount *a1, + const struct TALER_Amount *a2) +{ + if (GNUNET_OK != + TALER_amount_cmp_currency (a1, + a2)) + { + memset (mi, + 0, + sizeof (*mi)); + return GNUNET_SYSERR; + } + if (1 == TALER_amount_cmp (a1, + a2)) + *mi = *a2; + else + *mi = *a1; + return GNUNET_OK; +} + + bool TALER_amount_is_zero (const struct TALER_Amount *amount) {