exchange

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

auditordb_lib.h (13982B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2016 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 include/auditordb_lib.h
     18  * @brief high-level interface for the auditor's database
     19  * @author Florian Dold
     20  * @author Benedikt Mueller
     21  * @author Christian Grothoff
     22  */
     23 #ifndef TALER_AUDITORDB_LIB_H
     24 #define TALER_AUDITORDB_LIB_H
     25 
     26 #include <jansson.h>
     27 #include <gnunet/gnunet_util_lib.h>
     28 #include <gnunet/gnunet_db_lib.h>
     29 #include <taler/taler_util.h>
     30 #include <auditordb_lib.h>
     31 
     32 /**
     33  * Connection to the postgres database of the auditor.
     34  */
     35 struct TALER_AUDITORDB_PostgresContext;
     36 
     37 
     38 /**
     39  * Information about a deposit confirmation we received from
     40  * a merchant.
     41  */
     42 struct TALER_AUDITORDB_DepositConfirmation
     43 {
     44 
     45   /**
     46    * Hash over the contract for which this deposit is made.
     47    */
     48   struct TALER_PrivateContractHashP h_contract_terms;
     49 
     50   /**
     51    * Hash over the policy extension for the deposit.
     52    */
     53   struct TALER_ExtensionPolicyHashP h_policy;
     54 
     55   /**
     56    * Hash over the wiring information of the merchant.
     57    */
     58   struct TALER_MerchantWireHashP h_wire;
     59 
     60   /**
     61    * Time when this deposit confirmation was generated by the exchange.
     62    */
     63   struct GNUNET_TIME_Timestamp exchange_timestamp;
     64 
     65   /**
     66    * How much time does the @e merchant have to issue a refund
     67    * request?  Zero if refunds are not allowed.  After this time, the
     68    * coin cannot be refunded.  Note that the wire transfer will not be
     69    * performed by the exchange until the refund deadline.  This value
     70    * is taken from the original deposit request.
     71    */
     72   struct GNUNET_TIME_Timestamp refund_deadline;
     73 
     74   /**
     75    * How much time does the @e exchange have to wire the funds?
     76    */
     77   struct GNUNET_TIME_Timestamp wire_deadline;
     78 
     79   /**
     80    * Amount to be deposited, excluding fee.  Calculated from the
     81    * amount with fee and the fee from the deposit request.
     82    */
     83   struct TALER_Amount total_without_fee;
     84 
     85   /**
     86    * Array of the coin public keys involved in the
     87    * batch deposit operation.
     88    */
     89   const struct TALER_CoinSpendPublicKeyP *coin_pubs;
     90 
     91   /**
     92    * Array of coin deposit signatures from the deposit operation.
     93    */
     94   const struct TALER_CoinSpendSignatureP *coin_sigs;
     95 
     96   /**
     97    * The Merchant's public key.  Allows the merchant to later refund
     98    * the transaction or to inquire about the wire transfer identifier.
     99    */
    100   struct TALER_MerchantPublicKeyP merchant;
    101 
    102   /**
    103    * Signature from the exchange of type
    104    * #TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT.
    105    */
    106   struct TALER_ExchangeSignatureP exchange_sig;
    107 
    108   /**
    109    * Public signing key from the exchange matching @e exchange_sig.
    110    */
    111   struct TALER_ExchangePublicKeyP exchange_pub;
    112 
    113   /**
    114    * Exchange master signature over @e exchange_sig.
    115    */
    116   struct TALER_MasterSignatureP master_sig;
    117 
    118   /**
    119    * Row of this entry in the auditor database.
    120    */
    121   uint64_t row_id;
    122 
    123   /**
    124    * Length of the @e coin_pubs and @e coin_sigs arrays.
    125    */
    126   unsigned int num_coins;
    127 
    128   bool suppressed;
    129 
    130 };
    131 
    132 
    133 /**
    134  * Information about a row inconsistency
    135  */
    136 struct TALER_AUDITORDB_Generic_Update
    137 {
    138   uint64_t row_id;
    139   bool suppressed;
    140   bool ancient;
    141 };
    142 
    143 
    144 /**
    145  * Information about a coin inconsistency
    146  */
    147 struct TALER_AUDITORDB_CoinInconsistency
    148 {
    149   uint64_t row_id;
    150   char *operation;
    151   struct TALER_Amount exchange_amount;
    152   struct TALER_Amount auditor_amount;
    153   struct GNUNET_CRYPTO_EddsaPublicKey coin_pub;
    154   bool profitable;
    155 };
    156 
    157 /**
    158  * Information about a row inconsistency
    159  */
    160 struct TALER_AUDITORDB_RowInconsistency
    161 {
    162   uint64_t row_id;
    163   char *row_table;
    164   char *diagnostic;
    165   bool suppressed;
    166 };
    167 
    168 /**
    169  * Information about a bad sig loss
    170  */
    171 struct TALER_AUDITORDB_BadSigLosses
    172 {
    173   uint64_t row_id;
    174   uint64_t problem_row_id;
    175   char *operation;
    176   struct TALER_Amount loss;
    177   struct GNUNET_CRYPTO_EddsaPublicKey operation_specific_pub;
    178   bool suppressed;
    179 };
    180 
    181 /**
    182  * Information about a closure lags
    183  */
    184 struct TALER_AUDITORDB_ClosureLags
    185 {
    186   uint64_t row_id;
    187   uint64_t problem_row_id;
    188   struct TALER_Amount amount;
    189   struct GNUNET_TIME_Absolute deadline;
    190   struct TALER_WireTransferIdentifierRawP wtid;
    191   struct TALER_FullPayto account;
    192   bool suppressed;
    193 };
    194 
    195 /**
    196  * Information about a emergency
    197  */
    198 struct TALER_AUDITORDB_Emergency
    199 {
    200   uint64_t row_id;
    201   struct TALER_DenominationHashP denompub_h;
    202   struct TALER_Amount denom_risk;
    203   struct TALER_Amount denom_loss;
    204   struct GNUNET_TIME_Absolute deposit_start;
    205   struct GNUNET_TIME_Absolute deposit_end;
    206   struct TALER_Amount value;
    207   bool suppressed;
    208 };
    209 
    210 /**
    211  * Information about an emergency by count
    212  */
    213 struct TALER_AUDITORDB_EmergenciesByCount
    214 {
    215   uint64_t row_id;
    216   struct TALER_DenominationHashP denompub_h;
    217   uint64_t num_issued;
    218   uint64_t num_known;
    219   struct TALER_Amount risk;
    220   struct GNUNET_TIME_Absolute start;
    221   struct GNUNET_TIME_Absolute deposit_end;
    222   struct TALER_Amount value;
    223   bool suppressed;
    224 };
    225 
    226 /**
    227  * Information about a fee time inconsistency
    228  */
    229 struct TALER_AUDITORDB_FeeTimeInconsistency
    230 {
    231   uint64_t row_id;
    232   uint64_t problem_row_id;
    233   char *type;
    234   struct GNUNET_TIME_Absolute time;
    235   char *diagnostic;
    236 };
    237 
    238 /**
    239  * Information about a denom key validity withdraw inconsistency
    240  */
    241 struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency
    242 {
    243   uint64_t row_id;
    244   uint64_t problem_row_id;
    245   struct GNUNET_TIME_Absolute execution_date;
    246   struct TALER_ReservePublicKeyP reserve_pub;
    247   struct TALER_DenominationHashP denompub_h;
    248   bool suppressed;
    249 };
    250 
    251 /**
    252  * Information about a purse not closed inconsistencies
    253  */
    254 struct TALER_AUDITORDB_PurseNotClosedInconsistencies
    255 {
    256   uint64_t row_id;
    257   struct GNUNET_CRYPTO_EddsaPublicKey purse_pub;
    258   struct TALER_Amount amount;
    259   struct GNUNET_TIME_Absolute expiration_date;
    260   bool suppressed;
    261 };
    262 
    263 /**
    264  * Information about a reserve balance insufficient inconsistency
    265  */
    266 struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency
    267 {
    268   uint64_t row_id;
    269   struct GNUNET_CRYPTO_EddsaPublicKey reserve_pub;
    270   bool inconsistency_gain;
    271   struct TALER_Amount inconsistency_amount;
    272   bool suppressed;
    273 };
    274 
    275 /**
    276  * Information about a reserve in inconsistency
    277  */
    278 struct TALER_AUDITORDB_ReserveInInconsistency
    279 {
    280   uint64_t serial_id;
    281   uint64_t bank_row_id;
    282   struct TALER_Amount amount_exchange_expected;
    283   struct TALER_Amount amount_wired;
    284   struct TALER_ReservePublicKeyP reserve_pub;
    285   struct GNUNET_TIME_Absolute timestamp;
    286   struct TALER_FullPayto account;
    287   char *diagnostic;
    288   bool suppressed;
    289 
    290 };
    291 
    292 /**
    293  * Balance values for a reserve (or all reserves).
    294  */
    295 struct TALER_AUDITORDB_ReserveFeeBalance
    296 {
    297   /**
    298    * Remaining funds.
    299    */
    300   struct TALER_Amount reserve_balance;
    301 
    302   /**
    303    * Losses from operations that should not have
    304    * happened (e.g. negative balance).
    305    */
    306   struct TALER_Amount reserve_loss;
    307 
    308   /**
    309    * Fees charged for withdraw.
    310    */
    311   struct TALER_Amount withdraw_fee_balance;
    312 
    313   /**
    314    * Fees charged for closing.
    315    */
    316   struct TALER_Amount close_fee_balance;
    317 
    318   /**
    319    * Fees charged for purse creation.
    320    */
    321   struct TALER_Amount purse_fee_balance;
    322 
    323   /**
    324    * Opening fees charged.
    325    */
    326   struct TALER_Amount open_fee_balance;
    327 
    328   /**
    329    * History fees charged.
    330    */
    331   struct TALER_Amount history_fee_balance;
    332 };
    333 
    334 
    335 /**
    336  * Balance data for denominations in circulation.
    337  */
    338 struct TALER_AUDITORDB_DenominationCirculationData
    339 {
    340   /**
    341    * Amount of outstanding coins in circulation.
    342    */
    343   struct TALER_Amount denom_balance;
    344 
    345   /**
    346    * Amount lost due coins illicitly accepted (effectively, a
    347    * negative @a denom_balance).
    348    */
    349   struct TALER_Amount denom_loss;
    350 
    351   /**
    352    * Total amount that could still be theoretically lost in the future due to
    353    * recoup operations.  (Total put into circulation minus @e recoup_loss).
    354    */
    355   struct TALER_Amount denom_risk;
    356 
    357   /**
    358    * Amount lost due to recoups.
    359    */
    360   struct TALER_Amount recoup_loss;
    361 
    362   /**
    363    * Number of coins of this denomination that the exchange signed into
    364    * existence.
    365    */
    366   uint64_t num_issued;
    367 };
    368 
    369 struct TALER_AUDITORDB_DenominationsWithoutSigs
    370 {
    371   uint64_t row_id;
    372   struct TALER_DenominationHashP denompub_h;
    373   struct TALER_Amount value;
    374   struct GNUNET_TIME_Absolute start_time;
    375   struct GNUNET_TIME_Absolute end_time;
    376   bool suppressed;
    377 };
    378 
    379 struct TALER_AUDITORDB_MisattributionInInconsistency
    380 {
    381   uint64_t row_id;
    382   struct TALER_Amount amount;
    383   uint64_t bank_row;
    384   struct TALER_ReservePublicKeyP reserve_pub;
    385   bool suppressed;
    386 
    387 };
    388 
    389 struct TALER_AUDITORDB_DenominationPending
    390 {
    391   uint64_t row_id;
    392   struct TALER_DenominationHashP denom_pub_hash;
    393   struct TALER_Amount denom_balance;
    394   struct TALER_Amount denom_loss;
    395   uint64_t num_issued;
    396   struct TALER_Amount denom_risk;
    397   struct TALER_Amount recoup_loss;
    398   bool suppressed;
    399 
    400 };
    401 
    402 struct TALER_AUDITORDB_HistoricReserveSummary
    403 {
    404   uint64_t row_id;
    405   struct GNUNET_TIME_Absolute start_date;
    406   struct GNUNET_TIME_Absolute end_date;
    407   struct TALER_Amount reserve_profits;
    408   bool suppressed;
    409 
    410 };
    411 
    412 struct TALER_AUDITORDB_WireFormatInconsistency
    413 {
    414   uint64_t row_id;
    415   struct TALER_Amount amount;
    416   uint64_t wire_offset;
    417   char *diagnostic;
    418   bool suppressed;
    419 
    420 };
    421 
    422 struct TALER_AUDITORDB_WireOutInconsistency
    423 {
    424   uint64_t row_id;
    425   struct TALER_FullPayto destination_account;
    426   char *diagnostic;
    427   uint64_t wire_out_row_id;
    428   struct TALER_Amount expected;
    429   struct TALER_Amount claimed;
    430   bool suppressed;
    431 
    432 };
    433 
    434 struct TALER_AUDITORDB_RowMinorInconsistencies
    435 {
    436   uint64_t row_id;
    437   char *row_table;
    438   uint64_t problem_row;
    439   char *diagnostic;
    440   bool suppressed;
    441 };
    442 
    443 
    444 struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency
    445 {
    446   uint64_t row_id;
    447   struct TALER_ReservePublicKeyP reserve_pub;
    448   struct TALER_Amount exchange_amount;
    449   struct TALER_Amount auditor_amount;
    450   bool suppressed;
    451 
    452 };
    453 
    454 struct TALER_AUDITORDB_ReserveNotClosedInconsistency
    455 {
    456   uint64_t row_id;
    457   struct TALER_ReservePublicKeyP reserve_pub;
    458   struct TALER_Amount balance;
    459   struct GNUNET_TIME_Absolute expiration_time;
    460   char *diagnostic;
    461   bool suppressed;
    462 
    463 };
    464 
    465 
    466 enum TALER_AUDITORDB_DeletableSuppressableTables
    467 {
    468   /**
    469    * For auditor_amount_arithmetic_inconsistency table.
    470    */
    471   TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY,
    472 
    473   /**
    474    * For auditor_closure_lags table.
    475    */
    476   TALER_AUDITORDB_CLOSURE_LAGS,
    477 
    478   /**
    479    * For auditor_progress table.
    480    */
    481   TALER_AUDITORDB_PROGRESS,
    482 
    483   /**
    484    * For auditor_bad_sig_losses table.
    485    */
    486   TALER_AUDITORDB_BAD_SIG_LOSSES,
    487 
    488   /**
    489    * For auditor_coin_inconsistency table.
    490    */
    491   TALER_AUDITORDB_COIN_INCONSISTENCY,
    492 
    493   /**
    494    * For auditor_denomination_key_validity_withdraw_inconsistency table.
    495    */
    496   TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY,
    497 
    498   /**
    499    * For auditor_denomination_pending table.
    500    */
    501   TALER_AUDITORDB_DENOMINATION_PENDING,
    502 
    503   /**
    504    * For auditor_denominations_without_sig table.
    505    */
    506   TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIG,
    507 
    508   /**
    509    * For auditor_deposit_confirmation table.
    510    */
    511   TALER_AUDITORDB_DEPOSIT_CONFIRMATION,
    512 
    513   /**
    514    * For auditor_emergency table.
    515    */
    516   TALER_AUDITORDB_EMERGENCY,
    517 
    518   /**
    519    * For auditor_emergency_by_count table.
    520    */
    521   TALER_AUDITORDB_EMERGENCY_BY_COUNT,
    522 
    523   /**
    524    * For auditor_fee_time_inconsistency table.
    525    */
    526   TALER_AUDITORDB_FEE_TIME_INCONSISTENCY,
    527 
    528   /**
    529    * For auditor_misattribution_in_inconsistency table.
    530    */
    531   TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY,
    532 
    533   /**
    534    * For auditor_purse_not_closed_inconsistency table.
    535    */
    536   TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCY,
    537 
    538   /**
    539    * For auditor_refreshes_hanging table.
    540    */
    541   TALER_AUDITORDB_REFRESHES_HANGING,
    542 
    543   /**
    544    * For auditor_reserve_balance_insufficient_inconsistency table.
    545    */
    546   TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY,
    547 
    548   /**
    549    * For auditor_reserve_balance_summary_wrong_inconsistency table.
    550    */
    551   TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY,
    552 
    553   /**
    554    * For auditor_reserve_in_inconsistency table.
    555    */
    556   TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY,
    557 
    558   /**
    559    * For auditor_reserve_not_closed_inconsistency table.
    560    */
    561   TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY,
    562 
    563   /**
    564    * For auditor_row_inconsistency table.
    565    */
    566   TALER_AUDITORDB_ROW_INCONSISTENCY,
    567 
    568   /**
    569    * For auditor_row_minor_inconsistency table.
    570    */
    571   TALER_AUDITORDB_ROW_MINOR_INCONSISTENCY,
    572 
    573   /**
    574    * For auditor_wire_format_inconsistency table.
    575    */
    576   TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY,
    577 
    578   /**
    579    * For auditor_wire_out_inconsistency table.
    580    */
    581   TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY,
    582 
    583   /**
    584    * Terminal.
    585    */
    586   TALER_AUDITORDB_DELETABLESUPPRESSABLE_TABLES_MAX
    587 };
    588 
    589 
    590 /**
    591  * Information about an arithmetic inconsistency
    592  */
    593 struct TALER_AUDITORDB_AmountArithmeticInconsistency
    594 {
    595   uint64_t row_id;
    596   uint64_t problem_row_id;
    597   char *operation;
    598   struct TALER_Amount exchange_amount;
    599   struct TALER_Amount auditor_amount;
    600   bool profitable;
    601   bool suppressed;
    602 };
    603 
    604 
    605 /**
    606  * Initialize database connection.
    607  *
    608  * @param cfg configuration to use
    609  * @param skip_preflight true if we should skip the usual
    610  *   preflight check which assures us that the DB is actually
    611  *   operational; only taler-auditor-dbinit should use true here.
    612  * @return NULL on failure
    613  */
    614 struct TALER_AUDITORDB_PostgresContext *
    615 TALER_AUDITORDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
    616                          bool skip_preflight);
    617 
    618 
    619 /**
    620  * Shutdown the database connection.
    621  *
    622  * @param[in] pg connection to disconnect
    623  */
    624 void
    625 TALER_AUDITORDB_disconnect (struct TALER_AUDITORDB_PostgresContext *pg);
    626 
    627 
    628 #endif