exchange

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

update_rules.h (3612B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file update_rules.h
     18  * @brief implementation to update rules for an account
     19  * @author Christian Grothoff
     20  */
     21 #ifndef EXCHANGE_DATABASE_UPDATE_RULES_H
     22 #define EXCHANGE_DATABASE_UPDATE_RULES_H
     23 
     24 #include "taler/taler_util.h"
     25 #include "taler/taler_json_lib.h"
     26 #include "taler/taler_exchangedb_lib.h"
     27 
     28 
     29 /**
     30  * Handle for helper logic that advances rules to the currently
     31  * valid rule set.
     32  */
     33 struct TALER_EXCHANGEDB_RuleUpdater;
     34 
     35 /**
     36  * Main result returned in the
     37  * #TALER_EXCHANGEDB_CurrentRulesCallback
     38  */
     39 struct TALER_EXCHANGEDB_RuleUpdaterResult
     40 {
     41   /**
     42    * Row the rule set is based on.
     43    */
     44   uint64_t legitimization_outcome_last_row;
     45 
     46   /**
     47    * Current legitimization rule set, owned by callee.  Will be NULL on error
     48    * or for default rules. Will not contain skip rules and not be expired.
     49    */
     50   struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs;
     51 
     52   /**
     53    * Hint to return, if @e ec is not #TALER_EC_NONE. Can be NULL.
     54    */
     55   const char *hint;
     56 
     57   /**
     58    * Error code in case a problem was encountered
     59    * when fetching or updating the legitimization rules.
     60    */
     61   enum TALER_ErrorCode ec;
     62 };
     63 
     64 
     65 /**
     66  * Function called with the current rule set.
     67  *
     68  * @param cls closure
     69  * @param rur includes legitimziation rule set that applies to the account
     70  *   (owned by callee, callee must free the lrs!)
     71  */
     72 typedef void
     73 (*TALER_EXCHANGEDB_CurrentRulesCallback)(
     74   void *cls,
     75   struct TALER_EXCHANGEDB_RuleUpdaterResult *rur);
     76 
     77 
     78 /**
     79  * Obtains the current rule set for an account and advances it
     80  * to the rule set that should apply right now. Considers
     81  * expiration of rules as well as "skip" measures. Runs
     82  * AML programs as needed to advance the rule book to the currently
     83  * valid state.
     84  *
     85  * On success, the result is returned in a (fresh) transaction
     86  * that must be committed for the result to be valid. This should
     87  * be used to ensure transactionality of the AML program result.
     88  *
     89  * This function should be called *outside* of any other transaction.
     90  * Calling it while a transaction is already running risks aborting
     91  * that transaction.
     92  *
     93  * @param pg database plugin to use
     94  * @param attribute_key key to use to decrypt attributes
     95  * @param account account to get the rule set for
     96  * @param is_wallet true if @a account is a wallet
     97  * @param cb function to call with the result
     98  * @param cb_cls closure for @a cb
     99  * @return handle to cancel the operation
    100  */
    101 struct TALER_EXCHANGEDB_RuleUpdater *
    102 TALER_EXCHANGEDB_update_rules (
    103   struct TALER_EXCHANGEDB_PostgresContext *pg,
    104   const struct TALER_AttributeEncryptionKeyP *attribute_key,
    105   const struct TALER_NormalizedPaytoHashP *account,
    106   bool is_wallet,
    107   TALER_EXCHANGEDB_CurrentRulesCallback cb,
    108   void *cb_cls);
    109 
    110 
    111 /**
    112  * Cancel operation to get the current legitimization rule set.
    113  *
    114  * @param[in] ru operation to cancel
    115  */
    116 void
    117 TALER_EXCHANGEDB_update_rules_cancel (
    118   struct TALER_EXCHANGEDB_RuleUpdater *ru);
    119 
    120 
    121 #endif