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 (3877B)


      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 "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 #ifndef TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE
     73 /**
     74  * Type of the closure for #TALER_EXCHANGEDB_CurrentRulesCallback.
     75  */
     76 #define TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE void
     77 #endif
     78 typedef void
     79 (*TALER_EXCHANGEDB_CurrentRulesCallback)(
     80   TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE *cls,
     81   struct TALER_EXCHANGEDB_RuleUpdaterResult *rur);
     82 
     83 
     84 /**
     85  * Obtains the current rule set for an account and advances it
     86  * to the rule set that should apply right now. Considers
     87  * expiration of rules as well as "skip" measures. Runs
     88  * AML programs as needed to advance the rule book to the currently
     89  * valid state.
     90  *
     91  * On success, the result is returned in a (fresh) transaction
     92  * that must be committed for the result to be valid. This should
     93  * be used to ensure transactionality of the AML program result.
     94  *
     95  * This function should be called *outside* of any other transaction.
     96  * Calling it while a transaction is already running risks aborting
     97  * that transaction.
     98  *
     99  * @param pg database plugin to use
    100  * @param attribute_key key to use to decrypt attributes
    101  * @param account account to get the rule set for
    102  * @param is_wallet true if @a account is a wallet
    103  * @param cb function to call with the result
    104  * @param cb_cls closure for @a cb
    105  * @return handle to cancel the operation
    106  */
    107 struct TALER_EXCHANGEDB_RuleUpdater *
    108 TALER_EXCHANGEDB_update_rules (
    109   struct TALER_EXCHANGEDB_PostgresContext *pg,
    110   const struct TALER_AttributeEncryptionKeyP *attribute_key,
    111   const struct TALER_NormalizedPaytoHashP *account,
    112   bool is_wallet,
    113   TALER_EXCHANGEDB_CurrentRulesCallback cb,
    114   TALER_EXCHANGEDB_CURRENT_RULES_RESULT_CLOSURE *cb_cls);
    115 
    116 
    117 /**
    118  * Cancel operation to get the current legitimization rule set.
    119  *
    120  * @param[in] ru operation to cancel
    121  */
    122 void
    123 TALER_EXCHANGEDB_update_rules_cancel (
    124   struct TALER_EXCHANGEDB_RuleUpdater *ru);
    125 
    126 
    127 #endif