merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler_merchantdb_plugin.h (153554B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014-2025 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Lesser 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.GPL.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file taler_merchantdb_plugin.h
     18  * @brief database access for the merchant
     19  * @author Florian Dold
     20  * @author Christian Grothoff
     21  * @author Priscilla Huang
     22  */
     23 #ifndef TALER_MERCHANTDB_PLUGIN_H
     24 #define TALER_MERCHANTDB_PLUGIN_H
     25 
     26 #include <gnunet/gnunet_common.h>
     27 #include <gnunet/gnunet_time_lib.h>
     28 #include <gnunet/gnunet_util_lib.h>
     29 #include <gnunet/gnunet_db_lib.h>
     30 #include <taler/taler_exchange_service.h>
     31 #include <taler_merchant_util.h>
     32 #include <jansson.h>
     33 
     34 #ifdef HAVE_DONAU_DONAU_SERVICE_H
     35 #include <donau/donau_service.h>
     36 #include "taler_merchant_donau.h"
     37 #endif
     38 
     39 /**
     40  * Handle to interact with the database.
     41  */
     42 struct TALER_MERCHANTDB_Plugin;
     43 
     44 
     45 GNUNET_NETWORK_STRUCT_BEGIN
     46 
     47 
     48 /**
     49  * Format of the data hashed to generate the notification
     50  * string whenever the KYC status for an account has
     51  * changed.
     52  */
     53 struct TALER_MERCHANTDB_MerchantKycStatusChangeEventP
     54 {
     55   /**
     56    * Type is TALER_DBEVENT_MERCHANT_EXCHANGE_KYC_STATUS_CHANGED.
     57    */
     58   struct GNUNET_DB_EventHeaderP header;
     59 
     60   /**
     61    * Salted hash of the affected account.
     62    */
     63   struct TALER_MerchantWireHashP h_wire;
     64 };
     65 
     66 GNUNET_NETWORK_STRUCT_END
     67 
     68 /**
     69  * Current exposed deposit limits by an exchange
     70  * for a merchant (until other rules may apply).
     71  */
     72 struct TALER_MERCHANTDB_DepositLimits
     73 {
     74   /**
     75    * Maximum amount to be deposited within @a timeframe.
     76    */
     77   struct TALER_Amount threshold;
     78 
     79   /**
     80    * Timeframe over which the limit applies.
     81    */
     82   struct GNUNET_TIME_Relative timeframe;
     83 
     84   /**
     85    * True if this is a soft limit that could be
     86    * raised (by AML staff or by passing KYC checks).
     87    */
     88   bool soft_limit;
     89 };
     90 
     91 /**
     92  * Details about a wire account of the merchant.
     93  */
     94 struct TALER_MERCHANTDB_AccountDetails
     95 {
     96   /**
     97    * Hash of the wire details (@e payto_uri and @e salt).
     98    */
     99   struct TALER_MerchantWireHashP h_wire;
    100 
    101   /**
    102    * Salt value used for hashing @e payto_uri.
    103    */
    104   struct TALER_WireSaltP salt;
    105 
    106   /**
    107    * Instance ID. Do not free (may be aliased with
    108    * the instance ID given in the query!).
    109    * FIXME: set in all functions involving this struct!
    110    */
    111   const char *instance_id;
    112 
    113   /**
    114    * Actual account address as a payto://-URI.
    115    */
    116   struct TALER_FullPayto payto_uri;
    117 
    118   /**
    119    * Where can the taler-merchant-wirewatch helper
    120    * download information about incoming transfers?
    121    * NULL if not available.
    122    */
    123   char *credit_facade_url;
    124 
    125   /**
    126    * JSON with credentials to use to access the
    127    * @e credit_facade_url.
    128    */
    129   json_t *credit_facade_credentials;
    130 
    131   /**
    132    * Is the account set for active use in new contracts?
    133    */
    134   bool active;
    135 
    136 };
    137 
    138 
    139 /**
    140  * Binary login token. Just a vanilla token made out
    141  * of random bits.
    142  */
    143 struct TALER_MERCHANTDB_LoginTokenP
    144 {
    145   /**
    146    * 32 bytes of entropy.
    147    */
    148   uint64_t data[32 / 8];
    149 };
    150 
    151 /**
    152  * Authentication settings for an instance.
    153  */
    154 struct TALER_MERCHANTDB_InstanceAuthSettings
    155 {
    156   /**
    157    * Hash used for authentication.  All zero if authentication is off.
    158    */
    159   struct TALER_MerchantAuthenticationHashP auth_hash;
    160 
    161   /**
    162    * Salt used to hash the "Authentication" header, the result must then
    163    * match the @e auth_hash.
    164    */
    165   struct TALER_MerchantAuthenticationSaltP auth_salt;
    166 };
    167 
    168 /**
    169  * General settings for an instance.
    170  */
    171 struct TALER_MERCHANTDB_InstanceSettings
    172 {
    173   /**
    174    * prefix for the instance under "/instances/"
    175    */
    176   char *id;
    177 
    178   /**
    179    * legal name of the instance
    180    */
    181   char *name;
    182 
    183   /**
    184    * merchant's site url
    185    */
    186   char *website;
    187 
    188   /**
    189    * email contact for password reset / possibly admin / customers
    190    */
    191   char *email;
    192 
    193   /**
    194    * phone contact for password reset / possibly admin / customers
    195    */
    196   char *phone;
    197 
    198   /**
    199    * merchant's logo data uri
    200    */
    201   char *logo;
    202 
    203   /**
    204    * Address of the business
    205    */
    206   json_t *address;
    207 
    208   /**
    209    * jurisdiction of the business
    210    */
    211   json_t *jurisdiction;
    212 
    213   /**
    214    * Use STEFAN curves to determine acceptable
    215    * fees by default (otherwise: accept no fees by default).
    216    */
    217   bool use_stefan;
    218 
    219   /**
    220    * True of @e phone was validated.
    221    */
    222   bool phone_validated;
    223 
    224   /**
    225    * True of @e email was validated.
    226    */
    227   bool email_validated;
    228 
    229   /**
    230    * If the frontend does NOT specify an execution date, how long should
    231    * we tell the exchange to wait to aggregate transactions before
    232    * executing the wire transfer?  This delay is added to the current
    233    * time when we generate the advisory execution time for the exchange.
    234    */
    235   struct GNUNET_TIME_Relative default_wire_transfer_delay;
    236 
    237   /**
    238    * If the frontend does NOT specify a payment deadline, how long should
    239    * offers we make be valid by default?
    240    */
    241   struct GNUNET_TIME_Relative default_pay_delay;
    242 
    243   /**
    244    * If the frontend does NOT specify a refund deadline, how long should
    245    * refunds be possible?
    246    */
    247   struct GNUNET_TIME_Relative default_refund_delay;
    248 
    249   /**
    250    * How much should we round up the wire transfer deadline computed by
    251    * adding the @e default_wire_transfer_delay to the refund deadline.
    252    */
    253   enum GNUNET_TIME_RounderInterval default_wire_transfer_rounding_interval;
    254 
    255 };
    256 
    257 
    258 /**
    259  * Typically called by `lookup_instances`.
    260  *
    261  * @param cls closure
    262  * @param merchant_pub public key of the instance
    263  * @param merchant_priv private key of the instance, NULL if not available
    264  * @param is general instance settings
    265  * @param ias instance authentication settings
    266  */
    267 typedef void
    268 (*TALER_MERCHANTDB_InstanceCallback)(
    269   void *cls,
    270   const struct TALER_MerchantPublicKeyP *merchant_pub,
    271   const struct TALER_MerchantPrivateKeyP *merchant_priv,
    272   const struct TALER_MERCHANTDB_InstanceSettings *is,
    273   const struct TALER_MERCHANTDB_InstanceAuthSettings *ias);
    274 
    275 
    276 /**
    277  * Callback invoked with information about a bank account.
    278  *
    279  * @param cls closure
    280  * @param merchant_priv private key of the merchant instance
    281  * @param ad details about the account
    282  */
    283 typedef void
    284 (*TALER_MERCHANTDB_AccountCallback)(
    285   void *cls,
    286   const struct TALER_MerchantPrivateKeyP *merchant_priv,
    287   const struct TALER_MERCHANTDB_AccountDetails *ad);
    288 
    289 
    290 /**
    291  * Determines the maximum @a amount for a particular
    292  * type of operation for a given @a exchange_url.
    293  *
    294  * @param cls closure
    295  * @param exchange_url base URL of the exchange to get
    296  *   the limit for
    297  * @param[in,out] amount lowered to the maximum amount
    298  *   allowed at the exchange
    299  */
    300 typedef void
    301 (*TALER_MERCHANTDB_OperationLimitCallback)(
    302   void *cls,
    303   const char *exchange_url,
    304   struct TALER_Amount *amount);
    305 
    306 
    307 /**
    308  * Typically called by `lookup_products`.
    309  *
    310  * @param cls a `json_t *` JSON array to build
    311  * @param product_serial row ID of the product
    312  * @param product_id ID of the product
    313  */
    314 typedef void
    315 (*TALER_MERCHANTDB_ProductsCallback)(
    316   void *cls,
    317   uint64_t product_serial,
    318   const char *product_id);
    319 
    320 
    321 /**
    322  * Details about a product.
    323  */
    324 struct TALER_MERCHANTDB_ProductDetails
    325 {
    326   /**
    327    * Name of the product.
    328    */
    329   char *product_name;
    330 
    331   /**
    332    * Description of the product.
    333    */
    334   char *description;
    335 
    336   /**
    337    * Internationalized description.
    338    */
    339   json_t *description_i18n;
    340 
    341   /**
    342    * Unit in which the product is sold.
    343    */
    344   char *unit;
    345 
    346   /**
    347    * Price per unit of the product.  Zero to imply that the
    348    * product is not sold separately or that the price is not fixed.
    349    */
    350   struct TALER_Amount price;
    351 
    352   /**
    353    * Optional list of per-unit prices. When NULL or empty, @e price
    354    * must be used as the canonical single price.
    355    */
    356   struct TALER_Amount *price_array;
    357 
    358   /**
    359    * Number of entries in @e price_array.
    360    */
    361   size_t price_array_length;
    362 
    363   /**
    364    * Base64-encoded product image, or an empty string.
    365    */
    366   char *image;
    367 
    368   /**
    369    * List of taxes the merchant pays for this product. Never NULL,
    370    * but can be an empty array.
    371    */
    372   json_t *taxes;
    373 
    374   /**
    375    * Number of units of the product in stock in sum in total, including all
    376    * existing sales and lost product, in product-specific units. UINT64_MAX
    377    * indicates "infinite".
    378    */
    379   uint64_t total_stock;
    380 
    381   /**
    382    * Fractional part of stock in units of 1/1000000 of the base value.
    383    */
    384   uint32_t total_stock_frac;
    385 
    386   /**
    387    * Honor fractional stock if TRUE, else only integer stock.
    388    */
    389   bool allow_fractional_quantity;
    390 
    391   /**
    392    * Precision level (number of decimal places) to apply when
    393    * fractional quantities are enabled.
    394    */
    395   uint32_t fractional_precision_level;
    396 
    397   /**
    398    * Number of units of the product in sold, in product-specific units.
    399    */
    400   uint64_t total_sold;
    401 
    402   /**
    403    * Fractional part of units sold in units of 1/1000000 of the base value.
    404    */
    405   uint32_t total_sold_frac;
    406 
    407   /**
    408    * Number of units of stock lost.
    409    */
    410   uint64_t total_lost;
    411 
    412   /**
    413    * Fractional part of lost units in units of 1/1000000 of the base value.
    414    */
    415   uint32_t total_lost_frac;
    416 
    417   /**
    418    * Identifies where the product is in stock, possibly an empty map.
    419    */
    420   json_t *address;
    421 
    422   /**
    423    * Identifies when the product will be restocked. 0 for unknown,
    424    * #GNUNET_TIME_UNIT_FOREVER_ABS for never.
    425    */
    426   struct GNUNET_TIME_Timestamp next_restock;
    427 
    428   /**
    429    * Minimum required age for consumers buying this product.
    430    * Default is 0. Only enforced of an exchange supports age
    431    * restrictions.
    432    */
    433   uint32_t minimum_age;
    434 };
    435 
    436 
    437 /**
    438  * Details about an inventory measurement unit.
    439  */
    440 struct TALER_MERCHANTDB_UnitDetails
    441 {
    442 
    443   /**
    444    * Database serial.
    445    */
    446   uint64_t unit_serial;
    447 
    448   /**
    449    * Backend identifier used in product payloads.
    450    */
    451   char *unit;
    452 
    453   /**
    454    * Default long label (fallback string).
    455    */
    456   char *unit_name_long;
    457 
    458   /**
    459    * Default short label (fallback string).
    460    */
    461   char *unit_name_short;
    462 
    463   /**
    464    * Internationalised long labels.
    465    */
    466   json_t *unit_name_long_i18n;
    467 
    468   /**
    469    * Internationalised short labels.
    470    */
    471   json_t *unit_name_short_i18n;
    472 
    473   /**
    474    * Whether fractional quantities are enabled by default.
    475    */
    476   bool unit_allow_fraction;
    477 
    478   /**
    479    * Maximum number of fractional digits honoured by default.
    480    */
    481   uint32_t unit_precision_level;
    482 
    483   /**
    484    * Hidden from selectors when false.
    485    */
    486   bool unit_active;
    487 
    488   /**
    489    * Built-in units cannot be deleted.
    490    */
    491   bool unit_builtin;
    492 };
    493 
    494 
    495 /**
    496  * Typically called by `lookup_all_products`.
    497  *
    498  * @param cls a `json_t *` JSON array to build
    499  * @param product_serial row ID of the product
    500  * @param product_id ID of the product
    501  * @param pd full product details
    502  * @param num_categories length of @a categories array
    503  * @param categories array of categories the
    504  *   product is in
    505  */
    506 typedef void
    507 (*TALER_MERCHANTDB_ProductCallback)(
    508   void *cls,
    509   uint64_t product_serial,
    510   const char *product_id,
    511   const struct TALER_MERCHANTDB_ProductDetails *pd,
    512   size_t num_categories,
    513   const uint64_t *categories);
    514 
    515 
    516 /**
    517  * Typically called by `lookup_login_tokens`.
    518  *
    519  * @param cls a `json_t *` JSON array to build
    520  * @param creation_time creation time of the token
    521  * @param expiration_time expiration time of the token
    522  * @param scope validity scope of the token
    523  * @param description description of the token
    524  * @param serial serial number of the token
    525  */
    526 typedef void
    527 (*TALER_MERCHANTDB_LoginTokensCallback)(
    528   void *cls,
    529   struct GNUNET_TIME_Timestamp creation_time,
    530   struct GNUNET_TIME_Timestamp expiration_time,
    531   uint32_t scope,
    532   const char *description,
    533   uint64_t serial);
    534 
    535 
    536 /**
    537  * Typically called by `lookup_templates`.
    538  *
    539  * @param cls closure
    540  * @param template_id ID of the template
    541  * @param template_description description of the template
    542  */
    543 typedef void
    544 (*TALER_MERCHANTDB_TemplatesCallback)(
    545   void *cls,
    546   const char *template_id,
    547   const char *template_description);
    548 
    549 
    550 /**
    551  * Typically called by `lookup_otp_devices`.
    552  *
    553  * @param cls closure
    554  * @param otp_id ID of the OTP device
    555  * @param otp_description description of the OTP device
    556  */
    557 typedef void
    558 (*TALER_MERCHANTDB_OtpDeviceCallback)(
    559   void *cls,
    560   const char *otp_id,
    561   const char *otp_description);
    562 
    563 
    564 /**
    565  * Details about a template.
    566  */
    567 struct TALER_MERCHANTDB_TemplateDetails
    568 {
    569   /**
    570    * Description of the template.
    571    */
    572   char *template_description;
    573 
    574   /**
    575    * In this template contract, we can have additional information.
    576    */
    577   json_t *template_contract;
    578 
    579   /**
    580    * ID of the OTP device linked to the template, or NULL.
    581    */
    582   char *otp_id;
    583 
    584   /**
    585    * Editable default values for fields not specified
    586    * in the @e template_contract. NULL if the user
    587    * cannot edit anything.
    588    */
    589   json_t *editable_defaults;
    590 
    591 };
    592 
    593 
    594 /**
    595  * Details about an OTP device.
    596  */
    597 struct TALER_MERCHANTDB_OtpDeviceDetails
    598 {
    599 
    600   /**
    601    * Description of the device.
    602    */
    603   char *otp_description;
    604 
    605   /**
    606    * Current usage counter value.
    607    */
    608   uint64_t otp_ctr;
    609 
    610   /**
    611    * Base64-encoded key.
    612    */
    613   char *otp_key;
    614 
    615   /**
    616    * Algorithm used to compute purchase confirmations.
    617    */
    618   enum TALER_MerchantConfirmationAlgorithm otp_algorithm;
    619 };
    620 
    621 
    622 /**
    623  * Typically called by `lookup_categories`.
    624  *
    625  * @param cls closure
    626  * @param category_id ID of the category
    627  * @param category_name name of the category
    628  * @param category_name_i18n translations of the @a category_name
    629  * @param product_count number of products in the category
    630  */
    631 typedef void
    632 (*TALER_MERCHANTDB_CategoriesCallback)(
    633   void *cls,
    634   uint64_t category_id,
    635   const char *category_name,
    636   const json_t *category_name_i18n,
    637   uint64_t product_count);
    638 
    639 
    640 /**
    641  * Typically called by `lookup_units`.
    642  *
    643  * @param cls closure
    644  * @param unit_serial database identifier
    645  * @param ud measurement unit details (borrowed)
    646  */
    647 typedef void
    648 (*TALER_MERCHANTDB_UnitsCallback)(
    649   void *cls,
    650   uint64_t unit_serial,
    651   const struct TALER_MERCHANTDB_UnitDetails *ud);
    652 
    653 
    654 /**
    655  * Details about a product category.
    656  */
    657 struct TALER_MERCHANTDB_CategoryDetails
    658 {
    659 
    660   /**
    661    * Name of the category.
    662    */
    663   char *category_name;
    664 
    665   /**
    666    * Translations of the name of the category.
    667    */
    668   json_t *category_name_i18n;
    669 
    670 };
    671 
    672 
    673 /**
    674  * Typically called by `lookup_webhooks`.
    675  *
    676  * @param cls a `json_t *` JSON array to build
    677  * @param webhook_id ID of the webhook
    678  * @param event_type event of the webhook
    679  */
    680 typedef void
    681 (*TALER_MERCHANTDB_WebhooksCallback)(
    682   void *cls,
    683   const char *webhook_id,
    684   const char *event_type);
    685 
    686 
    687 /**
    688  * Details about a webhook.
    689  */
    690 struct TALER_MERCHANTDB_WebhookDetails
    691 {
    692 
    693   /**
    694    * event of the webhook.
    695    */
    696   char *event_type;
    697 
    698   /**
    699    * URL of the webhook. The customer will be redirected on this url.
    700    */
    701   char *url;
    702 
    703   /**
    704    * Http method used by the webhook.
    705    */
    706   char *http_method;
    707 
    708   /**
    709    * Header template of the webhook.
    710    */
    711   char *header_template;
    712 
    713   /**
    714    * Body template of the webhook.
    715    */
    716   char *body_template;
    717 
    718 };
    719 
    720 
    721 /**
    722  * Typically called by `lookup_webhook_by_event`.
    723  *
    724  * @param cls a `json_t *` JSON array to build
    725  * @param webhook_serial reference to the configured webhook template.
    726  * @param event_type which type of event triggers this type of webhook
    727  * @param url the HTTP URL to make the webhook request to
    728  * @param http_method HTTP method use for the webhook
    729  * @param header_template template for the header of the webhook
    730  * @param body_template template for the body of the webhook
    731  */
    732 typedef void
    733 (*TALER_MERCHANTDB_WebhookDetailCallback)(
    734   void *cls,
    735   uint64_t webhook_serial,
    736   const char *event_type,
    737   const char *url,
    738   const char *http_method,
    739   const char *header_template,
    740   const char *body_template);
    741 
    742 
    743 /**
    744  * Typically called by `lookup_pending_webhooks`.
    745  *
    746  * @param cls a `json_t *` JSON array to build
    747  * @param webhook_pending_serial reference to the configured webhook template.
    748  * @param next_attempt is the time we should make the next request to the webhook.
    749  * @param retries how often have we tried this request to the webhook.
    750  * @param url to make request to
    751  * @param http_method use for the webhook
    752  * @param header of the webhook
    753  * @param body of the webhook
    754  */
    755 typedef void
    756 (*TALER_MERCHANTDB_PendingWebhooksCallback)(
    757   void *cls,
    758   uint64_t webhook_pending_serial,
    759   struct GNUNET_TIME_Absolute
    760   next_attempt,
    761   uint32_t retries,
    762   const char *url,
    763   const char *http_method,
    764   const char *header,
    765   const char *body);
    766 
    767 
    768 /**
    769  * Details about the pending webhook.
    770  */
    771 struct TALER_MERCHANTDB_PendingWebhookDetails
    772 {
    773 
    774   /**
    775    * Identifies when we should make the next request to the webhook. 0 for unknown,
    776    * #GNUNET_TIME_UNIT_FOREVER_ABS for never.
    777    */
    778   struct GNUNET_TIME_Absolute next_attempt;
    779 
    780   /**
    781    * How often have we tried this request so far.
    782    */
    783   uint32_t retries;
    784 
    785   /**
    786    * URL of the webhook. The customer will be redirected on this url.
    787    */
    788   char *url;
    789 
    790   /**
    791    * Http method used for the webhook.
    792    */
    793   char *http_method;
    794 
    795   /**
    796    * Header of the webhook.
    797    */
    798   char *header;
    799 
    800   /**
    801    * Body of the webhook.
    802    */
    803   char *body;
    804 
    805 };
    806 
    807 
    808 /**
    809  * Filter preferences.
    810  */
    811 struct TALER_MERCHANTDB_OrderFilter
    812 {
    813   /**
    814    * Filter orders by this fulfillment URL.
    815    */
    816   const char *fulfillment_url;
    817 
    818   /**
    819    * Filter orders by this session ID.
    820    */
    821   const char *session_id;
    822 
    823   /**
    824    * Filter by payment status.
    825    */
    826   enum TALER_EXCHANGE_YesNoAll paid;
    827 
    828   /**
    829    * Filter by refund status.
    830    */
    831   enum TALER_EXCHANGE_YesNoAll refunded;
    832 
    833   /**
    834    * Filter by wire transfer status.
    835    */
    836   enum TALER_EXCHANGE_YesNoAll wired;
    837 
    838   /**
    839    * Filter orders by date, exact meaning depends on @e delta.
    840    */
    841   struct GNUNET_TIME_Timestamp date;
    842 
    843   /**
    844    * Filter orders by order serial number, exact meaning depends on @e delta.
    845    */
    846   uint64_t start_row;
    847 
    848   /**
    849    * takes value of the form N (-N), so that at most N values strictly older
    850    * (younger) than start and date are returned.
    851    */
    852   int64_t delta;
    853 
    854   /**
    855    * Timeout for long-polling.
    856    */
    857   struct GNUNET_TIME_Relative timeout;
    858 
    859   /**
    860    * Filter to apply on the summary of the order.
    861    */
    862   const char *summary_filter;
    863 
    864 };
    865 
    866 
    867 /**
    868  * Typically called by `lookup_orders`.
    869  *
    870  * @param cls a `json_t *` JSON array to build
    871  * @param order_id ID of the order
    872  * @param order_serial row of the order in the database
    873  * @param timestamp creation time of the order in the database
    874  */
    875 typedef void
    876 (*TALER_MERCHANTDB_OrdersCallback)(void *cls,
    877                                    const char *order_id,
    878                                    uint64_t order_serial,
    879                                    struct GNUNET_TIME_Timestamp timestamp);
    880 
    881 
    882 /**
    883  * Typically called by `select_order_blinded_sigs`
    884  *
    885  * @param cls closure
    886  * @param hash hash of the token
    887  * @param blinded_sig blinded signature for the token
    888  */
    889 typedef void
    890 (*TALER_MERCHANTDB_BlindedSigCallback)(
    891   void *cls,
    892   struct GNUNET_HashCode *hash,
    893   struct GNUNET_CRYPTO_BlindedSignature *blinded_sig);
    894 
    895 /**
    896  * Function called with information about a coin that was deposited.
    897  *
    898  * @param cls closure
    899  * @param exchange_url exchange where @a coin_pub was deposited
    900  * @param coin_pub public key of the coin
    901  * @param amount_with_fee amount the exchange will deposit for this coin
    902  * @param deposit_fee fee the exchange will charge for this coin
    903  * @param refund_fee fee the exchange will charge for refunding this coin
    904  */
    905 typedef void
    906 (*TALER_MERCHANTDB_DepositsCallback)(
    907   void *cls,
    908   const char *exchange_url,
    909   const struct TALER_CoinSpendPublicKeyP *coin_pub,
    910   const struct TALER_Amount *amount_with_fee,
    911   const struct TALER_Amount *deposit_fee,
    912   const struct TALER_Amount *refund_fee);
    913 
    914 
    915 /**
    916  * Function called with information about a refund.
    917  *
    918  * @param cls closure
    919  * @param coin_pub public coin from which the refund comes from
    920  * @param refund_amount refund amount which is being taken from @a coin_pub
    921  */
    922 typedef void
    923 (*TALER_MERCHANTDB_RefundCallback)(
    924   void *cls,
    925   const struct TALER_CoinSpendPublicKeyP *coin_pub,
    926   const struct TALER_Amount *refund_amount);
    927 
    928 
    929 /**
    930  * Typically called by `lookup_transfer_details_by_order`.
    931  *
    932  * @param cls closure
    933  * @param wtid wire transfer subject of the wire transfer for the coin
    934  * @param exchange_url base URL of the exchange that made the payment
    935  * @param execution_time when was the payment made
    936  * @param deposit_value contribution of the coin to the total wire transfer value
    937  * @param deposit_fee deposit fee charged by the exchange for the coin
    938  * @param transfer_confirmed did the merchant confirm that a wire transfer with
    939  *        @a wtid over the total amount happened?
    940  */
    941 typedef void
    942 (*TALER_MERCHANTDB_OrderTransferDetailsCallback)(
    943   void *cls,
    944   const struct TALER_WireTransferIdentifierRawP *wtid,
    945   const char *exchange_url,
    946   struct GNUNET_TIME_Timestamp execution_time,
    947   const struct TALER_Amount *deposit_value,
    948   const struct TALER_Amount *deposit_fee,
    949   bool transfer_confirmed);
    950 
    951 
    952 /**
    953  * Function called with detailed information about a refund.
    954  *
    955  * @param cls closure
    956  * @param refund_serial unique serial number of the refund
    957  * @param timestamp time of the refund (for grouping of refunds in the wallet UI)
    958  * @param coin_pub public coin from which the refund comes from
    959  * @param exchange_url URL of the exchange that issued @a coin_pub
    960  * @param rtransaction_id identificator of the refund
    961  * @param reason human-readable explanation of the refund
    962  * @param refund_amount refund amount which is being taken from @a coin_pub
    963  * @param pending true if the this refund was not yet processed by the wallet/exchange
    964  */
    965 typedef void
    966 (*TALER_MERCHANTDB_RefundDetailCallback)(
    967   void *cls,
    968   uint64_t refund_serial,
    969   struct GNUNET_TIME_Timestamp timestamp,
    970   const struct TALER_CoinSpendPublicKeyP *coin_pub,
    971   const char *exchange_url,
    972   uint64_t rtransaction_id,
    973   const char *reason,
    974   const struct TALER_Amount *refund_amount,
    975   bool pending);
    976 
    977 
    978 /**
    979  * Function called from ``account_kyc_get_status``
    980  * with KYC status information for this merchant.
    981  *
    982  * @param cls closure
    983  * @param h_wire hash of the wire account
    984  * @param payto_uri payto:// URI of the merchant's bank account
    985  * @param exchange_url base URL of the exchange for which this is a status
    986  * @param last_check when did we last get an update on our KYC status from the exchange
    987  * @param kyc_ok true if we satisfied the KYC requirements
    988  * @param access_token access token for the KYC SPA, NULL if we cannot access it yet (need KYC auth wire transfer)
    989  * @param last_http_status last HTTP status from /kyc-check
    990  * @param last_ec last Taler error code from /kyc-check
    991  * @param in_aml_review true if the account is pending review
    992  * @param jlimits JSON array of applicable AccountLimits, or NULL if unknown (like defaults apply)
    993  */
    994 typedef void
    995 (*TALER_MERCHANTDB_KycCallback)(
    996   void *cls,
    997   const struct TALER_MerchantWireHashP *h_wire,
    998   struct TALER_FullPayto payto_uri,
    999   const char *exchange_url,
   1000   struct GNUNET_TIME_Timestamp last_check,
   1001   bool kyc_ok,
   1002   const struct TALER_AccountAccessTokenP *access_token,
   1003   unsigned int last_http_status,
   1004   enum TALER_ErrorCode last_ec,
   1005   bool in_aml_review,
   1006   const json_t *jlimits);
   1007 
   1008 
   1009 /**
   1010  * Results from trying to increase a refund.
   1011  */
   1012 enum TALER_MERCHANTDB_RefundStatus
   1013 {
   1014 
   1015   /**
   1016    * Refund amount exceeds legal exchange limits.
   1017    */
   1018   TALER_MERCHANTDB_RS_LEGAL_FAILURE = -5,
   1019 
   1020   /**
   1021    * Refund amount currency does not match original payment.
   1022    */
   1023   TALER_MERCHANTDB_RS_BAD_CURRENCY = -4,
   1024 
   1025   /**
   1026    * Refund amount exceeds original payment.
   1027    */
   1028   TALER_MERCHANTDB_RS_TOO_HIGH = -3,
   1029 
   1030   /**
   1031    * Hard database failure.
   1032    */
   1033   TALER_MERCHANTDB_RS_HARD_ERROR = -2,
   1034 
   1035   /**
   1036    * Soft database failure.
   1037    */
   1038   TALER_MERCHANTDB_RS_SOFT_ERROR = -1,
   1039 
   1040   /**
   1041    * Order not found.
   1042    */
   1043   TALER_MERCHANTDB_RS_NO_SUCH_ORDER = 0,
   1044 
   1045   /**
   1046    * Refund is now at or above the requested amount.
   1047    */
   1048   TALER_MERCHANTDB_RS_SUCCESS = 1
   1049 
   1050 };
   1051 
   1052 
   1053 /**
   1054  * Function called with information about a wire transfer identifier.
   1055  *
   1056  * @param cls closure
   1057  * @param order_id the order to which the deposits belong
   1058  * @param deposit_value the amount deposited under @a order_id
   1059  * @param deposit_fee the fee charged for @a deposit_value
   1060  */
   1061 typedef void
   1062 (*TALER_MERCHANTDB_TransferSummaryCallback)(
   1063   void *cls,
   1064   const char *order_id,
   1065   const struct TALER_Amount *deposit_value,
   1066   const struct TALER_Amount *deposit_fee);
   1067 
   1068 
   1069 /**
   1070  * Function called with information about wire transfers
   1071  * that taler-merchant-exchange still needs to process.
   1072  *
   1073  * @param cls closure
   1074  * @param rowid row of the transfer in the merchant database
   1075  * @param instance_id instance that received the transfer
   1076  * @param exchange_url URL of the exchange that is making the deposit
   1077  * @param payto_uri account of the merchant that received the transfer
   1078  * @param wtid wire transfer subject identifying the aggregation
   1079  * @param next_attempt when should we next try to interact with the exchange
   1080  */
   1081 typedef void
   1082 (*TALER_MERCHANTDB_OpenTransferCallback)(
   1083   void *cls,
   1084   uint64_t rowid,
   1085   const char *instance_id,
   1086   const char *exchange_url,
   1087   struct TALER_FullPayto payto_uri,
   1088   const struct TALER_WireTransferIdentifierRawP *wtid,
   1089   struct GNUNET_TIME_Absolute next_attempt);
   1090 
   1091 
   1092 /**
   1093  * Callback for results from `lookup_pending_deposits`.
   1094  *
   1095  * @param cls NULL
   1096  * @param deposit_serial identifies the deposit operation
   1097  * @param wire_deadline when is the wire due
   1098  * @param retry_time when to next try the exchange again
   1099  * @param h_contract_terms hash of the contract terms
   1100  * @param merchant_priv private key of the merchant
   1101  * @param instance_id name of the instance
   1102  * @param h_wire hash of the merchant's wire account into
   1103  * @param amount_with_fee amount the exchange will deposit for this coin
   1104  * @param deposit_fee fee the exchange will charge for this coin which the deposit was made
   1105  * @param coin_pub public key of the deposited coin
   1106  */
   1107 typedef void
   1108 (*TALER_MERCHANTDB_PendingDepositsCallback) (
   1109   void *cls,
   1110   uint64_t deposit_serial,
   1111   struct GNUNET_TIME_Absolute wire_deadline,
   1112   struct GNUNET_TIME_Absolute retry_time,
   1113   const struct TALER_PrivateContractHashP *h_contract_terms,
   1114   const struct TALER_MerchantPrivateKeyP *merchant_priv,
   1115   const char *instance_id,
   1116   const struct TALER_MerchantWireHashP *h_wire,
   1117   const struct TALER_Amount *amount_with_fee,
   1118   const struct TALER_Amount *deposit_fee,
   1119   const struct TALER_CoinSpendPublicKeyP *coin_pub);
   1120 
   1121 
   1122 /**
   1123  * Function called with detailed information about a wire transfer and
   1124  * the underlying deposits that are being aggregated.
   1125  *
   1126  * @param cls closure
   1127  * @param current_offset offset in the exchange reply we are at
   1128  * @param ttd details about the transfer at @a current_offset
   1129  */
   1130 typedef void
   1131 (*TALER_MERCHANTDB_TransferDetailsCallback)(
   1132   void *cls,
   1133   unsigned int current_offset,
   1134   const struct TALER_TrackTransferDetails *ttd);
   1135 
   1136 
   1137 /**
   1138  * Function called with information about a accounts
   1139  * the wirewatcher should monitor.
   1140  *
   1141  * @param cls closure
   1142  * @param instance instance that owns the account
   1143  * @param payto_uri account URI
   1144  * @param credit_facade_url URL for the credit facade
   1145  * @param credit_facade_credentials account access credentials
   1146  * @param last_serial last transaction serial (inclusive) we have seen from this account
   1147  */
   1148 typedef void
   1149 (*TALER_MERCHANTDB_WirewatchWorkCallback)(
   1150   void *cls,
   1151   const char *instance,
   1152   struct TALER_FullPayto payto_uri,
   1153   const char *credit_facade_url,
   1154   const json_t *credit_facade_credentials,
   1155   uint64_t last_serial);
   1156 
   1157 
   1158 /**
   1159  * Function called with information about a wire transfer.
   1160  *
   1161  * @param cls closure with a `json_t *` array to build up the response
   1162  * @param expected_credit_amount how we expect to see wired to the merchant (minus fees), NULL if unknown
   1163  * @param wtid wire transfer identifier
   1164  * @param payto_uri target account that received the wire transfer
   1165  * @param exchange_url base URL of the exchange that made the wire transfer
   1166  * @param expected_transfer_serial_id serial number identifying the expected transfer in the backend
   1167  * @param execution_time when did the exchange make the transfer, #GNUNET_TIME_UNIT_FOREVER_ABS
   1168  *           if it did not yet happen
   1169  * @param confirmed true if the merchant confirmed this wire transfer
   1170  *                 false if it is so far only claimed to have been made by the exchange
   1171  */
   1172 typedef void
   1173 (*TALER_MERCHANTDB_TransferCallback)(
   1174   void *cls,
   1175   const struct TALER_Amount *expected_credit_amount,
   1176   const struct TALER_WireTransferIdentifierRawP *wtid,
   1177   struct TALER_FullPayto payto_uri,
   1178   const char *exchange_url,
   1179   uint64_t expected_transfer_serial_id,
   1180   struct GNUNET_TIME_Absolute execution_time,
   1181   bool confirmed);
   1182 
   1183 
   1184 /**
   1185  * Function called with information about expected incoming wire transfers.
   1186  *
   1187  * @param cls closure with a `json_t *` array to build up the response
   1188  * @param expected_credit_amount how we expect to see wired to the merchant (minus fees), NULL if unknown
   1189  * @param wtid wire transfer identifier
   1190  * @param payto_uri target account that received the wire transfer
   1191  * @param exchange_url base URL of the exchange that made the wire transfer
   1192  * @param expected_transfer_serial_id serial number identifying the expected transfer in the backend
   1193  * @param execution_time when did the exchange claim to have made the transfer
   1194  * @param confirmed true if the merchant confirmed this wire transfer
   1195  *                 false if it is so far only claimed to have been made by the exchange
   1196  * @param validated true if the reconciliation succeeded
   1197  * @param last_http_status HTTP status of our last request to the exchange for this transfer
   1198  * @param last_ec last error code we got back (otherwise #TALER_EC_NONE)
   1199  * @param last_error_detail last detail we got back (or NULL for none)
   1200  */
   1201 typedef void
   1202 (*TALER_MERCHANTDB_IncomingCallback)(
   1203   void *cls,
   1204   const struct TALER_Amount *expected_credit_amount,
   1205   const struct TALER_WireTransferIdentifierRawP *wtid,
   1206   struct TALER_FullPayto payto_uri,
   1207   const char *exchange_url,
   1208   uint64_t expected_transfer_serial_id,
   1209   struct GNUNET_TIME_Timestamp execution_time,
   1210   bool confirmed,
   1211   bool validated,
   1212   unsigned int last_http_status,
   1213   enum TALER_ErrorCode last_ec,
   1214   const char *last_error_detail);
   1215 
   1216 
   1217 /**
   1218  * If the given account is feasible, add it to the array
   1219  * of accounts we return.
   1220  *
   1221  * @param cls closure
   1222  * @param payto_uri URI of the account
   1223  * @param conversion_url URL of a conversion service
   1224  * @param debit_restrictions restrictions for debits from account
   1225  * @param credit_restrictions restrictions for credits to account
   1226  * @param master_sig signature affirming the account
   1227  */
   1228 typedef void
   1229 (*TALER_MERCHANTDB_ExchangeAccountCallback) (
   1230   void *cls,
   1231   struct TALER_FullPayto payto_uri,
   1232   const char *conversion_url,
   1233   const json_t *debit_restrictions,
   1234   const json_t *credit_restrictions,
   1235   const struct TALER_MasterSignatureP *master_sig);
   1236 
   1237 
   1238 /**
   1239  * Function called with information about a coin that was deposited.
   1240  *
   1241  * @param cls closure
   1242  * @param deposit_serial which deposit operation is this about
   1243  * @param exchange_url URL of the exchange that issued the coin
   1244  * @param h_wire hash of merchant's wire details
   1245  * @param deposit_timestamp when was the deposit made
   1246  * @param amount_with_fee amount the exchange will deposit for this coin
   1247  * @param deposit_fee fee the exchange will charge for this coin
   1248  * @param coin_pub public key of the coin
   1249  */
   1250 typedef void
   1251 (*TALER_MERCHANTDB_DepositedCoinsCallback)(
   1252   void *cls,
   1253   uint64_t deposit_serial,
   1254   const char *exchange_url,
   1255   const struct TALER_MerchantWireHashP *h_wire,
   1256   struct GNUNET_TIME_Timestamp deposit_timestamp,
   1257   const struct TALER_Amount *amount_with_fee,
   1258   const struct TALER_Amount *deposit_fee,
   1259   const struct TALER_CoinSpendPublicKeyP *coin_pub);
   1260 
   1261 
   1262 /**
   1263  * Function called with information about a coin that was deposited.
   1264  *
   1265  * @param cls closure
   1266  * @param exchange_url URL of the exchange that issued the coin
   1267  * @param amount_with_fee amount the exchange will deposit for this coin
   1268  * @param deposit_fee fee the exchange will charge for this coin
   1269  * @param refund_fee fee the exchange will charge for refunding this coin
   1270  * @param wire_fee wire fee the exchange charges
   1271  * @param h_wire hash of merchant's wire details
   1272  * @param deposit_timestamp when did the exchange receive the deposit
   1273  * @param refund_deadline until when are refunds allowed
   1274  * @param exchange_sig signature by the exchange
   1275  * @param exchange_pub exchange signing key used for @a exchange_sig
   1276  */
   1277 typedef void
   1278 (*TALER_MERCHANTDB_CoinDepositCallback)(
   1279   void *cls,
   1280   const char *exchange_url,
   1281   const struct TALER_Amount *amount_with_fee,
   1282   const struct TALER_Amount *deposit_fee,
   1283   const struct TALER_Amount *refund_fee,
   1284   const struct TALER_Amount *wire_fee,
   1285   const struct TALER_MerchantWireHashP *h_wire,
   1286   struct GNUNET_TIME_Timestamp deposit_timestamp,
   1287   struct GNUNET_TIME_Timestamp refund_deadline,
   1288   const struct TALER_ExchangeSignatureP *exchange_sig,
   1289   const struct TALER_ExchangePublicKeyP *exchange_pub);
   1290 
   1291 
   1292 /**
   1293  * Possible token family kinds.
   1294  */
   1295 enum TALER_MERCHANTDB_TokenFamilyKind
   1296 {
   1297 
   1298   /**
   1299    * Token family representing a discount token
   1300    */
   1301   TALER_MERCHANTDB_TFK_Discount = 0,
   1302 
   1303   /**
   1304    * Token family representing a subscription token
   1305    */
   1306   TALER_MERCHANTDB_TFK_Subscription = 1,
   1307 
   1308 };
   1309 
   1310 
   1311 /**
   1312  * Typically called by `lookup_token_families`.
   1313  *
   1314  * @param cls a `json_t *` JSON array to build
   1315  * @param slug slug of the token family
   1316  * @param name name of the token family
   1317  * @param description description of the token family
   1318  * @param description_i18n Internationalized token family description.
   1319  * @param start_time start time of the token family's validity period
   1320  * @param expiration end time of the token family's validity period
   1321  * @param kind kind of the token family
   1322  */
   1323 typedef void
   1324 (*TALER_MERCHANTDB_TokenFamiliesCallback)(
   1325   void *cls,
   1326   const char *slug,
   1327   const char *name,
   1328   const char *description,
   1329   const json_t *description_i18n,
   1330   struct GNUNET_TIME_Timestamp start_time,
   1331   struct GNUNET_TIME_Timestamp expiration,
   1332   const char *kind);
   1333 
   1334 
   1335 /**
   1336  * Details about a token family.
   1337  */
   1338 struct TALER_MERCHANTDB_TokenFamilyDetails
   1339 {
   1340   /**
   1341    * Token family slug used for identification.
   1342    */
   1343   char *slug;
   1344 
   1345   /**
   1346    * User readable name of the token family.
   1347    */
   1348   char *name;
   1349 
   1350   /**
   1351    * Description of the token family.
   1352    */
   1353   char *description;
   1354 
   1355   /**
   1356    * Internationalized token family description.
   1357    */
   1358   json_t *description_i18n;
   1359 
   1360   /**
   1361    * Meta-data associated with the token family.
   1362    * Includes information like "trusted_domains" or
   1363    * "expected_domains", if set.
   1364    */
   1365   json_t *extra_data;
   1366 
   1367   /**
   1368    * Cipher that should be used for this token family.  Note: We do not expose
   1369    * this over the API and do not let clients set it. NULL for default (when
   1370    * calling database).
   1371    */
   1372   char *cipher_spec;
   1373 
   1374   /**
   1375    * Start time of the token family duration.
   1376    */
   1377   struct GNUNET_TIME_Timestamp valid_after;
   1378 
   1379   /**
   1380    * End time of the token family duration.
   1381    */
   1382   struct GNUNET_TIME_Timestamp valid_before;
   1383 
   1384   /**
   1385    * Validity duration of the token family. Must be larger or
   1386    * equal to @a rounding plus @a start_offset_s.
   1387    */
   1388   struct GNUNET_TIME_Relative duration;
   1389 
   1390   /**
   1391    * Rounding duration of the token family.
   1392    */
   1393   struct GNUNET_TIME_Relative validity_granularity;
   1394 
   1395   /**
   1396    * Offset (in seconds) to subtract from the rounded
   1397    * validity start period.
   1398    */
   1399   struct GNUNET_TIME_Relative start_offset;
   1400 
   1401   /**
   1402    * Token family kind.
   1403    */
   1404   enum TALER_MERCHANTDB_TokenFamilyKind kind;
   1405 
   1406   /**
   1407    * Counter for each issued token of this family.
   1408    */
   1409   uint64_t issued;
   1410 
   1411   /**
   1412    * Counter for each used token of this family.
   1413    */
   1414   uint64_t used;
   1415 };
   1416 
   1417 
   1418 /**
   1419  * Details about a token key.
   1420  */
   1421 struct TALER_MERCHANTDB_TokenFamilyKeyDetails
   1422 {
   1423   /**
   1424    * Tokens signed with this key are valid from this date on.
   1425    * This is the time the key was created.
   1426    */
   1427   struct GNUNET_TIME_Timestamp signature_validity_start; // valid_after;
   1428 
   1429   /**
   1430    * Tokens signed with this key are valid until this date.
   1431    */
   1432   struct GNUNET_TIME_Timestamp signature_validity_end; // valid_before;
   1433 
   1434   /**
   1435    * Private key expires for use at this time. Signatures can
   1436    * only be created until this point.
   1437    */
   1438   struct GNUNET_TIME_Timestamp private_key_deleted_at;
   1439 
   1440   /**
   1441    * Token family public key.
   1442    */
   1443   struct TALER_TokenIssuePublicKey pub;
   1444 
   1445   /**
   1446    * Token family private key.
   1447    */
   1448   struct TALER_TokenIssuePrivateKey priv;
   1449 
   1450   /**
   1451    * Details about the token family this key belongs to.
   1452    */
   1453   struct TALER_MERCHANTDB_TokenFamilyDetails token_family;
   1454 };
   1455 
   1456 
   1457 /**
   1458  * Function called with applicable token keys.
   1459  *
   1460  * @param cls closure
   1461  * @param details details about an applicable key
   1462  */
   1463 typedef void
   1464 (*TALER_MERCHANTDB_TokenKeyCallback) (
   1465   void *cls,
   1466   const struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details);
   1467 
   1468 
   1469 /**
   1470  * Details about a spent token.
   1471  */
   1472 struct TALER_MERCHANTDB_SpentTokenDetails
   1473 {
   1474   /**
   1475    * Public key of the spent token.
   1476    */
   1477   struct TALER_TokenUsePublicKeyP pub;
   1478 
   1479   /**
   1480    * Signature that this token was spent on the specified order.
   1481    */
   1482   struct TALER_TokenUseSignatureP sig;
   1483 
   1484   /**
   1485    * Blind signature for the spent token to prove validity of it.
   1486    */
   1487   struct TALER_BlindedTokenIssueSignature blind_sig;
   1488 };
   1489 
   1490 
   1491 /**
   1492  * Function called with information about a token that was used.
   1493  *
   1494  * @param cls closure
   1495  * @param spent_token_serial which used token is this about
   1496  * @param h_contract_terms hash of the contract terms this token was used on
   1497  * @param h_issue_pub hash of the token issue public key
   1498  * @param use_pub token use public key
   1499  * @param use_sig token use signature
   1500  * @param issue_sig unblinded token issue signature
   1501  */
   1502 typedef void
   1503 (*TALER_MERCHANTDB_UsedTokensCallback)(
   1504   void *cls,
   1505   uint64_t spent_token_serial,
   1506   const struct TALER_PrivateContractHashP *h_contract_terms,
   1507   const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub,
   1508   const struct TALER_TokenUsePublicKeyP *use_pub,
   1509   const struct TALER_TokenUseSignatureP *use_sig,
   1510   const struct TALER_TokenIssueSignature *issue_sig);
   1511 
   1512 
   1513 /**
   1514  * Returns amount-valued statistics by bucket.
   1515  * Called by `lookup_statistics_amount_by_bucket`.
   1516  *
   1517  * @param cls closure
   1518  * @param description description of the statistic
   1519  * @param bucket_start start time of the bucket
   1520  * @param bucket_end end time of the bucket
   1521  * @param bucket_range range of the bucket
   1522  * @param cumulative_amounts_len the length of @a cumulative_amounts
   1523  * @param cumulative_amounts the cumulative amounts array
   1524  */
   1525 typedef void
   1526 (*TALER_MERCHANTDB_AmountByBucketStatisticsCallback)(
   1527   void *cls,
   1528   const char *description,
   1529   struct GNUNET_TIME_Timestamp bucket_start,
   1530   struct GNUNET_TIME_Timestamp bucket_end,
   1531   const char *bucket_range,
   1532   unsigned int cumulative_amounts_len,
   1533   const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]);
   1534 
   1535 
   1536 /**
   1537  * Returns amount-valued statistics over a particular time interval.
   1538  * Called by `lookup_statistics_amount_by_interval`.
   1539  *
   1540  * @param cls closure
   1541  * @param description description of the statistic
   1542  * @param interval_start start time of the bucket
   1543  * @param cumulative_amounts_len the length of @a cumulative_amounts
   1544  * @param cumulative_amounts the cumulative amounts array
   1545  */
   1546 typedef void
   1547 (*TALER_MERCHANTDB_AmountByIntervalStatisticsCallback)(
   1548   void *cls,
   1549   const char *description,
   1550   struct GNUNET_TIME_Timestamp interval_start,
   1551   unsigned int cumulative_amounts_len,
   1552   const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]);
   1553 
   1554 
   1555 /**
   1556  * Function returning integer-valued statistics for a bucket.
   1557  * Called by `lookup_statistics_counter_by_bucket`.
   1558  *
   1559  * @param cls closure
   1560  * @param description description of the statistic
   1561  * @param bucket_start start time of the bucket
   1562  * @param bucket_end end time of the bucket
   1563  * @param bucket_range range of the bucket
   1564  * @param cumulative_counter counter value
   1565  */
   1566 typedef void
   1567 (*TALER_MERCHANTDB_CounterByBucketStatisticsCallback)(
   1568   void *cls,
   1569   const char *description,
   1570   struct GNUNET_TIME_Timestamp bucket_start,
   1571   struct GNUNET_TIME_Timestamp bucket_end,
   1572   const char *bucket_range,
   1573   uint64_t cumulative_counter);
   1574 
   1575 /**
   1576  * Details about a statistic with counter.
   1577  */
   1578 struct TALER_MERCHANTDB_StatisticsCounterByBucketDetails
   1579 {
   1580   /**
   1581    * Start time of the bucket (inclusive).
   1582    */
   1583   struct GNUNET_TIME_Timestamp start_time;
   1584 
   1585   /**
   1586    * End time of the bucket (exclusive).
   1587    */
   1588   struct GNUNET_TIME_Timestamp end_time;
   1589 
   1590   /**
   1591    * Description of the statistic
   1592    */
   1593   char*description;
   1594 
   1595   /**
   1596    * Range of the bucket
   1597    */
   1598   char *range;
   1599 
   1600   /**
   1601    * Sum of all counters falling under the given
   1602    * SLUG within this timeframe
   1603    */
   1604   uint64_t cumulative_number;
   1605 };
   1606 
   1607 /**
   1608  * Details about a statistic with counter.
   1609  */
   1610 struct TALER_MERCHANTDB_StatisticsCounterByIntervalDetails
   1611 {
   1612   /**
   1613    * Start time of the interval.
   1614    * The interval always ends at the response generation time.
   1615    */
   1616   struct GNUNET_TIME_Timestamp start_time;
   1617 
   1618   /**
   1619    * Sum of all counters falling under the given
   1620    * SLUG within this timeframe
   1621    */
   1622   uint64_t cumulative_counter;
   1623 };
   1624 
   1625 
   1626 /**
   1627  * Function returning integer-valued statistics for a time interval.
   1628  * Called by `lookup_statistics_counter_by_interval`.
   1629  *
   1630  * @param cls closure
   1631  * @param description description of the statistic
   1632  * @param interval_start start time of the interval
   1633  * @param cumulative_counter counter value
   1634  */
   1635 typedef void
   1636 (*TALER_MERCHANTDB_CounterByIntervalStatisticsCallback)(
   1637   void *cls,
   1638   const char *description,
   1639   struct GNUNET_TIME_Timestamp interval_start,
   1640   uint64_t cumulative_counter);
   1641 
   1642 
   1643 /**
   1644  * Handle to interact with the database.
   1645  *
   1646  * Functions ending with "_TR" run their OWN transaction scope
   1647  * and MUST NOT be called from within a transaction setup by the
   1648  * caller.  Functions ending with "_NT" require the caller to
   1649  * setup a transaction scope.  Functions without a suffix are
   1650  * simple, single SQL queries that MAY be used either way.
   1651  */
   1652 struct TALER_MERCHANTDB_Plugin
   1653 {
   1654 
   1655   /**
   1656    * Closure for all callbacks.
   1657    */
   1658   void *cls;
   1659 
   1660   /**
   1661    * Name of the library which generated this plugin.  Set by the
   1662    * plugin loader.
   1663    */
   1664   char *library_name;
   1665 
   1666   /**
   1667    * Connect to the database.
   1668    *
   1669    * @param cls closure
   1670    */
   1671   enum GNUNET_GenericReturnValue
   1672     (*connect)(void *cls);
   1673 
   1674   /**
   1675    * Drop merchant tables. Used for testcases and to reset the DB.
   1676    *
   1677    * @param cls closure
   1678    * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
   1679    */
   1680   enum GNUNET_GenericReturnValue
   1681     (*drop_tables)(void *cls);
   1682 
   1683   /**
   1684    * Garbage collect database. Removes unnecessary data.
   1685    *
   1686    * @param cls closure
   1687    * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
   1688    */
   1689   enum GNUNET_GenericReturnValue
   1690     (*gc)(void *cls);
   1691 
   1692   /**
   1693    * Initialize merchant tables
   1694    *
   1695    * @param cls closure
   1696    * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
   1697    */
   1698   enum GNUNET_GenericReturnValue
   1699     (*create_tables)(void *cls);
   1700 
   1701   /**
   1702    * Register callback to be invoked on events of type @a es.
   1703    *
   1704    * @param cls database context to use
   1705    * @param es specification of the event to listen for
   1706    * @param timeout how long to wait for the event
   1707    * @param cb function to call when the event happens, possibly
   1708    *         multiple times (until cancel is invoked)
   1709    * @param cb_cls closure for @a cb
   1710    * @return handle useful to cancel the listener
   1711    */
   1712   struct GNUNET_DB_EventHandler *
   1713   (*event_listen)(void *cls,
   1714                   const struct GNUNET_DB_EventHeaderP *es,
   1715                   struct GNUNET_TIME_Relative timeout,
   1716                   GNUNET_DB_EventCallback cb,
   1717                   void *cb_cls);
   1718 
   1719   /**
   1720    * Stop notifications.
   1721    *
   1722    * @param eh handle to unregister.
   1723    */
   1724   void
   1725   (*event_listen_cancel)(struct GNUNET_DB_EventHandler *eh);
   1726 
   1727 
   1728   /**
   1729    * Notify all that listen on @a es of an event.
   1730    *
   1731    * @param cls database context to use
   1732    * @param es specification of the event to generate
   1733    * @param extra additional event data provided
   1734    * @param extra_size number of bytes in @a extra
   1735    */
   1736   void
   1737   (*event_notify)(void *cls,
   1738                   const struct GNUNET_DB_EventHeaderP *es,
   1739                   const void *extra,
   1740                   size_t extra_size);
   1741 
   1742 
   1743   /**
   1744    * Do a pre-flight check that we are not in an uncommitted transaction.  If
   1745    * we are, die.  Does not return anything, as we will continue regardless of
   1746    * the outcome.
   1747    *
   1748    * @param cls the `struct PostgresClosure` with the plugin-specific state
   1749    */
   1750   void
   1751   (*preflight) (void *cls);
   1752 
   1753   /**
   1754    * Start a transaction.
   1755    *
   1756    * @param cls the `struct PostgresClosure` with the plugin-specific state
   1757    * @param name unique name identifying the transaction (for debugging),
   1758    *             must point to a constant
   1759    * @return #GNUNET_OK on success
   1760    */
   1761   enum GNUNET_GenericReturnValue
   1762     (*start)(void *cls,
   1763              const char *name);
   1764 
   1765   /**
   1766    * Start a transaction with isolation level 'read committed'.
   1767    *
   1768    * @param cls the `struct PostgresClosure` with the plugin-specific state
   1769    * @param name unique name identifying the transaction (for debugging),
   1770    *             must point to a constant
   1771    * @return #GNUNET_OK on success
   1772    */
   1773   enum GNUNET_GenericReturnValue
   1774     (*start_read_committed)(void *cls,
   1775                             const char *name);
   1776 
   1777   /**
   1778    * Roll back the current transaction of a database connection.
   1779    *
   1780    * @param cls the `struct PostgresClosure` with the plugin-specific state
   1781    */
   1782   void
   1783   (*rollback) (void *cls);
   1784 
   1785   /**
   1786    * Commit the current transaction of a database connection.
   1787    *
   1788    * @param cls the `struct PostgresClosure` with the plugin-specific state
   1789    * @return transaction status
   1790    */
   1791   enum GNUNET_DB_QueryStatus
   1792     (*commit)(void *cls);
   1793 
   1794   /**
   1795    * Lookup all of the instances this backend has configured.
   1796    *
   1797    * @param cls closure
   1798    * @param active_only only find 'active' instances
   1799    * @param cb function to call on all instances found
   1800    * @param cb_cls closure for @a cb
   1801    */
   1802   enum GNUNET_DB_QueryStatus
   1803     (*lookup_instances)(void *cls,
   1804                         bool active_only,
   1805                         TALER_MERCHANTDB_InstanceCallback cb,
   1806                         void *cb_cls);
   1807 
   1808   /**
   1809    * Lookup one of the instances this backend has configured.
   1810    *
   1811    * @param cls closure
   1812    * @param id ID of instance to look up
   1813    * @param active_only only find 'active' instances
   1814    * @param cb function to call on all instances found
   1815    * @param cb_cls closure for @a cb
   1816    */
   1817   enum GNUNET_DB_QueryStatus
   1818     (*lookup_instance)(void *cls,
   1819                        const char *id,
   1820                        bool active_only,
   1821                        TALER_MERCHANTDB_InstanceCallback cb,
   1822                        void *cb_cls);
   1823 
   1824   /**
   1825    * Lookup authentication data of an instance.
   1826    *
   1827    * @param cls closure
   1828    * @param instance_id instance to query
   1829    * @param[out] ias where to store the auth data
   1830    */
   1831   enum GNUNET_DB_QueryStatus
   1832     (*lookup_instance_auth)(void *cls,
   1833                             const char *instance_id,
   1834                             struct TALER_MERCHANTDB_InstanceAuthSettings *ias);
   1835 
   1836 
   1837   /**
   1838    * Insert information about an instance into our database.
   1839    *
   1840    * @param cls closure
   1841    * @param merchant_pub public key of the instance
   1842    * @param merchant_priv private key of the instance
   1843    * @param is details about the instance
   1844    * @param validation_needed true if validation is
   1845    *        required before the instance can be used
   1846    * @return database result code
   1847    */
   1848   enum GNUNET_DB_QueryStatus
   1849     (*insert_instance)(void *cls,
   1850                        const struct TALER_MerchantPublicKeyP *merchant_pub,
   1851                        const struct TALER_MerchantPrivateKeyP *merchant_priv,
   1852                        const struct TALER_MERCHANTDB_InstanceSettings *is,
   1853                        const struct TALER_MERCHANTDB_InstanceAuthSettings *ias,
   1854                        bool validation_needed);
   1855 
   1856 
   1857   /**
   1858    * Insert information about an instance's account into our database.
   1859    *
   1860    * @param cls closure
   1861    * @param account_details details about the account
   1862    * @return database result code
   1863    */
   1864   enum GNUNET_DB_QueryStatus
   1865     (*insert_account)(
   1866     void *cls,
   1867     const struct TALER_MERCHANTDB_AccountDetails *account_details);
   1868 
   1869 
   1870   /**
   1871    * Insert instance login token into our database.
   1872    *
   1873    * @param cls closure
   1874    * @param id identifier of the instance
   1875    * @param token value of the token
   1876    * @param creation_time the current time
   1877    * @param expiration_time when does the token expire
   1878    * @param validity_scope scope of the token
   1879    * @param description description of the token
   1880    * @return database result code
   1881    */
   1882   enum GNUNET_DB_QueryStatus
   1883     (*insert_login_token)(
   1884     void *cls,
   1885     const char *id,
   1886     const struct TALER_MERCHANTDB_LoginTokenP *token,
   1887     struct GNUNET_TIME_Timestamp creation_time,
   1888     struct GNUNET_TIME_Timestamp expiration_time,
   1889     uint32_t validity_scope,
   1890     const char *description);
   1891 
   1892 
   1893   /**
   1894    * Lookup information about a login token from database.
   1895    *
   1896    * @param cls closure
   1897    * @param id identifier of the instance
   1898    * @param token value of the token
   1899    * @param[out] expiration_time set to expiration time
   1900    * @param[out] validity_scope set to scope of the token
   1901    * @return database result code
   1902    */
   1903   enum GNUNET_DB_QueryStatus
   1904     (*select_login_token)(
   1905     void *cls,
   1906     const char *id,
   1907     const struct TALER_MERCHANTDB_LoginTokenP *token,
   1908     struct GNUNET_TIME_Timestamp *expiration_time,
   1909     uint32_t *validity_scope);
   1910 
   1911   /**
   1912    * Lookup login tokens for instance.
   1913    *
   1914    * @param cls closure
   1915    * @param instance_id instance to lookup tokens for
   1916    * @param offset transfer_serial number of the transfer we want to offset from
   1917    * @param limit number of entries to return, negative for descending,
   1918    *                positive for ascending
   1919    * @param cb function to call on all products found
   1920    * @param cb_cls closure for @a cb
   1921    * @return database result code
   1922     */
   1923   enum GNUNET_DB_QueryStatus
   1924     (*lookup_login_tokens)(void *cls,
   1925                            const char *instance_id,
   1926                            uint64_t offset,
   1927                            int64_t limit,
   1928                            TALER_MERCHANTDB_LoginTokensCallback cb,
   1929                            void *cb_cls);
   1930 
   1931   /**
   1932    * Delete login token from database.
   1933    *
   1934    * @param cls closure
   1935    * @param id identifier of the instance
   1936    * @param token value of the token
   1937    * @return database result code
   1938    */
   1939   enum GNUNET_DB_QueryStatus
   1940     (*delete_login_token)(
   1941     void *cls,
   1942     const char *id,
   1943     const struct TALER_MERCHANTDB_LoginTokenP *token);
   1944 
   1945   /**
   1946    * Delete login token from database by serial.
   1947    *
   1948    * @param cls closure
   1949    * @param id identifier of the instance
   1950    * @param serial serial of the token
   1951    * @return database result code
   1952    */
   1953   enum GNUNET_DB_QueryStatus
   1954     (*delete_login_token_serial)(
   1955     void *cls,
   1956     const char *id,
   1957     uint64_t serial);
   1958 
   1959 
   1960   /**
   1961    * Update information about an instance's account into our database.
   1962    *
   1963    * @param cls closure
   1964    * @param id identifier of the instance
   1965    * @param h_wire which account to update
   1966    * @param credit_facade_url new facade URL, can be NULL
   1967    * @param credit_facade_credentials new credentials, can be NULL
   1968    * @return database result code
   1969    */
   1970   enum GNUNET_DB_QueryStatus
   1971     (*update_account)(
   1972     void *cls,
   1973     const char *id,
   1974     const struct TALER_MerchantWireHashP *h_wire,
   1975     const char *credit_facade_url,
   1976     const json_t *credit_facade_credentials);
   1977 
   1978 
   1979   /**
   1980    * Obtain information about an instance's accounts.
   1981    *
   1982    * @param cls closure
   1983    * @param id identifier of the instance
   1984    * @param cb function to call on each account
   1985    * @param cb_cls closure for @a cb
   1986    * @return database result code
   1987    */
   1988   enum GNUNET_DB_QueryStatus
   1989     (*select_accounts)(
   1990     void *cls,
   1991     const char *id,
   1992     TALER_MERCHANTDB_AccountCallback cb,
   1993     void *cb_cls);
   1994 
   1995 
   1996   /**
   1997    * Obtain detailed information about an instance's account.
   1998    *
   1999    * @param cls closure
   2000    * @param id identifier of the instance
   2001    * @param h_wire wire hash of the account
   2002    * @param[out] ad account details returned
   2003    * @return database result code
   2004    */
   2005   enum GNUNET_DB_QueryStatus
   2006     (*select_account)(
   2007     void *cls,
   2008     const char *id,
   2009     const struct TALER_MerchantWireHashP *h_wire,
   2010     struct TALER_MERCHANTDB_AccountDetails *ad);
   2011 
   2012 
   2013   /**
   2014  * Obtain detailed information about an instance's account.
   2015  *
   2016  * @param cls closure
   2017  * @param id identifier of the instance
   2018  * @param payto_uri URI of the account
   2019  * @param[out] ad account details returned
   2020  * @return database result code
   2021  */
   2022   enum GNUNET_DB_QueryStatus
   2023     (*select_account_by_uri)(
   2024     void *cls,
   2025     const char *id,
   2026     struct TALER_FullPayto payto_uri,
   2027     struct TALER_MERCHANTDB_AccountDetails *ad);
   2028 
   2029 
   2030   /**
   2031    * Delete private key of an instance from our database.
   2032    *
   2033    * @param cls closure
   2034    * @param merchant_id identifier of the instance
   2035    * @return database result code
   2036    */
   2037   enum GNUNET_DB_QueryStatus
   2038     (*delete_instance_private_key)(
   2039     void *cls,
   2040     const char *merchant_id);
   2041 
   2042   /**
   2043    * Purge an instance and all associated information from our database.
   2044    * Highly likely to cause undesired data loss. Use with caution.
   2045    *
   2046    * @param cls closure
   2047    * @param merchant_id identifier of the instance
   2048    * @return database result code
   2049    */
   2050   enum GNUNET_DB_QueryStatus
   2051     (*purge_instance)(void *cls,
   2052                       const char *merchant_id);
   2053 
   2054   /**
   2055    * Update information about an instance into our database.
   2056    *
   2057    * @param cls closure
   2058    * @param is details about the instance
   2059    * @return database result code
   2060    */
   2061   enum GNUNET_DB_QueryStatus
   2062     (*update_instance)(void *cls,
   2063                        const struct TALER_MERCHANTDB_InstanceSettings *is);
   2064 
   2065   /**
   2066    * Update information about an instance's authentication settings
   2067    * into our database.
   2068    *
   2069    * @param cls closure
   2070    * @param merchant_id merchant backend instance ID
   2071    * @param ias instance auth settings
   2072    * @return database result code
   2073    */
   2074   enum GNUNET_DB_QueryStatus
   2075     (*update_instance_auth)(
   2076     void *cls,
   2077     const char *merchant_id,
   2078     const struct TALER_MERCHANTDB_InstanceAuthSettings *ias);
   2079 
   2080   /**
   2081    * Set an instance's account in our database to "inactive".
   2082    *
   2083    * @param cls closure
   2084    * @param merchant_id merchant backend instance ID
   2085    * @param h_wire hash of the wire account to set to inactive
   2086    * @return database result code
   2087    */
   2088   enum GNUNET_DB_QueryStatus
   2089     (*inactivate_account)(void *cls,
   2090                           const char *merchant_id,
   2091                           const struct TALER_MerchantWireHashP *h_wire);
   2092 
   2093 
   2094   /**
   2095    * Set an instance's account in our database to "active".
   2096    *
   2097    * @param cls closure
   2098    * @param merchant_id merchant backend instance ID
   2099    * @param h_wire hash of the wire account to set to active
   2100    * @return database result code
   2101    */
   2102   enum GNUNET_DB_QueryStatus
   2103     (*activate_account)(void *cls,
   2104                         const char *merchant_id,
   2105                         const struct TALER_MerchantWireHashP *h_wire);
   2106 
   2107 
   2108   /**
   2109    * Check an instance's account's KYC status.
   2110    *
   2111    * @param cls closure
   2112    * @param merchant_id merchant backend instance ID
   2113    * @param h_wire hash of the wire account to check,
   2114    *        NULL to check all accounts of the merchant
   2115    * @param exchange_url base URL of the exchange to check,
   2116    *        NULL to check all exchanges
   2117    * @param kyc_cb KYC status callback to invoke
   2118    * @param kyc_cb_cls closure for @a kyc_cb
   2119    * @return database result code
   2120    */
   2121   enum GNUNET_DB_QueryStatus
   2122     (*account_kyc_get_status)(
   2123     void *cls,
   2124     const char *merchant_id,
   2125     const struct TALER_MerchantWireHashP *h_wire,
   2126     const char *exchange_url,
   2127     TALER_MERCHANTDB_KycCallback kyc_cb,
   2128     void *kyc_cb_cls);
   2129 
   2130   /**
   2131    * Check an account's KYC status at an exchange.
   2132    *
   2133    * @param cls closure
   2134    * @param merchant_payto_uri  merchant backend instance ID
   2135    * @param instance_id the instance for which to check
   2136    * @param exchange_url base URL of the exchange
   2137    * @param[out] auth_ok true if @a access_token was set
   2138    * @param[out] access_token set to access token for /kyc-info
   2139    * @param[out] kyc_ok true if no urgent KYC work must be done for this account
   2140    * @param[out] last_http_status set to last HTTP status from exchange on /kyc-check
   2141    * @param[out] last_ec set to last Taler error code from exchange on /kyc-check
   2142    * @param[out] rule_gen set to decision row at the exchange, 0 if no
   2143    *    known decision of the exchange exists for this record; used
   2144    *    for long-polling for changes to exchange decisions
   2145    * @param[out] last_kyc_check set to time of last KYC check
   2146    * @param[out] aml_review set to true if the account is under AML review (if this exposed)
   2147    * @param[out] jlimits set to JSON array with AccountLimits, NULL if unknown (and likely defaults apply or KYC auth is urgently needed, see @a auth_ok)
   2148    * @return database result code
   2149    */
   2150   enum GNUNET_DB_QueryStatus
   2151     (*get_kyc_status)(
   2152     void *cls,
   2153     struct TALER_FullPayto merchant_account_uri,
   2154     const char *instance_id,
   2155     const char *exchange_url,
   2156     bool *auth_ok,
   2157     struct TALER_AccountAccessTokenP *access_token,
   2158     bool *kyc_ok,
   2159     unsigned int *last_http_status,
   2160     enum TALER_ErrorCode *last_ec,
   2161     uint64_t *rule_gen,
   2162     struct GNUNET_TIME_Timestamp *last_kyc_check,
   2163     bool *aml_review,
   2164     json_t **jlimits);
   2165 
   2166 
   2167   /**
   2168    * Check an account's KYC limits at an exchange.
   2169    *
   2170    * @param cls closure
   2171    * @param merchant_payto_uri  merchant backend instance ID
   2172    * @param instance_id the instance for which to check
   2173    * @param exchange_url base URL of the exchange
   2174    * @param[out] kyc_ok true if no urgent KYC work must be done for this account
   2175    * @param[out] no_access_token true if we do not have a valid KYC access token (KYC auth missing)
   2176    * @param[out] jlimits set to JSON array with AccountLimits, NULL if unknown (and likely defaults apply or KYC auth is urgently needed, see @a auth_ok)
   2177    * @return database result code
   2178    */
   2179   enum GNUNET_DB_QueryStatus
   2180     (*get_kyc_limits)(
   2181     void *cls,
   2182     struct TALER_FullPayto merchant_account_uri,
   2183     const char *instance_id,
   2184     const char *exchange_url,
   2185     bool *kyc_ok,
   2186     bool *no_access_token,
   2187     json_t **jlimits);
   2188 
   2189 
   2190   /**
   2191    * Update an instance's account's KYC status.
   2192    *
   2193    * @param cls closure
   2194    * @param merchant_id merchant backend instance ID
   2195    * @param h_wire hash of the wire account to check
   2196    * @param exchange_url base URL of the exchange to check
   2197    * @param timestamp timestamp to store
   2198    * @param exchange_http_status HTTP status code returned last by the exchange
   2199    * @param exchange_ec_code Taler error code returned last by the exchange
   2200    * @param rule_gen generation of the rule in the exchange database
   2201    *      (useful for long-polling to wait for rule changes)
   2202    * @param access_token access token for the KYC process, NULL for none
   2203    * @param jlimits JSON array with AccountLimits returned by the exchange
   2204    * @param in_aml_review true if the exchange says the account is under review
   2205    * @param kyc_ok current KYC status (true for satisfied)
   2206    * @return database result code
   2207    */
   2208   enum GNUNET_DB_QueryStatus
   2209     (*account_kyc_set_status)(
   2210     void *cls,
   2211     const char *merchant_id,
   2212     const struct TALER_MerchantWireHashP *h_wire,
   2213     const char *exchange_url,
   2214     struct GNUNET_TIME_Timestamp timestamp,
   2215     unsigned int exchange_http_status,
   2216     enum TALER_ErrorCode exchange_ec_code,
   2217     uint64_t rule_gen,
   2218     const struct TALER_AccountAccessTokenP *access_token,
   2219     const json_t *jlimits,
   2220     bool in_aml_review,
   2221     bool kyc_ok);
   2222 
   2223 
   2224   /**
   2225    * Set an instance's account's KYC status to failed.
   2226    *
   2227    * @param cls closure
   2228    * @param merchant_id merchant backend instance ID
   2229    * @param h_wire hash of the wire account to check
   2230    * @param exchange_url base URL of the exchange to check
   2231    * @param timestamp timestamp to store
   2232    * @param exchange_http_status HTTP status code returned last by the exchange
   2233    * @param kyc_ok current KYC status (should be false)
   2234    * @return database result code
   2235    */
   2236   enum GNUNET_DB_QueryStatus
   2237     (*account_kyc_set_failed)(
   2238     void *cls,
   2239     const char *merchant_id,
   2240     const struct TALER_MerchantWireHashP *h_wire,
   2241     const char *exchange_url,
   2242     struct GNUNET_TIME_Timestamp timestamp,
   2243     unsigned int exchange_http_status,
   2244     bool kyc_ok);
   2245 
   2246 
   2247   /**
   2248    * Lookup all of the products the given instance has configured.
   2249    *
   2250    * @param cls closure
   2251    * @param instance_id instance to lookup products for
   2252    * @param offset transfer_serial number of the transfer we want to offset from
   2253    * @param limit number of entries to return, negative for descending,
   2254    *                positive for ascending
   2255    * @param category_filter filter products by category, NULL to not filter;
   2256    *                uses the Postgresql "LIKE" pattern matcher, so
   2257    *                "%" stands for any sequence of zero or more characters,
   2258    *                "_" stands for any single character;
   2259    *                use "\%" and "\_" to exactly match "%" or "_".
   2260    *                We will always use case-insensitive searches, for case-sensitive
   2261    *                matching the client should filter the result set.
   2262    * @param name_filter filter products by name, NULL to not filter
   2263    *                uses the Postgresql "LIKE" pattern matcher, so
   2264    *                "%" stands for any sequence of zero or more characters,
   2265    *                "_" stands for any single character
   2266    *                use "\%" and "\_" to exactly match "%" or "_".
   2267    *                We will always use case-insensitive searches, for case-sensitive
   2268    *                matching the client should filter the result set.
   2269    * @param description_filter filter products by description, NULL to not filter
   2270    *                uses the Postgresql "LIKE" pattern matcher, so
   2271    *                "%" stands for any sequence of zero or more characters,
   2272    *                "_" stands for any single character
   2273    *                use "\%" and "\_" to exactly match "%" or "_".
   2274    *                We will always use case-insensitive searches, for case-sensitive
   2275    *                matching the client should filter the result set.
   2276    * @param cb function to call on all products found
   2277    * @param cb_cls closure for @a cb
   2278    * @return database result code
   2279    */
   2280   enum GNUNET_DB_QueryStatus
   2281     (*lookup_products)(void *cls,
   2282                        const char *instance_id,
   2283                        uint64_t offset,
   2284                        int64_t limit,
   2285                        const char *category_filter,
   2286                        const char *name_filter,
   2287                        const char *description_filter,
   2288                        TALER_MERCHANTDB_ProductsCallback cb,
   2289                        void *cb_cls);
   2290 
   2291 
   2292   /**
   2293    * Lookup full details of all of the products the given instance has configured (expensive).
   2294    *
   2295    * @param cls closure
   2296    * @param instance_id instance to lookup products for
   2297    * @param cb function to call on all products found
   2298    * @param cb_cls closure for @a cb
   2299    * @return database result code
   2300    */
   2301   enum GNUNET_DB_QueryStatus
   2302     (*lookup_all_products)(void *cls,
   2303                            const char *instance_id,
   2304                            TALER_MERCHANTDB_ProductCallback cb,
   2305                            void *cb_cls);
   2306 
   2307   /**
   2308    * Lookup details about a particular product.
   2309    *
   2310    * @param cls closure
   2311    * @param instance_id instance to lookup products for
   2312    * @param product_id product to lookup
   2313    * @param[out] pd set to the product details on success, can be NULL
   2314    *             (in that case we only want to check if the product exists)
   2315    * @param[out] num_categories set to length of @a categories array
   2316    * @param[out] categories set to array of categories the
   2317    *   product is in, caller must free() it.
   2318    * @return database result code
   2319    */
   2320   enum GNUNET_DB_QueryStatus
   2321     (*lookup_product)(void *cls,
   2322                       const char *instance_id,
   2323                       const char *product_id,
   2324                       struct TALER_MERCHANTDB_ProductDetails *pd,
   2325                       size_t *num_categories,
   2326                       uint64_t **categories);
   2327   /**
   2328    * Lookup product image by its hash.
   2329    *
   2330    * @param cls closure
   2331    * @param instance_id instance to lookup products for
   2332    * @param image_hash lowercase hexadecimal representation of the SHA256 hash
   2333    * @param[out] image set to base64-encoded data URL on success, caller must free()
   2334    * @return database result code
   2335    */
   2336   enum GNUNET_DB_QueryStatus
   2337     (*lookup_product_image_by_hash)(void *cls,
   2338                                     const char *instance_id,
   2339                                     const char *image_hash,
   2340                                     char **image);
   2341 
   2342   /**
   2343    * Delete information about a product. Note that the transaction must
   2344    * enforce that no stocks are currently locked.
   2345    *
   2346    * @param cls closure
   2347    * @param instance_id instance to delete product of
   2348    * @param product_id product to delete
   2349    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
   2350    *           if locks prevent deletion OR product unknown
   2351    */
   2352   enum GNUNET_DB_QueryStatus
   2353     (*delete_product)(void *cls,
   2354                       const char *instance_id,
   2355                       const char *product_id);
   2356 
   2357   /**
   2358    * Insert details about a particular product.
   2359    *
   2360    * @param cls closure
   2361    * @param instance_id instance to insert product for
   2362    * @param product_id product identifier of product to insert
   2363    * @param pd the product details to insert
   2364    * @param num_cats length of @a cats array
   2365    * @param cats array of categories the product is in
   2366    * @param[out] no_instance set to true if @a instance_id is unknown
   2367    * @param[out] conflict set to true if a conflicting
   2368    *        product already exists in the database
   2369    * @param[out] no_cat set to index of non-existing category from @a cats, or -1 if all @a cats were found
   2370    * @return database result code
   2371    */
   2372   enum GNUNET_DB_QueryStatus
   2373     (*insert_product)(void *cls,
   2374                       const char *instance_id,
   2375                       const char *product_id,
   2376                       const struct TALER_MERCHANTDB_ProductDetails *pd,
   2377                       size_t num_cats,
   2378                       const uint64_t *cats,
   2379                       bool *no_instance,
   2380                       bool *conflict,
   2381                       ssize_t *no_cat);
   2382 
   2383   /**
   2384    * Update details about a particular product. Note that the
   2385    * transaction must enforce that the sold/stocked/lost counters
   2386    * are not reduced (i.e. by expanding the WHERE clause on the existing
   2387    * values).
   2388    *
   2389    * @param cls closure
   2390    * @param instance_id instance to lookup products for
   2391    * @param product_id product to lookup
   2392    * @param pd product details with updated values
   2393    * @param num_cats length of @a cats array
   2394    * @param cats number of categories the product is in
   2395    * @param[out] no_instance the update failed as the instance is unknown
   2396    * @param[out] no_cat set to -1 on success, otherwise the update failed and this is set
   2397    *                to the index of a category in @a cats that is unknown
   2398    * @param[out] no_product the @a product_id is unknown
   2399    * @param[out] lost_reduced the update failed as the counter of units lost would have been lowered
   2400    * @param[out] sold_reduced the update failed as the counter of units sold would have been lowered
   2401    * @param[out] stocked_reduced the update failed as the counter of units stocked would have been lowered
   2402    * @return database result code
   2403    */
   2404   enum GNUNET_DB_QueryStatus
   2405     (*update_product)(void *cls,
   2406                       const char *instance_id,
   2407                       const char *product_id,
   2408                       const struct TALER_MERCHANTDB_ProductDetails *pd,
   2409                       size_t num_cats,
   2410                       const uint64_t *cats,
   2411                       bool *no_instance,
   2412                       ssize_t *no_cat,
   2413                       bool *no_product,
   2414                       bool *lost_reduced,
   2415                       bool *sold_reduced,
   2416                       bool *stocked_reduced);
   2417 
   2418   /**
   2419    * Lock stocks of a particular product. Note that the transaction must
   2420    * enforce that the "stocked-sold-lost >= locked" constraint holds.
   2421    *
   2422    * @param cls closure
   2423    * @param instance_id instance to lookup products for
   2424    * @param product_id product to lookup
   2425    * @param uuid the UUID that holds the lock
   2426    * @param quantity how many units should be locked
   2427    * @param quantity_frac fractional component of units to lock, in units of
   2428    *        1/1000000 of the base value
   2429    * @param expiration_time when should the lock expire
   2430    * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the
   2431    *         product is unknown OR if there insufficient stocks remaining
   2432    */
   2433   enum GNUNET_DB_QueryStatus
   2434     (*lock_product)(void *cls,
   2435                     const char *instance_id,
   2436                     const char *product_id,
   2437                     const struct GNUNET_Uuid *uuid,
   2438                     uint64_t quantity,
   2439                     uint32_t quantity_frac,
   2440                     struct GNUNET_TIME_Timestamp expiration_time);
   2441 
   2442 
   2443   /**
   2444    * Release all expired product locks, including
   2445    * those from expired offers -- across all
   2446    * instances.
   2447    *
   2448    * @param cls closure
   2449    * @return database result code
   2450    */
   2451   enum GNUNET_DB_QueryStatus
   2452     (*expire_locks)(void *cls);
   2453 
   2454 
   2455   /**
   2456    * Delete information about an order. Note that the transaction must
   2457    * enforce that the order is not awaiting payment anymore.
   2458    *
   2459    * @param cls closure
   2460    * @param instance_id instance to delete order of
   2461    * @param order_id order to delete
   2462    * @param force force deletion of claimed but unpaid orders
   2463    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
   2464    *           if locks prevent deletion OR order unknown
   2465    */
   2466   enum GNUNET_DB_QueryStatus
   2467     (*delete_order)(void *cls,
   2468                     const char *instance_id,
   2469                     const char *order_id,
   2470                     bool force);
   2471 
   2472 
   2473   /**
   2474    * Retrieve order given its @a order_id and the @a instance_id.
   2475    *
   2476    * @param cls closure
   2477    * @param instance_id instance to obtain order of
   2478    * @param order_id order id used to perform the lookup
   2479    * @param[out] claim_token the claim token generated for the order,
   2480    *             NULL to only test if the order exists
   2481    * @param[out] h_post_data set to the hash of the POST data that created the order
   2482    * @param[out] contract_terms where to store the retrieved contract terms,
   2483    *             NULL to only test if the order exists
   2484    * @return transaction status
   2485    */
   2486   enum GNUNET_DB_QueryStatus
   2487     (*lookup_order)(void *cls,
   2488                     const char *instance_id,
   2489                     const char *order_id,
   2490                     struct TALER_ClaimTokenP *claim_token,
   2491                     struct TALER_MerchantPostDataHashP *h_post_data,
   2492                     json_t **contract_terms);
   2493 
   2494 
   2495   /**
   2496    * Retrieve order summary given its @a order_id and the @a instance_id.
   2497    *
   2498    * @param cls closure
   2499    * @param instance_id instance to obtain order of
   2500    * @param order_id order id used to perform the lookup
   2501    * @param[out] timestamp when was the order created
   2502    * @param[out] order_serial under which serial do we keep this order
   2503    * @return transaction status
   2504    */
   2505   enum GNUNET_DB_QueryStatus
   2506     (*lookup_order_summary)(void *cls,
   2507                             const char *instance_id,
   2508                             const char *order_id,
   2509                             struct GNUNET_TIME_Timestamp *timestamp,
   2510                             uint64_t *order_serial);
   2511 
   2512 
   2513   /**
   2514    * Retrieve orders given the @a instance_id.
   2515    *
   2516    * @param cls closure
   2517    * @param instance_id instance to obtain order of
   2518    * @param of filter to apply when looking up orders
   2519    * @param[out] contract_terms where to store the retrieved contract terms,
   2520    *             NULL to only test if the order exists
   2521    * @return transaction status
   2522    */
   2523   enum GNUNET_DB_QueryStatus
   2524     (*lookup_orders)(void *cls,
   2525                      const char *instance_id,
   2526                      const struct TALER_MERCHANTDB_OrderFilter *of,
   2527                      TALER_MERCHANTDB_OrdersCallback cb,
   2528                      void *cb_cls);
   2529 
   2530 
   2531   /**
   2532    * Insert order into db.
   2533    *
   2534    * @param cls closure
   2535    * @param instance_id identifies the instance responsible for the order
   2536    * @param order_id alphanumeric string that uniquely identifies the order
   2537    * @param session_id session ID for the order
   2538    * @param h_post_data hash of the POST data for idempotency checks
   2539    * @param pay_deadline how long does the customer have to pay for the order
   2540    * @param claim_token token to use for access control
   2541    * @param contract_terms proposal data to store
   2542    * @param pos_key encoded key for payment verification
   2543    * @param pos_algorithm algorithm to compute the payment verification
   2544    * @return transaction status
   2545    */
   2546   enum GNUNET_DB_QueryStatus
   2547     (*insert_order)(void *cls,
   2548                     const char *instance_id,
   2549                     const char *order_id,
   2550                     const char *session_id,
   2551                     const struct TALER_MerchantPostDataHashP *h_post_data,
   2552                     struct GNUNET_TIME_Timestamp pay_deadline,
   2553                     const struct TALER_ClaimTokenP *claim_token,
   2554                     const json_t *contract_terms,
   2555                     const char *pos_key,
   2556                     enum TALER_MerchantConfirmationAlgorithm pos_algorithm);
   2557 
   2558 
   2559   /**
   2560    * Insert blinded signatures for an order.
   2561    *
   2562    * @param cls closure
   2563    * @param order_id order ID to insert blinded signatures for
   2564    * @param i index of the blinded signature in the output array
   2565    * @param hash hash of the token
   2566    * @param blinded_sigs JSON array of blinded signatures
   2567    */
   2568   enum GNUNET_DB_QueryStatus
   2569     (*insert_order_blinded_sigs)(
   2570     void *cls,
   2571     const char *order_id,
   2572     uint32_t i,
   2573     const struct GNUNET_HashCode *hash,
   2574     const struct GNUNET_CRYPTO_BlindedSignature *blind_sig);
   2575 
   2576 
   2577   /**
   2578    * Release an inventory lock by UUID. Releases ALL stocks locked under
   2579    * the given UUID.
   2580    *
   2581    * @param cls closure
   2582    * @param uuid the UUID to release locks for
   2583    * @return transaction status,
   2584    *   #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means there are no locks under @a uuid
   2585    *   #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates success
   2586    */
   2587   enum GNUNET_DB_QueryStatus
   2588     (*unlock_inventory)(void *cls,
   2589                         const struct GNUNET_Uuid *uuid);
   2590 
   2591 
   2592   /**
   2593    * Lock inventory stock to a particular order.
   2594    *
   2595    * @param cls closure
   2596    * @param instance_id identifies the instance responsible for the order
   2597    * @param order_id alphanumeric string that uniquely identifies the order
   2598    * @param product_id uniquely identifies the product to be locked
   2599    * @param quantity how many units should be locked to the @a order_id
   2600    * @param quantity_frac fractional component of the quantity to be locked,
   2601    *        in units of 1/1000000 of the base value
   2602    * @return transaction status,
   2603    *   #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means there are insufficient stocks
   2604    *   #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates success
   2605    */
   2606   enum GNUNET_DB_QueryStatus
   2607     (*insert_order_lock)(void *cls,
   2608                          const char *instance_id,
   2609                          const char *order_id,
   2610                          const char *product_id,
   2611                          uint64_t quantity,
   2612                          uint32_t quantity_frac);
   2613 
   2614 
   2615   /**
   2616    * Select blinded signatures for an order.
   2617    *
   2618    * @param cls closure
   2619    * @param order_id order ID to select blinded signatures for
   2620    * @param cb callback to call for each blinded signature found
   2621    * @param cb_cls closure for @a cb
   2622    */
   2623   enum GNUNET_DB_QueryStatus
   2624     (*select_order_blinded_sigs)(
   2625     void *cls,
   2626     const char *order_id,
   2627     TALER_MERCHANTDB_BlindedSigCallback cb,
   2628     void *cb_cls);
   2629 
   2630 
   2631   /**
   2632    * Retrieve contract terms given its @a order_id
   2633    *
   2634    * @param cls closure
   2635    * @param instance_id instance's identifier
   2636    * @param order_id order_id used to lookup.
   2637    * @param[out] contract_terms where to store the result, NULL to only check for existence
   2638    * @param[out] order_serial set to the order's serial number
   2639    * @param[out] paid set to true if the order is fully paid
   2640    * @param[out] claim_token set to the claim token, NULL to only check for existence
   2641    * @param[out] pos_key encoded key for payment verification
   2642    * @param[out] pos_algorithm set to algorithm to compute the payment verification
   2643    * @return transaction status
   2644    */
   2645   enum GNUNET_DB_QueryStatus
   2646     (*lookup_contract_terms2)(
   2647     void *cls,
   2648     const char *instance_id,
   2649     const char *order_id,
   2650     json_t **contract_terms,
   2651     uint64_t *order_serial,
   2652     bool *paid,
   2653     struct TALER_ClaimTokenP *claim_token,
   2654     char **pos_key,
   2655     enum TALER_MerchantConfirmationAlgorithm *pricing_algorithm);
   2656 
   2657 
   2658   /**
   2659    * Retrieve contract terms given its @a order_id
   2660    *
   2661    * @param cls closure
   2662    * @param instance_id instance's identifier
   2663    * @param order_id order_id used to lookup
   2664    * @param session_id session_id to compare, can be NULL
   2665    * @param[out] contract_terms where to store the result, NULL to only check for existence
   2666    * @param[out] order_serial set to the order's serial number
   2667    * @param[out] paid set to true if the order is fully paid
   2668    * @param[out] wired set to true if the exchange wired the funds
   2669    * @param[out] session_matches set to true if @a session_id matches session stored for this contract
   2670    * @param[out] claim_token set to the claim token, NULL to only check for existence
   2671    * @param[out] choice_index set to the choice index, -1 if not set
   2672    * @return transaction status
   2673    */
   2674   enum GNUNET_DB_QueryStatus
   2675     (*lookup_contract_terms3)(
   2676     void *cls,
   2677     const char *instance_id,
   2678     const char *order_id,
   2679     const char *session_id,
   2680     json_t **contract_terms,
   2681     uint64_t *order_serial,
   2682     bool *paid,
   2683     bool *wired,
   2684     bool *session_matches,
   2685     struct TALER_ClaimTokenP *claim_token,
   2686     int16_t *choice_index);
   2687 
   2688 
   2689   /**
   2690    * Retrieve contract terms given its @a order_id
   2691    *
   2692    * @param cls closure
   2693    * @param instance_id instance's identifier
   2694    * @param order_id order_id used to lookup.
   2695    * @param[out] contract_terms where to store the result, NULL to only check for existence
   2696    * @param[out] order_serial set to the order's serial number
   2697    * @param[out] claim_token set to the claim token, NULL to only check for existence
   2698    * @return transaction status
   2699    */
   2700   enum GNUNET_DB_QueryStatus
   2701     (*lookup_contract_terms)(
   2702     void *cls,
   2703     const char *instance_id,
   2704     const char *order_id,
   2705     json_t **contract_terms,
   2706     uint64_t *order_serial,
   2707     struct TALER_ClaimTokenP *claim_token);
   2708 
   2709 
   2710   /**
   2711    * Store contract terms given its @a order_id. Note that some attributes are
   2712    * expected to be calculated inside of the function, like the hash of the
   2713    * contract terms (to be hashed), the creation_time and pay_deadline (to be
   2714    * obtained from the merchant_orders table). The "session_id" should be
   2715    * initially set to the empty string.  The "fulfillment_url" and "refund_deadline"
   2716    * must be extracted from @a contract_terms.
   2717    *
   2718    * @param cls closure
   2719    * @param instance_id instance's identifier
   2720    * @param order_id order_id used to store
   2721    * @param claim_token the token belonging to the order
   2722    * @param[out] order_serial set to the serial of the order
   2723    * @return transaction status, #GNUNET_DB_STATUS_HARD_ERROR if @a contract_terms
   2724    *          is malformed
   2725    */
   2726   enum GNUNET_DB_QueryStatus
   2727     (*insert_contract_terms)(
   2728     void *cls,
   2729     const char *instance_id,
   2730     const char *order_id,
   2731     json_t *contract_terms,
   2732     uint64_t *order_serial);
   2733 
   2734 
   2735   /**
   2736    * Update the contract terms stored for @a order_id. Note that some attributes are
   2737    * expected to be calculated inside of the function, like the hash of the
   2738    * contract terms (to be hashed), the creation_time and pay_deadline (to be
   2739    * obtained from the merchant_orders table). The "session_id" should be
   2740    * initially set to the empty string.  The "fulfillment_url" and "refund_deadline"
   2741    * must be extracted from @a contract_terms.
   2742    *
   2743    * @param cls closure
   2744    * @param instance_id instance's identifier
   2745    * @param order_id order_id used to store
   2746    * @param contract_terms contract to store
   2747    * @return transaction status, #GNUNET_DB_STATUS_HARD_ERROR if @a contract_terms
   2748    *          is malformed
   2749    */
   2750   enum GNUNET_DB_QueryStatus
   2751     (*update_contract_terms)(void *cls,
   2752                              const char *instance_id,
   2753                              const char *order_id,
   2754                              json_t *contract_terms);
   2755 
   2756 
   2757   /**
   2758    * Delete information about a contract. Note that the transaction must
   2759    * enforce that the contract is not awaiting payment anymore AND was not
   2760    * paid, or is past the legal expiration.
   2761    *
   2762    * @param cls closure
   2763    * @param instance_id instance to delete order of
   2764    * @param order_id order to delete
   2765    * @param legal_expiration how long do we need to keep (paid) contracts on
   2766    *          file for legal reasons (i.e. taxation)
   2767    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
   2768    *           if locks prevent deletion OR order unknown
   2769    */
   2770   enum GNUNET_DB_QueryStatus
   2771     (*delete_contract_terms)(void *cls,
   2772                              const char *instance_id,
   2773                              const char *order_id,
   2774                              struct GNUNET_TIME_Relative legal_expiration);
   2775 
   2776 
   2777   /**
   2778    * Lookup information about coins that were successfully deposited for a
   2779    * given contract.
   2780    *
   2781    * @param cls closure
   2782    * @param instance_id instance to lookup deposits for
   2783    * @param h_contract_terms proposal data's hashcode
   2784    * @param cb function to call with payment data
   2785    * @param cb_cls closure for @a cb
   2786    * @return transaction status
   2787    */
   2788   enum GNUNET_DB_QueryStatus
   2789     (*lookup_deposits)(void *cls,
   2790                        const char *instance_id,
   2791                        const struct TALER_PrivateContractHashP *h_contract_terms
   2792                        ,
   2793                        TALER_MERCHANTDB_DepositsCallback cb,
   2794                        void *cb_cls);
   2795 
   2796 
   2797   /**
   2798    * Insert an exchange signing key into our database.
   2799    *
   2800    * @param cls closure
   2801    * @param master_pub exchange master public key used for @a master_sig
   2802    * @param exchange_pub exchange signing key to insert
   2803    * @param start_date when does the signing key become valid
   2804    * @param expire_date when does the signing key stop being used
   2805    * @param end_date when does the signing key become void as proof
   2806    * @param master_sig signature of @a master_pub over the @a exchange_pub and the dates
   2807    */
   2808   enum GNUNET_DB_QueryStatus
   2809     (*insert_exchange_signkey)(
   2810     void *cls,
   2811     const struct TALER_MasterPublicKeyP *master_pub,
   2812     const struct TALER_ExchangePublicKeyP *exchange_pub,
   2813     struct GNUNET_TIME_Timestamp start_date,
   2814     struct GNUNET_TIME_Timestamp expire_date,
   2815     struct GNUNET_TIME_Timestamp end_date,
   2816     const struct TALER_MasterSignatureP *master_sig);
   2817 
   2818 
   2819   /**
   2820    * Insert deposit confirmation from the exchange into the database.
   2821    *
   2822    * @param cls closure
   2823    * @param instance_id instance to lookup deposits for
   2824    * @param deposit_timestamp time when the exchange generated the deposit confirmation
   2825    * @param h_contract_terms proposal data's hashcode
   2826    * @param exchange_url URL of the exchange that issued @a coin_pub
   2827    * @param wire_transfer_deadline when do we expect the wire transfer from the exchange
   2828    * @param total_without_fees deposited total in the batch without fees
   2829    * @param wire_fee wire fee the exchange charges
   2830    * @param h_wire hash of the wire details of the target account of the merchant
   2831    * @param exchange_sig signature from exchange that coin was accepted
   2832    * @param exchange_pub signing key that was used for @a exchange_sig
   2833    * @param[out] batch_deposit_serial_id set to the table row
   2834    * @return transaction status
   2835    */
   2836   enum GNUNET_DB_QueryStatus
   2837     (*insert_deposit_confirmation)(
   2838     void *cls,
   2839     const char *instance_id,
   2840     struct GNUNET_TIME_Timestamp deposit_timestamp,
   2841     const struct TALER_PrivateContractHashP *h_contract_terms,
   2842     const char *exchange_url,
   2843     struct GNUNET_TIME_Timestamp wire_transfer_deadline,
   2844     const struct TALER_Amount *total_without_fees,
   2845     const struct TALER_Amount *wire_fee,
   2846     const struct TALER_MerchantWireHashP *h_wire,
   2847     const struct TALER_ExchangeSignatureP *exchange_sig,
   2848     const struct TALER_ExchangePublicKeyP *exchange_pub,
   2849     uint64_t *batch_deposit_serial_id);
   2850 
   2851 
   2852   /**
   2853    * Insert information about coin deposited as part of
   2854    * a batch into the database.
   2855    *
   2856    * @param cls closure
   2857    * @param offset offset of the coin in the batch
   2858    * @param deposit_confirmation_serial_id deposit confirmation for the batch the coin is part of
   2859    * @param coin_pub public key of the coin
   2860    * @param coin_sig deposit signature of the coin
   2861    * @param amount_with_fee amount the exchange will deposit for this coin
   2862    * @param deposit_fee fee the exchange will charge for this coin
   2863    * @param refund_fee fee the exchange will charge for refunds of coin
   2864    * @param check_time at what time should we check the deposit status
   2865    *        with the exchange (for settlement)
   2866    * @return transaction status
   2867    */
   2868   enum GNUNET_DB_QueryStatus
   2869     (*insert_deposit)(
   2870     void *cls,
   2871     uint32_t offset,
   2872     uint64_t deposit_confirmation_serial_id,
   2873     const struct TALER_CoinSpendPublicKeyP *coin_pub,
   2874     const struct TALER_CoinSpendSignatureP *coin_sig,
   2875     const struct TALER_Amount *amount_with_fee,
   2876     const struct TALER_Amount *deposit_fee,
   2877     const struct TALER_Amount *refund_fee,
   2878     struct GNUNET_TIME_Absolute check_time);
   2879 
   2880 
   2881   /**
   2882    * Obtain refunds associated with a contract.
   2883    *
   2884    * @param cls closure, typically a connection to the db
   2885    * @param instance_id instance to lookup refunds for
   2886    * @param h_contract_terms hash code of the contract
   2887    * @param rc function to call for each coin on which there is a refund
   2888    * @param rc_cls closure for @a rc
   2889    * @return transaction status
   2890    */
   2891   enum GNUNET_DB_QueryStatus
   2892     (*lookup_refunds)(void *cls,
   2893                       const char *instance_id,
   2894                       const struct TALER_PrivateContractHashP *h_contract_terms,
   2895                       TALER_MERCHANTDB_RefundCallback rc,
   2896                       void *rc_cls);
   2897 
   2898 
   2899   /**
   2900    * Retrieve details about tokens that were used for an order.
   2901    *
   2902    * @param cls closure
   2903    * @param order_serial identifies the order
   2904    * @param cb function to call for each used token
   2905    * @param cb_cls closure for @a cb
   2906    * @return transaction status
   2907    */
   2908   enum GNUNET_DB_QueryStatus
   2909     (*lookup_spent_tokens_by_order)(void *cls,
   2910                                     uint64_t order_serial,
   2911                                     TALER_MERCHANTDB_UsedTokensCallback cb,
   2912                                     void *cb_cls);
   2913 
   2914 
   2915   /**
   2916    * Mark contract as paid and store the current @a session_id
   2917    * for which the contract was paid. Deletes the underlying order
   2918    * and marks the locked stocks of the order as sold.
   2919    *
   2920    * @param cls closure
   2921    * @param instance_id instance to mark contract as paid for
   2922    * @param h_contract_terms hash of the contract that is now paid
   2923    * @param session_id the session that paid the contract
   2924    * @return transaction status
   2925    */
   2926   enum GNUNET_DB_QueryStatus
   2927     (*mark_contract_paid)(
   2928     void *cls,
   2929     const char *instance_id,
   2930     const struct TALER_PrivateContractHashP *h_contract_terms,
   2931     const char *session_id,
   2932     int16_t choice_index);
   2933 
   2934 
   2935   /**
   2936    * Update session associated with a contract and return
   2937    * the fulfillment URL and the refund status.
   2938    *
   2939    * @param cls closure
   2940    * @param instance_id instance to mark contract as paid for
   2941    * @param h_contract_terms hash of the contract that is now paid
   2942    * @param session_id the session that paid the contract
   2943    * @param[out] fulfillment_url set to the fulfillment URL (possibly NULL)
   2944    * @param[out] refunded set to true if the order was refunded
   2945    * @return transaction status
   2946    */
   2947   enum GNUNET_DB_QueryStatus
   2948     (*update_contract_session)(
   2949     void *cls,
   2950     const char *instance_id,
   2951     const struct TALER_PrivateContractHashP *h_contract_terms,
   2952     const char *session_id,
   2953     char **fulfillment_url,
   2954     bool *refunded);
   2955 
   2956 
   2957   /**
   2958    * Function called during aborts to refund a coin. Marks the
   2959    * respective coin as refunded.
   2960    *
   2961    * @param cls closure
   2962    * @param instance_id instance to refund payment for
   2963    * @param h_contract_terms hash of the contract to refund coin for
   2964    * @param refund_timestamp timestamp of when the coin was refunded
   2965    * @param coin_pub public key of the coin to refund (fully)
   2966    * @param reason text justifying the refund
   2967    * @return transaction status
   2968    *        #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a coin_pub is unknown to us;
   2969    *        #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the request is valid,
   2970    *        regardless of whether it actually increased the refund
   2971    */
   2972   enum GNUNET_DB_QueryStatus
   2973     (*refund_coin)(void *cls,
   2974                    const char *instance_id,
   2975                    const struct TALER_PrivateContractHashP *h_contract_terms,
   2976                    struct GNUNET_TIME_Timestamp refund_timestamp,
   2977                    const struct TALER_CoinSpendPublicKeyP *coin_pub,
   2978                    const char *reason);
   2979 
   2980 
   2981   /**
   2982    * Retrieve contract terms given its @a order_id
   2983    *
   2984    * @param cls closure
   2985    * @param instance_id instance's identifier
   2986    * @param order_id order to lookup contract for
   2987    * @param[out] h_contract_terms set to the hash of the contract.
   2988    * @param[out] paid set to the payment status of the contract
   2989    * @return transaction status
   2990    */
   2991   enum GNUNET_DB_QueryStatus
   2992     (*lookup_order_status)(void *cls,
   2993                            const char *instance_id,
   2994                            const char *order_id,
   2995                            struct TALER_PrivateContractHashP *h_contract_terms,
   2996                            bool *paid);
   2997 
   2998   /**
   2999    * Retrieve contract terms given its @a order_serial
   3000    *
   3001    * @param cls closure
   3002    * @param instance_id instance's identifier
   3003    * @param order_serial serial ID of the order to look up
   3004    * @param[out] order_id set to ID of the order
   3005    * @param[out] h_contract_terms set to the hash of the contract.
   3006    * @param[out] paid set to the payment status of the contract
   3007    * @return transaction status
   3008    */
   3009   enum GNUNET_DB_QueryStatus
   3010     (*lookup_order_status_by_serial)(void *cls,
   3011                                      const char *instance_id,
   3012                                      uint64_t order_serial,
   3013                                      char **order_id,
   3014                                      struct TALER_PrivateContractHashP *
   3015                                      h_contract_terms,
   3016                                      bool *paid);
   3017 
   3018 
   3019   /**
   3020    * Retrieve details about coins that were deposited for an order.
   3021    *
   3022    * @param cls closure
   3023    * @param order_serial identifies the order
   3024    * @param cb function to call for each deposited coin
   3025    * @param cb_cls closure for @a cb
   3026    * @return transaction status
   3027    */
   3028   enum GNUNET_DB_QueryStatus
   3029     (*lookup_deposits_by_order)(void *cls,
   3030                                 uint64_t order_serial,
   3031                                 TALER_MERCHANTDB_DepositedCoinsCallback cb,
   3032                                 void *cb_cls);
   3033 
   3034 
   3035   /**
   3036    * Retrieve wire transfer details for all deposits associated with
   3037    * a given @a order_serial.
   3038    *
   3039    * @param cls closure
   3040    * @param order_serial identifies the order
   3041    * @param cb function called with the wire transfer details
   3042    * @param cb_cls closure for @a cb
   3043    * @return transaction status
   3044    */
   3045   enum GNUNET_DB_QueryStatus
   3046     (*lookup_transfer_details_by_order)(
   3047     void *cls,
   3048     uint64_t order_serial,
   3049     TALER_MERCHANTDB_OrderTransferDetailsCallback cb,
   3050     void *cb_cls);
   3051 
   3052 
   3053   /**
   3054    * Update transfer status.
   3055    *
   3056    * @param cls closure
   3057    * @param exchange_url the exchange that made the transfer
   3058    * @param wtid wire transfer subject
   3059    * @param next_attempt when should we try again (if ever)
   3060    * @param http_status last HTTP status code from the server, 0 for timeout
   3061    * @param ec current error state of checking the transfer
   3062    * @param detail last error detail from the server, possibly NULL
   3063    * @param needs_retry true if we should retry the request
   3064    * @return database transaction status
   3065    */
   3066   enum GNUNET_DB_QueryStatus
   3067     (*update_transfer_status)(
   3068     void *cls,
   3069     const char *exchange_url,
   3070     const struct TALER_WireTransferIdentifierRawP *wtid,
   3071     struct GNUNET_TIME_Absolute next_attempt,
   3072     unsigned int http_status,
   3073     enum TALER_ErrorCode ec,
   3074     const char *detail,
   3075     bool needs_retry);
   3076 
   3077 
   3078   /**
   3079    * Finalize transfer status with success.
   3080    *
   3081    * @param cls closure
   3082    * @param exchange_url the exchange that made the transfer
   3083    * @param wtid wire transfer subject
   3084    * @param h_details hash over all of the aggregated deposits
   3085    * @param total_amount total amount exchange claimed to have transferred
   3086    * @param wire_fee wire fee charged by the exchange
   3087    * @param exchange_pub key used to make @e exchange_sig
   3088    * @param exchange_sig signature of the exchange over reconciliation data
   3089    * @return database transaction status
   3090    */
   3091   enum GNUNET_DB_QueryStatus
   3092     (*finalize_transfer_status)(
   3093     void *cls,
   3094     const char *exchange_url,
   3095     const struct TALER_WireTransferIdentifierRawP *wtid,
   3096     const struct GNUNET_HashCode *h_details,
   3097     const struct TALER_Amount *total_amount,
   3098     const struct TALER_Amount *wire_fee,
   3099     const struct TALER_ExchangePublicKeyP *exchange_pub,
   3100     const struct TALER_ExchangeSignatureP *exchange_sig);
   3101 
   3102 
   3103   /**
   3104    * Retrieve wire transfer details of wire details
   3105    * that taler-merchant-exchange still needs to
   3106    * investigate.
   3107    *
   3108    * @param cls closure
   3109    * @param limit maximum number of results to return
   3110    * @param cb function called with the wire transfer data
   3111    * @param cb_cls closure for @a cb
   3112    * @return transaction status
   3113    */
   3114   enum GNUNET_DB_QueryStatus
   3115     (*select_open_transfers)(
   3116     void *cls,
   3117     uint64_t limit,
   3118     TALER_MERCHANTDB_OpenTransferCallback cb,
   3119     void *cb_cls);
   3120 
   3121 
   3122   /**
   3123    * Insert wire transfer details for a deposit.
   3124    *
   3125    * @param cls closure
   3126    * @param deposit_serial serial number of the deposit
   3127    * @param h_wire hash of the merchant's account that should receive the deposit
   3128    * @param exchange_url URL of the exchange that is making the deposit
   3129    * @param dd deposit transfer data from the exchange to store
   3130    * @return transaction status
   3131    */
   3132   enum GNUNET_DB_QueryStatus
   3133     (*insert_deposit_to_transfer)(void *cls,
   3134                                   uint64_t deposit_serial,
   3135                                   const struct TALER_MerchantWireHashP *h_wire,
   3136                                   const char *exchange_url,
   3137                                   const struct TALER_EXCHANGE_DepositData *dd);
   3138 
   3139 
   3140   /**
   3141    * Set 'wired' status for an order to 'true'.
   3142    *
   3143    * @param cls closure
   3144    * @param order_serial serial number of the order
   3145    * @return transaction status
   3146    */
   3147   enum GNUNET_DB_QueryStatus
   3148     (*mark_order_wired)(void *cls,
   3149                         uint64_t order_serial);
   3150 
   3151 
   3152   /**
   3153    * Function called when some backoffice staff decides to award or
   3154    * increase the refund on an existing contract.  This function
   3155    * MUST be called from within a transaction scope setup by the
   3156    * caller as it executes multiple SQL statements.
   3157    *
   3158    * @param cls closure
   3159    * @param instance_id instance identifier
   3160    * @param order_id the order to increase the refund for
   3161    * @param refund maximum refund to return to the customer for this contract
   3162    * @param olc function to call to obtain legal refund
   3163    *    limits per exchange, NULL for no limits
   3164    * @param olc_cls closure for @a olc
   3165    * @param reason 0-terminated UTF-8 string giving the reason why the customer
   3166    *               got a refund (free form, business-specific)
   3167    * @return transaction status
   3168    *        #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a refund is ABOVE the amount we
   3169    *        were originally paid and thus the transaction failed;
   3170    *        #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the request is valid,
   3171    *        regardless of whether it actually increased the refund beyond
   3172    *        what was already refunded (idempotency!)
   3173    */
   3174   enum TALER_MERCHANTDB_RefundStatus
   3175     (*increase_refund)(
   3176     void *cls,
   3177     const char *instance_id,
   3178     const char *order_id,
   3179     const struct TALER_Amount *refund,
   3180     TALER_MERCHANTDB_OperationLimitCallback olc,
   3181     void *olc_cls,
   3182     const char *reason);
   3183 
   3184 
   3185   /**
   3186    * Obtain detailed refund data associated with a contract.
   3187    *
   3188    * @param cls closure, typically a connection to the db
   3189    * @param instance_id instance to lookup refunds for
   3190    * @param h_contract_terms hash code of the contract
   3191    * @param rc function to call for each coin on which there is a refund
   3192    * @param rc_cls closure for @a rc
   3193    * @return transaction status
   3194    */
   3195   enum GNUNET_DB_QueryStatus
   3196     (*lookup_refunds_detailed)(
   3197     void *cls,
   3198     const char *instance_id,
   3199     const struct TALER_PrivateContractHashP *h_contract_terms,
   3200     TALER_MERCHANTDB_RefundDetailCallback rc,
   3201     void *rc_cls);
   3202 
   3203   /**
   3204    * Insert refund proof data from the exchange into the database.
   3205    *
   3206    * @param cls closure
   3207    * @param refund_serial serial number of the refund
   3208    * @param exchange_sig signature from exchange that coin was refunded
   3209    * @param exchange_pub signing key that was used for @a exchange_sig
   3210    * @return transaction status
   3211    */
   3212   enum GNUNET_DB_QueryStatus
   3213     (*insert_refund_proof)(
   3214     void *cls,
   3215     uint64_t refund_serial,
   3216     const struct TALER_ExchangeSignatureP *exchange_sig,
   3217     const struct TALER_ExchangePublicKeyP *exchange_pub);
   3218 
   3219 
   3220   /**
   3221    * Insert used token into the database.
   3222    *
   3223    * @param cls closure
   3224    * @param h_contract_terms hash of the contract the token was used for
   3225    * @param h_issue_pub hash of the token issue public key
   3226    * @param use_pub token use public key
   3227    * @param use_sig token use signature
   3228    * @param issue_sig token issue signature
   3229    * @return database result code
   3230    */
   3231   enum GNUNET_DB_QueryStatus
   3232     (*insert_spent_token)(
   3233     void *cls,
   3234     const struct TALER_PrivateContractHashP *
   3235     h_contract_terms,
   3236     const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub,
   3237     const struct TALER_TokenUsePublicKeyP *use_pub,
   3238     const struct TALER_TokenUseSignatureP *use_sig,
   3239     const struct TALER_TokenIssueSignature *issue_sig);
   3240 
   3241 
   3242   /**
   3243    * Insert issued token into the database.
   3244    *
   3245    * @param cls closure
   3246    * @param h_contract_terms hash of the contract the token was issued for
   3247    * @param h_issue_pub hash of the token issue public key used to sign the issued token
   3248    * @param blind_sig resulting blind token issue signature
   3249    * @return database result code
   3250    */
   3251   enum GNUNET_DB_QueryStatus
   3252     (*insert_issued_token)(
   3253     void *cls,
   3254     const struct TALER_PrivateContractHashP *h_contract_terms,
   3255     const struct TALER_TokenIssuePublicKeyHashP *h_issue_pub,
   3256     const struct TALER_BlindedTokenIssueSignature *blind_sig);
   3257 
   3258 
   3259   /**
   3260    * Lookup refund proof data.
   3261    *
   3262    * @param cls closure
   3263    * @param refund_serial serial number of the refund
   3264    * @param[out] exchange_sig set to signature from exchange
   3265    * @param[out] exchange_pub signing key that was used for @a exchange_sig
   3266    * @return transaction status
   3267    */
   3268   enum GNUNET_DB_QueryStatus
   3269     (*lookup_refund_proof)(
   3270     void *cls,
   3271     uint64_t refund_serial,
   3272     struct TALER_ExchangeSignatureP *exchange_sig,
   3273     struct TALER_ExchangePublicKeyP *exchange_pub);
   3274 
   3275 
   3276   /**
   3277    * Retrieve the order ID that was used to pay for a resource within a session.
   3278    *
   3279    * @param cls closure
   3280    * @param instance_id instance to lookup the order from
   3281    * @param fulfillment_url URL that canonically identifies the resource
   3282    *        being paid for
   3283    * @param session_id session id
   3284    * @param allow_refunded_for_repurchase true to include refunded orders in repurchase detection
   3285    * @param[out] order_id location to store the order ID that was used when
   3286    *             paying for the resource URL
   3287    * @return transaction status
   3288    */
   3289   enum GNUNET_DB_QueryStatus
   3290     (*lookup_order_by_fulfillment)(
   3291     void *cls,
   3292     const char *instance_id,
   3293     const char *fulfillment_url,
   3294     const char *session_id,
   3295     bool allow_refunded_for_repurchase,
   3296     char **order_id);
   3297 
   3298   /**
   3299    * Update information about progress made by taler-merchant-wirewatch.
   3300    *
   3301    * @param cls closure
   3302    * @param instance which instance does the account belong to
   3303    * @param payto_uri which account is this about
   3304    * @param last_serial last serial imported from the bank
   3305    * @return transaction status
   3306    */
   3307   enum GNUNET_DB_QueryStatus
   3308     (*update_wirewatch_progress)(
   3309     void *cls,
   3310     const char *instance,
   3311     struct TALER_FullPayto payto_uri,
   3312     uint64_t last_serial);
   3313 
   3314 
   3315   /**
   3316    * Select information about accounts which taler-merchant-wirewatch should work on.
   3317    *
   3318    * @param cls closure
   3319    * @param cb function to call with results
   3320    * @param cb_cls closure for @a cb
   3321    * @return transaction status
   3322    */
   3323   enum GNUNET_DB_QueryStatus
   3324     (*select_wirewatch_accounts)(
   3325     void *cls,
   3326     TALER_MERCHANTDB_WirewatchWorkCallback cb,
   3327     void *cb_cls);
   3328 
   3329 
   3330   /**
   3331    * Insert information about a wire transfer the merchant has received.
   3332    *
   3333    * @param cls closure
   3334    * @param instance_id instance to lookup the order from
   3335    * @param exchange_url which exchange made the transfer
   3336    * @param wtid identifier of the wire transfer
   3337    * @param credit_amount how much did we receive
   3338    * @param payto_uri what is the merchant's bank account that received the transfer
   3339    * @param bank_serial_id bank serial transfer ID, 0 for none (use NULL in DB!)
   3340    * @return transaction status
   3341    */
   3342   enum GNUNET_DB_QueryStatus
   3343     (*insert_transfer)(
   3344     void *cls,
   3345     const char *instance_id,
   3346     const char *exchange_url,
   3347     const struct TALER_WireTransferIdentifierRawP *wtid,
   3348     const struct TALER_Amount *credit_amount,
   3349     struct TALER_FullPayto payto_uri,
   3350     uint64_t bank_serial_id);
   3351 
   3352 
   3353   /**
   3354    * Delete information about a transfer. Note that transfers
   3355    * confirmed by the exchange cannot be deleted anymore.
   3356    *
   3357    * @param cls closure
   3358    * @param instance_id instance to delete transfer of
   3359    * @param transfer_serial_id transfer to delete
   3360    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
   3361    *           if deletion is prohibited OR transfer is unknown
   3362    */
   3363   enum GNUNET_DB_QueryStatus
   3364     (*delete_transfer)(void *cls,
   3365                        const char *instance_id,
   3366                        uint64_t transfer_serial_id);
   3367 
   3368 
   3369   /**
   3370    * Check if information about a transfer exists with the
   3371    * backend.  Returns no data, only the query status.
   3372    *
   3373    * @param cls closure
   3374    * @param instance_id instance to delete transfer of
   3375    * @param transfer_serial_id transfer to delete
   3376    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
   3377    *           if the transfer record exists
   3378    */
   3379   enum GNUNET_DB_QueryStatus
   3380     (*check_transfer_exists)(void *cls,
   3381                              const char *instance_id,
   3382                              uint64_t transfer_serial_id);
   3383 
   3384 
   3385   /**
   3386    * Lookup account serial by payto URI.
   3387    *
   3388    * @param cls closure
   3389    * @param instance_id instance to lookup the account from
   3390    * @param payto_uri what is the merchant's bank account to lookup
   3391    * @param[out] account_serial serial number of the account
   3392    * @return transaction status
   3393    */
   3394   enum GNUNET_DB_QueryStatus
   3395     (*lookup_account)(void *cls,
   3396                       const char *instance_id,
   3397                       struct TALER_FullPayto payto_uri,
   3398                       uint64_t *account_serial);
   3399 
   3400 
   3401   /**
   3402    * Insert information about a wire transfer the merchant has received.
   3403    *
   3404    * @param cls closure
   3405    * @param instance_id instance to provide transfer details for
   3406    * @param exchange_url which exchange made the transfer
   3407    * @param payto_uri what is the merchant's bank account that received the transfer
   3408    * @param wtid identifier of the wire transfer
   3409    * @param td transfer details to store
   3410    * @return transaction status,
   3411    *   #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the @a wtid and @a exchange_uri are not known for this @a instance_id
   3412    *   #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT on success
   3413    */
   3414   enum GNUNET_DB_QueryStatus
   3415     (*insert_transfer_details)(
   3416     void *cls,
   3417     const char *instance_id,
   3418     const char *exchange_url,
   3419     struct TALER_FullPayto payto_uri,
   3420     const struct TALER_WireTransferIdentifierRawP *wtid,
   3421     const struct TALER_EXCHANGE_TransferData *td);
   3422 
   3423 
   3424   /**
   3425    * Obtain information about wire fees charged by an exchange,
   3426    * including signature (so we have proof).
   3427    *
   3428    * @param cls closure
   3429    * @param master_pub master public key of the exchange
   3430    * @param h_wire_method hash of wire method
   3431    * @param contract_date date of the contract to use for the lookup
   3432    * @param[out] fees set to wire fees charged
   3433    * @param[out] start_date start of fee being used
   3434    * @param[out] end_date end of fee being used
   3435    * @param[out] master_sig signature of exchange over fee structure
   3436    * @return transaction status code
   3437    */
   3438   enum GNUNET_DB_QueryStatus
   3439     (*lookup_wire_fee)(
   3440     void *cls,
   3441     const struct TALER_MasterPublicKeyP *master_pub,
   3442     const char *wire_method,
   3443     struct GNUNET_TIME_Timestamp contract_date,
   3444     struct TALER_WireFeeSet *fees,
   3445     struct GNUNET_TIME_Timestamp *start_date,
   3446     struct GNUNET_TIME_Timestamp *end_date,
   3447     struct TALER_MasterSignatureP *master_sig);
   3448 
   3449 
   3450   /**
   3451    * Lookup information about coin payments by @a h_contract_terms and
   3452    * @a coin_pub.
   3453    *
   3454    * @param cls closure
   3455    * @param instance_id instance to lookup payments for
   3456    * @param h_contract_terms proposal data's hashcode
   3457    * @param coin_pub public key to use for the search
   3458    * @param cb function to call with payment data
   3459    * @param cb_cls closure for @a cb
   3460    * @return transaction status
   3461    */
   3462   enum GNUNET_DB_QueryStatus
   3463     (*lookup_deposits_by_contract_and_coin)(
   3464     void *cls,
   3465     const char *instance_id,
   3466     const struct TALER_PrivateContractHashP *h_contract_terms,
   3467     const struct TALER_CoinSpendPublicKeyP *coin_pub,
   3468     TALER_MERCHANTDB_CoinDepositCallback cb,
   3469     void *cb_cls);
   3470 
   3471 
   3472   /**
   3473    * Lookup transfer summary (used if we already verified the details).
   3474    *
   3475    * @param cls closure
   3476    * @param exchange_url the exchange that made the transfer
   3477    * @param wtid wire transfer subject
   3478    * @param cb function to call with detailed transfer data
   3479    * @param cb_cls closure for @a cb
   3480    * @return transaction status
   3481    */
   3482   enum GNUNET_DB_QueryStatus
   3483     (*lookup_transfer_summary)(
   3484     void *cls,
   3485     const char *exchange_url,
   3486     const struct TALER_WireTransferIdentifierRawP *wtid,
   3487     TALER_MERCHANTDB_TransferSummaryCallback cb,
   3488     void *cb_cls);
   3489 
   3490 
   3491   /**
   3492    * Lookup transfer details. Used if we still need to verify the details.
   3493    *
   3494    * @param cls closure
   3495    * @param exchange_url the exchange that made the transfer
   3496    * @param wtid wire transfer subject
   3497    * @param cb function to call with detailed transfer data
   3498    * @param cb_cls closure for @a cb
   3499    * @return transaction status
   3500    */
   3501   enum GNUNET_DB_QueryStatus
   3502     (*lookup_transfer_details)(
   3503     void *cls,
   3504     const char *exchange_url,
   3505     const struct TALER_WireTransferIdentifierRawP *wtid,
   3506     TALER_MERCHANTDB_TransferDetailsCallback cb,
   3507     void *cb_cls);
   3508 
   3509 
   3510   /**
   3511    * Lookup transfers.
   3512    *
   3513    * @param cls closure
   3514    * @param instance_id instance to lookup payments for
   3515    * @param payto_uri account that we are interested in transfers to
   3516    * @param before timestamp for the earliest transfer we care about
   3517    * @param after timestamp for the last transfer we care about
   3518    * @param limit number of entries to return, negative for descending in execution time,
   3519    *                positive for ascending in execution time
   3520    * @param offset transfer_serial number of the transfer we want to offset from
   3521    * @param expected filter for transfers that were expected
   3522    * @param cb function to call with detailed transfer data
   3523    * @param cb_cls closure for @a cb
   3524    * @return transaction status
   3525    */
   3526   enum GNUNET_DB_QueryStatus
   3527     (*lookup_transfers)(
   3528     void *cls,
   3529     const char *instance_id,
   3530     struct TALER_FullPayto payto_uri,
   3531     struct GNUNET_TIME_Timestamp before,
   3532     struct GNUNET_TIME_Timestamp after,
   3533     int64_t limit,
   3534     uint64_t offset,
   3535     enum TALER_EXCHANGE_YesNoAll expected,
   3536     TALER_MERCHANTDB_TransferCallback cb,
   3537     void *cb_cls);
   3538 
   3539 
   3540   /**
   3541    * Lookup expected incoming transfers.
   3542    *
   3543    * @param cls closure
   3544    * @param instance_id instance to lookup payments for
   3545    * @param payto_uri account that we are interested in transfers to
   3546    * @param before timestamp for the earliest transfer we care about
   3547    * @param after timestamp for the last transfer we care about
   3548    * @param limit number of entries to return, negative for descending in execution time,
   3549    *                positive for ascending in execution time
   3550    * @param offset expected_transfer_serial number of the transfer we want to offset from
   3551    * @param confirmed filter by confirmation status
   3552    * @param verified filter by verification status
   3553    * @param cb function to call with detailed transfer data
   3554    * @param cb_cls closure for @a cb
   3555    * @return transaction status
   3556    */
   3557   enum GNUNET_DB_QueryStatus
   3558     (*lookup_expected_transfers)(
   3559     void *cls,
   3560     const char *instance_id,
   3561     struct TALER_FullPayto payto_uri,
   3562     struct GNUNET_TIME_Timestamp before,
   3563     struct GNUNET_TIME_Timestamp after,
   3564     int64_t limit,
   3565     uint64_t offset,
   3566     enum TALER_EXCHANGE_YesNoAll confirmed,
   3567     enum TALER_EXCHANGE_YesNoAll verified,
   3568     TALER_MERCHANTDB_IncomingCallback cb,
   3569     void *cb_cls);
   3570 
   3571 
   3572   /**
   3573    * Store information about wire fees charged by an exchange,
   3574    * including signature (so we have proof).
   3575    *
   3576    * @param cls closure
   3577    * @param master_pub master public key of the exchange
   3578    * @param h_wire_method hash of wire method
   3579    * @param fees wire fees charged
   3580    * @param start_date start of fee being used
   3581    * @param end_date end of fee being used
   3582    * @param master_sig signature of exchange over fee structure
   3583    * @return transaction status code
   3584    */
   3585   enum GNUNET_DB_QueryStatus
   3586     (*store_wire_fee_by_exchange)(
   3587     void *cls,
   3588     const struct TALER_MasterPublicKeyP *master_pub,
   3589     const struct GNUNET_HashCode *h_wire_method,
   3590     const struct TALER_WireFeeSet *fees,
   3591     struct GNUNET_TIME_Timestamp start_date,
   3592     struct GNUNET_TIME_Timestamp end_date,
   3593     const struct TALER_MasterSignatureP *master_sig);
   3594 
   3595 
   3596   /**
   3597    * Delete information about wire accounts of an exchange. (Used when we got new account data.)
   3598    *
   3599    * @param cls closure
   3600    * @param master_pub public key of the exchange
   3601    * @return transaction status code
   3602    */
   3603   enum GNUNET_DB_QueryStatus
   3604     (*delete_exchange_accounts)(
   3605     void *cls,
   3606     const struct TALER_MasterPublicKeyP *master_pub);
   3607 
   3608 
   3609   /**
   3610    * Return information about wire accounts of an exchange.
   3611    *
   3612    * @param cls closure
   3613    * @param master_pub public key of the exchange
   3614    * @param cb function to call on each account
   3615    * @param cb_cls closure for @a cb
   3616    * @return transaction status code
   3617    */
   3618   enum GNUNET_DB_QueryStatus
   3619     (*select_accounts_by_exchange)(
   3620     void *cls,
   3621     const struct TALER_MasterPublicKeyP *master_pub,
   3622     TALER_MERCHANTDB_ExchangeAccountCallback cb,
   3623     void *cb_cls);
   3624 
   3625 
   3626   /**
   3627    * Insert information about a wire account of an exchange.
   3628    *
   3629    * @param cls closure
   3630    * @param master_pub public key of the exchange
   3631    * @param payto_uri URI of the bank account
   3632    * @param conversion_url conversion service, NULL if there is no conversion required
   3633    * @param debit_restrictions JSON array of debit restrictions on the account
   3634    * @param credit_restrictions JSON array of debit restrictions on the account
   3635    * @param master_sig signature affirming the account of the exchange
   3636    * @return transaction status code
   3637    */
   3638   enum GNUNET_DB_QueryStatus
   3639     (*insert_exchange_account)(
   3640     void *cls,
   3641     const struct TALER_MasterPublicKeyP *master_pub,
   3642     const struct TALER_FullPayto payto_uri,
   3643     const char *conversion_url,
   3644     const json_t *debit_restrictions,
   3645     const json_t *credit_restrictions,
   3646     const struct TALER_MasterSignatureP *master_sig);
   3647 
   3648 
   3649   /**
   3650    * Lookup all of the templates the given instance has configured.
   3651    *
   3652    * @param cls closure
   3653    * @param instance_id instance to lookup template for
   3654    * @param cb function to call on all template found
   3655    * @param cb_cls closure for @a cb
   3656    * @return database result code
   3657    */
   3658   enum GNUNET_DB_QueryStatus
   3659     (*lookup_templates)(void *cls,
   3660                         const char *instance_id,
   3661                         TALER_MERCHANTDB_TemplatesCallback cb,
   3662                         void *cb_cls);
   3663 
   3664 
   3665   /**
   3666    * Lookup details about a particular template.
   3667    *
   3668    * @param cls closure
   3669    * @param instance_id instance to lookup template for
   3670    * @param template_id template to lookup
   3671    * @param[out] td set to the template details on success, can be NULL
   3672    *             (in that case we only want to check if the template exists)
   3673    * @return database result code
   3674    */
   3675   enum GNUNET_DB_QueryStatus
   3676     (*lookup_template)(void *cls,
   3677                        const char *instance_id,
   3678                        const char *template_id,
   3679                        struct TALER_MERCHANTDB_TemplateDetails *td);
   3680 
   3681   /**
   3682    * Delete information about a template.
   3683    *
   3684    * @param cls closure
   3685    * @param instance_id instance to delete template of
   3686    * @param template_id template to delete
   3687    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
   3688    *           if template unknown.
   3689    */
   3690   enum GNUNET_DB_QueryStatus
   3691     (*delete_template)(void *cls,
   3692                        const char *instance_id,
   3693                        const char *template_id);
   3694 
   3695 
   3696   /**
   3697    * Insert details about a particular template.
   3698    *
   3699    * @param cls closure
   3700    * @param instance_id instance to insert template for
   3701    * @param template_id template identifier of template to insert
   3702    * @param otp_serial_id 0 if no OTP device is associated
   3703    * @param td the template details to insert
   3704    * @return database result code
   3705    */
   3706   enum GNUNET_DB_QueryStatus
   3707     (*insert_template)(void *cls,
   3708                        const char *instance_id,
   3709                        const char *template_id,
   3710                        uint64_t otp_serial_id,
   3711                        const struct TALER_MERCHANTDB_TemplateDetails *td);
   3712 
   3713 
   3714   /**
   3715    * Update details about a particular template.
   3716    *
   3717    * @param cls closure
   3718    * @param instance_id instance to update template for
   3719    * @param template_id template to update
   3720    * @param td update to the template details on success, can be NULL
   3721    *             (in that case we only want to check if the template exists)
   3722    * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
   3723    *         does not yet exist.
   3724    */
   3725   enum GNUNET_DB_QueryStatus
   3726     (*update_template)(void *cls,
   3727                        const char *instance_id,
   3728                        const char *template_id,
   3729                        const struct TALER_MERCHANTDB_TemplateDetails *td);
   3730 
   3731 
   3732   /**
   3733    * Delete information about an OTP device.
   3734    *
   3735    * @param cls closure
   3736    * @param instance_id instance to delete OTP device of
   3737    * @param otp_id otp device to delete
   3738    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
   3739    *           if template unknown.
   3740    */
   3741   enum GNUNET_DB_QueryStatus
   3742     (*delete_otp)(void *cls,
   3743                   const char *instance_id,
   3744                   const char *otp_id);
   3745 
   3746   /**
   3747    * Insert details about a particular OTP device.
   3748    *
   3749    * @param cls closure
   3750    * @param instance_id instance to insert OTP device for
   3751    * @param otp_id otp identifier of OTP device to insert
   3752    * @param td the OTP device details to insert
   3753    * @return database result code
   3754    */
   3755   enum GNUNET_DB_QueryStatus
   3756     (*insert_otp)(void *cls,
   3757                   const char *instance_id,
   3758                   const char *otp_id,
   3759                   const struct TALER_MERCHANTDB_OtpDeviceDetails *td);
   3760 
   3761 
   3762   /**
   3763    * Update details about a particular OTP device.
   3764    *
   3765    * @param cls closure
   3766    * @param instance_id instance to update OTP device for
   3767    * @param otp_id OTP device to update
   3768    * @param td update to the OTP device details on success, can be NULL
   3769    *             (in that case we only want to check if the template exists)
   3770    * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
   3771    *         does not yet exist.
   3772    */
   3773   enum GNUNET_DB_QueryStatus
   3774     (*update_otp)(void *cls,
   3775                   const char *instance_id,
   3776                   const char *otp_id,
   3777                   const struct TALER_MERCHANTDB_OtpDeviceDetails *td);
   3778 
   3779   /**
   3780    * Lookup all of the OTP devices the given instance has configured.
   3781    *
   3782    * @param cls closure
   3783    * @param instance_id instance to lookup OTP devices for
   3784    * @param cb function to call on all OTP devices found
   3785    * @param cb_cls closure for @a cb
   3786    * @return database result code
   3787    */
   3788   enum GNUNET_DB_QueryStatus
   3789     (*lookup_otp_devices)(void *cls,
   3790                           const char *instance_id,
   3791                           TALER_MERCHANTDB_OtpDeviceCallback cb,
   3792                           void *cb_cls);
   3793 
   3794 
   3795   /**
   3796    * Lookup details about an OTP device.
   3797    *
   3798    * @param cls closure
   3799    * @param instance_id instance to lookup template for
   3800    * @param otp_id OTP device to lookup
   3801    * @param[out] td set to the OTP device details on success, can be NULL
   3802    *             (in that case we only want to check if the template exists)
   3803    * @return database result code
   3804    */
   3805   enum GNUNET_DB_QueryStatus
   3806     (*select_otp)(void *cls,
   3807                   const char *instance_id,
   3808                   const char *otp_id,
   3809                   struct TALER_MERCHANTDB_OtpDeviceDetails *td);
   3810 
   3811 
   3812   /**
   3813    * Lookup serial number of an OTP device.
   3814    *
   3815    * @param cls closure
   3816    * @param instance_id instance to lookup template for
   3817    * @param otp_id OTP device to lookup
   3818    * @param[out] serial set to the OTP device serial number   * @return database result code
   3819    */
   3820   enum GNUNET_DB_QueryStatus
   3821     (*select_otp_serial)(void *cls,
   3822                          const char *instance_id,
   3823                          const char *otp_id,
   3824                          uint64_t *serial);
   3825 
   3826   /**
   3827    * Delete information about a measurement unit.
   3828    *
   3829    * @param cls closure
   3830    * @param instance_id instance to delete unit from
   3831    * @param unit_id symbolic identifier of the unit
   3832    * @param[out] no_instance set to true if @a instance_id is unknown
   3833    * @param[out] no_unit set to true if the unit does not exist
   3834    * @param[out] builtin_conflict set to true if the unit is builtin and may not be deleted
   3835    * @return DB status code
   3836    */
   3837   enum GNUNET_DB_QueryStatus
   3838     (*delete_unit)(void *cls,
   3839                    const char *instance_id,
   3840                    const char *unit_id,
   3841                    bool *no_instance,
   3842                    bool *no_unit,
   3843                    bool *builtin_conflict);
   3844 
   3845   /**
   3846    * Insert a measurement unit definition.
   3847    *
   3848    * @param cls closure
   3849    * @param instance_id instance to insert unit for
   3850    * @param ud unit details to store (unit_serial ignored)
   3851    * @param[out] no_instance set to true if @a instance_id is unknown
   3852    * @param[out] conflict set to true if a conflicting unit already exists
   3853    * @param[out] unit_serial set to the inserted serial on success
   3854    * @return database result code
   3855    */
   3856   enum GNUNET_DB_QueryStatus
   3857     (*insert_unit)(void *cls,
   3858                    const char *instance_id,
   3859                    const struct TALER_MERCHANTDB_UnitDetails *ud,
   3860                    bool *no_instance,
   3861                    bool *conflict,
   3862                    uint64_t *unit_serial);
   3863 
   3864   /**
   3865    * Update a measurement unit definition.
   3866    *
   3867    * @param cls closure
   3868    * @param instance_id instance owning the unit
   3869    * @param unit_id symbolic identifier of the unit
   3870    * @param unit_name_long optional new long label (NULL to keep current)
   3871    * @param unit_name_long_i18n optional new long-label translations (NULL to keep current)
   3872    * @param unit_name_short optional new short label (NULL to keep current)
   3873    * @param unit_name_short_i18n optional new short-label translations (NULL to keep current)
   3874    * @param unit_allow_fraction optional new fractional toggle (NULL to keep current)
   3875    * @param unit_precision_level optional new fractional precision (NULL to keep current)
   3876    * @param unit_active optional new visibility flag (NULL to keep current)
   3877    * @param[out] no_instance set if instance unknown
   3878    * @param[out] no_unit set if unit unknown
   3879    * @param[out] builtin_conflict set if immutable builtin fields touched
   3880    * @return database result code
   3881    */
   3882   enum GNUNET_DB_QueryStatus
   3883     (*update_unit)(void *cls,
   3884                    const char *instance_id,
   3885                    const char *unit_id,
   3886                    const char *unit_name_long,
   3887                    const json_t *unit_name_long_i18n,
   3888                    const char *unit_name_short,
   3889                    const json_t *unit_name_short_i18n,
   3890                    const bool *unit_allow_fraction,
   3891                    const uint32_t *unit_precision_level,
   3892                    const bool *unit_active,
   3893                    bool *no_instance,
   3894                    bool *no_unit,
   3895                    bool *builtin_conflict);
   3896 
   3897   /**
   3898    * Lookup all measurement units of an instance.
   3899    *
   3900    * @param cls closure
   3901    * @param instance_id instance to fetch units for
   3902    * @param cb function to call per unit
   3903    * @param cb_cls closure for @a cb
   3904    * @return database result code
   3905    */
   3906   enum GNUNET_DB_QueryStatus
   3907     (*lookup_units)(void *cls,
   3908                     const char *instance_id,
   3909                     TALER_MERCHANTDB_UnitsCallback cb,
   3910                     void *cb_cls);
   3911 
   3912   /**
   3913    * Lookup a single measurement unit.
   3914    *
   3915    * @param cls closure
   3916    * @param instance_id instance to fetch unit for
   3917    * @param unit_id symbolic identifier
   3918    * @param[out] ud unit details on success; may be NULL to test existence
   3919    * @return database result code
   3920    */
   3921   enum GNUNET_DB_QueryStatus
   3922     (*select_unit)(void *cls,
   3923                    const char *instance_id,
   3924                    const char *unit_id,
   3925                    struct TALER_MERCHANTDB_UnitDetails *ud);
   3926 
   3927 
   3928   /**
   3929    * Delete information about a product category.
   3930    *
   3931    * @param cls closure
   3932    * @param instance_id instance to delete category of
   3933    * @param category_id identifies the category to delete
   3934    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
   3935    *           if template unknown.
   3936    */
   3937   enum GNUNET_DB_QueryStatus
   3938     (*delete_category)(void *cls,
   3939                        const char *instance_id,
   3940                        uint64_t category_id);
   3941 
   3942   /**
   3943    * Insert new product category.
   3944    *
   3945    * @param cls closure
   3946    * @param instance_id instance to insert OTP device for
   3947    * @param category_name name of the category
   3948    * @param category_name_i18n translations of the category name
   3949    * @param[out] category_id set to the category id on success
   3950    * @return database result code
   3951    */
   3952   enum GNUNET_DB_QueryStatus
   3953     (*insert_category)(void *cls,
   3954                        const char *instance_id,
   3955                        const char *category_name,
   3956                        const json_t *category_name_i18n,
   3957                        uint64_t *category_id);
   3958 
   3959 
   3960   /**
   3961    * Update descriptions of a product category.
   3962    *
   3963    * @param cls closure
   3964    * @param instance_id instance to update OTP device for
   3965    * @param category_id category to update
   3966    * @param category_name name of the category
   3967    * @param category_name_i18n translations of the category name
   3968    * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
   3969    *         does not yet exist.
   3970    */
   3971   enum GNUNET_DB_QueryStatus
   3972     (*update_category)(void *cls,
   3973                        const char *instance_id,
   3974                        uint64_t category_id,
   3975                        const char *category_name,
   3976                        const json_t *category_name_i18n);
   3977 
   3978   /**
   3979    * Lookup all of the product categories the given instance has configured.
   3980    *
   3981    * @param cls closure
   3982    * @param instance_id instance to lookup OTP devices for
   3983    * @param cb function to call on all categories found
   3984    * @param cb_cls closure for @a cb
   3985    * @return database result code
   3986    */
   3987   enum GNUNET_DB_QueryStatus
   3988     (*lookup_categories)(void *cls,
   3989                          const char *instance_id,
   3990                          TALER_MERCHANTDB_CategoriesCallback cb,
   3991                          void *cb_cls);
   3992 
   3993 
   3994   /**
   3995    * Lookup details about product category.
   3996    *
   3997    * @param cls closure
   3998    * @param instance_id instance to lookup template for
   3999    * @param category_id category to update
   4000    * @param[out] cd set to the category details on success, can be NULL
   4001    *             (in that case we only want to check if the category exists)
   4002    * @param[out] num_products set to length of @a products array
   4003    * @param[out] products set to buffer with @a num_products 0-terminated strings with the product IDs, caller must free() it.
   4004    * @return database result code
   4005    */
   4006   enum GNUNET_DB_QueryStatus
   4007     (*select_category)(void *cls,
   4008                        const char *instance_id,
   4009                        uint64_t category_id,
   4010                        struct TALER_MERCHANTDB_CategoryDetails *cd,
   4011                        size_t *num_products,
   4012                        char **products);
   4013 
   4014 
   4015   /**
   4016    * Lookup details about product category by name.
   4017    *
   4018    * @param cls closure
   4019    * @param instance_id instance to lookup template for
   4020    * @param category_name category name to look for
   4021    * @param[out] name_i18n category name translation
   4022    * @param[out] category_id category ID
   4023    * @return database result code
   4024    */
   4025   enum GNUNET_DB_QueryStatus
   4026     (*select_category_by_name)(void *cls,
   4027                                const char *instance_id,
   4028                                const char *category_name,
   4029                                json_t **name_i18n,
   4030                                uint64_t *category_id);
   4031 
   4032 
   4033   /**
   4034    * Lookup all of the webhooks the given instance has configured.
   4035    *
   4036    * @param cls closure
   4037    * @param instance_id instance to lookup webhook for
   4038    * @param cb function to call on all webhook found
   4039    * @param cb_cls closure for @a cb
   4040    * @return database result code
   4041    */
   4042   enum GNUNET_DB_QueryStatus
   4043     (*lookup_webhooks)(void *cls,
   4044                        const char *instance_id,
   4045                        TALER_MERCHANTDB_WebhooksCallback cb,
   4046                        void *cb_cls);
   4047 
   4048 
   4049   /**
   4050    * Lookup details about a particular webhook.
   4051    *
   4052    * @param cls closure
   4053    * @param instance_id instance to lookup webhook for
   4054    * @param webhook_id webhook to lookup
   4055    * @param[out] wb set to the webhook details on success, can be NULL
   4056    *             (in that case we only want to check if the webhook exists)
   4057    * @return database result code
   4058    */
   4059   enum GNUNET_DB_QueryStatus
   4060     (*lookup_webhook)(void *cls,
   4061                       const char *instance_id,
   4062                       const char *webhook_id,
   4063                       struct TALER_MERCHANTDB_WebhookDetails *wb);
   4064 
   4065   /**
   4066    * Delete information about a webhook.
   4067    *
   4068    * @param cls closure
   4069    * @param instance_id instance to delete webhook of
   4070    * @param webhook_id webhook to delete
   4071    * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
   4072    *           if webhook unknown.
   4073    */
   4074   enum GNUNET_DB_QueryStatus
   4075     (*delete_webhook)(void *cls,
   4076                       const char *instance_id,
   4077                       const char *webhook_id);
   4078 
   4079 
   4080   /**
   4081    * Insert details about a particular webhook.
   4082    *
   4083    * @param cls closure
   4084    * @param instance_id instance to insert webhook for
   4085    * @param webhook_id webhook identifier of webhook to insert
   4086    * @param wb the webhook details to insert
   4087    * @return database result code
   4088    */
   4089   enum GNUNET_DB_QueryStatus
   4090     (*insert_webhook)(void *cls,
   4091                       const char *instance_id,
   4092                       const char *webhook_id,
   4093                       const struct TALER_MERCHANTDB_WebhookDetails *wb);
   4094 
   4095 
   4096   /**
   4097    * Update details about a particular webhook.
   4098    *
   4099    * @param cls closure
   4100    * @param instance_id instance to update webhook for
   4101    * @param webhook_id webhook to update
   4102    * @param wb update to the webhook details on success, can be NULL
   4103    *             (in that case we only want to check if the webhook exists)
   4104    * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the webhook
   4105    *         does not yet exist.
   4106    */
   4107   enum GNUNET_DB_QueryStatus
   4108     (*update_webhook)(void *cls,
   4109                       const char *instance_id,
   4110                       const char *webhook_id,
   4111                       const struct TALER_MERCHANTDB_WebhookDetails *wb);
   4112 
   4113   /**
   4114    * Lookup webhook by event
   4115    *
   4116    * @param cls closure
   4117    * @param instance_id instance to lookup webhook for
   4118    * @param event_type event that we need to put in the pending webhook
   4119    * @param[out] cb set to the webhook details on success
   4120    * @param cb_cls callback closure
   4121    * @return database result code
   4122    */
   4123   enum GNUNET_DB_QueryStatus
   4124     (*lookup_webhook_by_event)(void *cls,
   4125                                const char *instance_id,
   4126                                const char *event_type,
   4127                                TALER_MERCHANTDB_WebhookDetailCallback cb,
   4128                                void *cb_cls);
   4129 
   4130   /**
   4131    * Insert webhook in the pending webhook.
   4132    *
   4133    * @param cls closure
   4134    * @param instance_id instance to insert webhook for
   4135    * @param webhook_serial webhook to insert in the pending webhook
   4136    * @param url to make the request to
   4137    * @param http_method for the webhook
   4138    * @param header of the webhook
   4139    * @param body of the webhook
   4140    * @return database result code
   4141    */
   4142   enum GNUNET_DB_QueryStatus
   4143     (*insert_pending_webhook)(void *cls,
   4144                               const char *instance_id,
   4145                               uint64_t webhook_serial,
   4146                               const char *url,
   4147                               const char *http_method,
   4148                               const char *header,
   4149                               const char *body);
   4150   /**
   4151    * Lookup the webhook that need to be send in priority. These webhooks are not successfully
   4152    * send.
   4153    *
   4154    * @param cls closure
   4155    * @param cb pending webhook callback
   4156    * @param cb_cls callback closure
   4157    */
   4158   // WHERE next_attempt <= now ORDER BY next_attempt ASC
   4159   enum GNUNET_DB_QueryStatus
   4160     (*lookup_pending_webhooks)(void *cls,
   4161                                TALER_MERCHANTDB_PendingWebhooksCallback cb,
   4162                                void *cb_cls);
   4163 
   4164   /**
   4165    * Lookup future webhook in the pending webhook that need to be send.
   4166    * With that we can know how long the system can 'sleep'.
   4167    *
   4168    * @param cls closure
   4169    * @param cb pending webhook callback
   4170    * @param cb_cls callback closure
   4171    */
   4172   // ORDER BY next_attempt ASC LIMIT 1
   4173   enum GNUNET_DB_QueryStatus
   4174     (*lookup_future_webhook)(void *cls,
   4175                              TALER_MERCHANTDB_PendingWebhooksCallback cb,
   4176                              void *cb_cls);
   4177 
   4178   /**
   4179    * Lookup all the webhooks in the pending webhook.
   4180    * Use by the administrator
   4181    *
   4182    * @param cls closure
   4183    * @param instance_id to lookup webhooks for this instance particularly
   4184    * @param min_row to see the list of the pending webhook that it is started with this minimum row.
   4185    * @param max_results to see the list of the pending webhook that it is end with this max results.
   4186    * @param cb pending webhook callback
   4187    * @param cb_cls callback closure
   4188    */
   4189   // WHERE webhook_pending_serial > min_row ORDER BY webhook_pending_serial ASC LIMIT max_results
   4190   enum GNUNET_DB_QueryStatus
   4191     (*lookup_all_webhooks)(void *cls,
   4192                            const char *instance_id,
   4193                            uint64_t min_row,
   4194                            uint32_t max_results,
   4195                            TALER_MERCHANTDB_PendingWebhooksCallback cb,
   4196                            void *cb_cls);
   4197 
   4198 
   4199   /**
   4200    * Update the pending webhook. It is use if the webhook can't be send.
   4201    *
   4202    * @param cls closure
   4203    * @param webhook_serial webhook that need to be update
   4204    * @param next_attempt when we should make the next request to the webhook
   4205    * @return database result code
   4206    */
   4207   enum GNUNET_DB_QueryStatus
   4208     (*update_pending_webhook)(void *cls,
   4209                               uint64_t webhook_pending_serial,
   4210                               struct GNUNET_TIME_Absolute next_attempt);
   4211   // maybe add: http status of failure?
   4212 
   4213 
   4214   /**
   4215    * Delete a webhook in the pending webhook after the
   4216    * webhook was completed successfully.
   4217    *
   4218    * @param cls closure
   4219    * @param webhook_serial webhook that need to be delete in the pending webhook
   4220    * @return database result code
   4221    */
   4222   enum GNUNET_DB_QueryStatus
   4223     (*delete_pending_webhook)(void *cls,
   4224                               uint64_t webhook_pending_serial);
   4225 
   4226 
   4227   /**
   4228    * Retrieve exchange's keys from the database.
   4229    *
   4230    * @param cls plugin closure
   4231    * @param exchange_url base URL of the exchange
   4232    * @param[out] first_retry set to earliest we may retry fetching the keys
   4233    * @param[out] keys set to the keys of the exchange
   4234    * @return transaction status
   4235    */
   4236   enum GNUNET_DB_QueryStatus
   4237     (*select_exchange_keys)(void *cls,
   4238                             const char *exchange_url,
   4239                             struct GNUNET_TIME_Absolute *first_retry,
   4240                             struct TALER_EXCHANGE_Keys **keys);
   4241 
   4242 
   4243   /**
   4244    * Insert or update @a keys into the database.
   4245    *
   4246    * @param cls plugin closure
   4247    * @param keys data to store
   4248    * @param first_retry earliest we may retry fetching the keys
   4249    * @return transaction status
   4250    */
   4251   enum GNUNET_DB_QueryStatus
   4252     (*insert_exchange_keys)(void *cls,
   4253                             const struct TALER_EXCHANGE_Keys *keys,
   4254                             struct GNUNET_TIME_Absolute first_retry);
   4255 
   4256 
   4257   /**
   4258    * Lookup all of the token families the given instance has configured.
   4259    *
   4260    * @param cls closure
   4261    * @param instance_id instance to lookup token families for
   4262    * @param cb function to call on all token families found
   4263    * @param cb_cls closure for @a cb
   4264    * @return database result code
   4265    */
   4266   enum GNUNET_DB_QueryStatus
   4267     (*lookup_token_families)(void *cls,
   4268                              const char *instance_id,
   4269                              TALER_MERCHANTDB_TokenFamiliesCallback cb,
   4270                              void *cb_cls);
   4271 
   4272   /**
   4273    * Lookup details about a particular token family.
   4274    *
   4275    * @param cls closure
   4276    * @param instance_id instance to lookup token family for
   4277    * @param token_family_slug token family to lookup
   4278    * @param[out] details set to the token family details on success, can be NULL
   4279    *             (in that case we only want to check if the token family exists)
   4280    * @return database result code
   4281    */
   4282   enum GNUNET_DB_QueryStatus
   4283     (*lookup_token_family)(void *cls,
   4284                            const char *instance_id,
   4285                            const char *token_family_slug,
   4286                            struct TALER_MERCHANTDB_TokenFamilyDetails *details);
   4287 
   4288   /**
   4289    * Delete information about a token family.
   4290    *
   4291    * @param cls closure
   4292    * @param instance_id instance to delete token family of
   4293    * @param token_family_slug slug of token family to delete
   4294    * @return database result code
   4295    */
   4296   enum GNUNET_DB_QueryStatus
   4297     (*delete_token_family)(void *cls,
   4298                            const char *instance_id,
   4299                            const char *token_family_slug);
   4300 
   4301   /**
   4302    * Update details about a particular token family.
   4303    *
   4304    * @param cls closure
   4305    * @param instance_id instance to update token family for
   4306    * @param token_family_slug slug of token family to update
   4307    * @param details set to the updated token family on success, can be NULL
   4308    *        (in that case we only want to check if the token family exists)
   4309    * @return database result code
   4310    */
   4311   enum GNUNET_DB_QueryStatus
   4312     (*update_token_family)(
   4313     void *cls,
   4314     const char *instance_id,
   4315     const char *token_family_slug,
   4316     const struct TALER_MERCHANTDB_TokenFamilyDetails *details);
   4317 
   4318 
   4319   /**
   4320    * Insert details about a particular token family.
   4321    *
   4322    * @param cls closure
   4323    * @param instance_id instance to insert token family for
   4324    * @param token_family_slug slug of token family to insert
   4325    * @param details the token family details to insert
   4326    * @return database result code
   4327    */
   4328   enum GNUNET_DB_QueryStatus
   4329     (*insert_token_family)(
   4330     void *cls,
   4331     const char *instance_id,
   4332     const char *token_family_slug,
   4333     const struct TALER_MERCHANTDB_TokenFamilyDetails *details);
   4334 
   4335 
   4336   /**
   4337   * Lookup details about a particular token family key.
   4338   *
   4339   * @param cls closure
   4340   * @param instance_id instance to lookup token family key for
   4341   * @param token_family_slug slug of token family to lookup
   4342   * @param valid_at find a key with a validity period that includes this time
   4343   * @param sign_until find a private key that can sign until this time
   4344   * @param[out] details set to the token family key details on success, can be NULL
   4345   *             (in that case we only want to check if the token family key exists)
   4346   * @return database result code
   4347   */
   4348   enum GNUNET_DB_QueryStatus
   4349     (*lookup_token_family_key)(
   4350     void *cls,
   4351     const char *instance_id,
   4352     const char *token_family_slug,
   4353     struct GNUNET_TIME_Timestamp valid_at,
   4354     struct GNUNET_TIME_Timestamp sign_until,
   4355     struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details);
   4356 
   4357 
   4358   /**
   4359    * Lookup token family keys that may be used for a payment.
   4360    *
   4361    * @param cls closure
   4362    * @param instance_id instance to lookup token family key for
   4363    * @param token_family_slug slug of token family to lookup
   4364    * @param start_time signature validity start the keys must fall into
   4365    * @param end_time signature validity end the keys must fall into
   4366    * @param cb function to call with each matching key
   4367    * @param cb_cls closure for @a cb
   4368    * @return database result code
   4369    */
   4370   enum GNUNET_DB_QueryStatus
   4371     (*lookup_token_family_keys)(
   4372     void *cls,
   4373     const char *instance_id,
   4374     const char *token_family_slug,
   4375     struct GNUNET_TIME_Timestamp start_time,
   4376     struct GNUNET_TIME_Timestamp end_time,
   4377     TALER_MERCHANTDB_TokenKeyCallback cb,
   4378     void *cb_cls);
   4379 
   4380 
   4381   /**
   4382    * Insert details a key pair for a token family.
   4383    *
   4384    * @param cls closure
   4385    * @param merchant_id instance name
   4386    * @param token_family_slug slug of token family to insert the key pair for
   4387    * @param pub token family public key
   4388    * @param priv token family private key
   4389    * @param key_expires when does the private key expire (because
   4390    *     the validity period of the next token family key starts)
   4391    * @param valid_after start of validity period for signatures with this key
   4392    * @param valid_before end of validity period for signatures with this key
   4393    * @return database result code
   4394    */
   4395   enum GNUNET_DB_QueryStatus
   4396     (*insert_token_family_key)(
   4397     void *cls,
   4398     const char *merchant_id,
   4399     const char *token_family_slug,
   4400     const struct TALER_TokenIssuePublicKey *pub,
   4401     const struct TALER_TokenIssuePrivateKey *priv,
   4402     struct GNUNET_TIME_Timestamp key_expires,
   4403     struct GNUNET_TIME_Timestamp valid_after,
   4404     struct GNUNET_TIME_Timestamp valid_before);
   4405 
   4406   /**
   4407    * Lookup deposits that are finished and awaiting a wire transfer.
   4408    *
   4409    * @param cls closure
   4410    * @param exchange_url exchange to filter deposits by
   4411    * @param limit maximum number of deposits to return
   4412    * @param allow_future true to allow deposits with wire deadline in the future
   4413    * @param cb function to call with deposit data
   4414    * @param cb_cls closure for @a cb
   4415    * @return transaction status
   4416    */
   4417   enum GNUNET_DB_QueryStatus
   4418     (*lookup_pending_deposits)(
   4419     void *cls,
   4420     const char *exchange_url,
   4421     uint64_t limit,
   4422     bool allow_future,
   4423     TALER_MERCHANTDB_PendingDepositsCallback cb,
   4424     void *cb_cls);
   4425 
   4426 
   4427   /**
   4428    * Update the deposit confirmation status associated with
   4429    * the given @a deposit_serial.
   4430    *
   4431    * @param cls closure
   4432    * @param deposit_serial deposit to update status for
   4433    * @param retry_needed true if the HTTP request should be retried
   4434    * @param retry_time when should we ask the exchange again
   4435    * @param last_http_status HTTP status code of the last reply
   4436    * @param last_ec Taler error code of the last reply
   4437    * @param last_detail detail from error message to record, possibly NULL
   4438    * @return database result code
   4439    */
   4440   enum GNUNET_DB_QueryStatus
   4441     (*update_deposit_confirmation_status)(
   4442     void *cls,
   4443     uint64_t deposit_serial,
   4444     bool retry_needed,
   4445     struct GNUNET_TIME_Timestamp retry_time,
   4446     uint32_t last_http_status,
   4447     enum TALER_ErrorCode last_ec,
   4448     const char *last_detail);
   4449 
   4450 
   4451   /**
   4452    * Update the amount of receipts for a Donau instance.
   4453    *
   4454    * @param cls closure
   4455    * @param donau_instances_serial serial number of the Donau instance
   4456    * @param new_amount new receipts_to_date amount
   4457    * @return database result code
   4458    */
   4459   enum GNUNET_DB_QueryStatus
   4460     (*update_donau_instance_receipts_amount)(
   4461     void *cls,
   4462     uint64_t *donau_instances_serial,
   4463     const struct TALER_Amount *new_amount
   4464     );
   4465 
   4466 
   4467   /**
   4468    * Check if a new matching multi-factor authorization (MFA) challenge
   4469    * exists in the database.
   4470    *
   4471    * @param cls closure
   4472    * @param challenge_id set to the ID of the challenge
   4473    * @param h_body hash of the request body
   4474    * @param[out] salt salt used to compute @a h_body
   4475    * @param[out] required address set to where the challenge is to be send
   4476    * @param[out] op operation that triggered the MFA request
   4477    * @param[out] confirmation_date when was the challenge solved,
   4478    *             set to "GNUNET_TIME_ABSOLUTE_NEVER" if unsolved
   4479    * @param[out] retransmission_date set to when a fresh challenge
   4480    *             may be transmitted
   4481    * @param[out] retry_counter set to the number of attempts that remain
   4482    *             for solving the challenge (after this time)
   4483    * @param[out] tan_channel which channel was used
   4484    * @return database result code
   4485    */
   4486   enum GNUNET_DB_QueryStatus
   4487     (*lookup_mfa_challenge)(
   4488     void *cls,
   4489     uint64_t challenge_id,
   4490     const struct TALER_MERCHANT_MFA_BodyHash *h_body,
   4491     struct TALER_MERCHANT_MFA_BodySalt *salt,
   4492     char **required_address,
   4493     enum TALER_MERCHANT_MFA_CriticalOperation *op,
   4494     struct GNUNET_TIME_Absolute *confirmation_date,
   4495     struct GNUNET_TIME_Absolute *retransmission_date,
   4496     uint32_t *retry_counter,
   4497     enum TALER_MERCHANT_MFA_Channel *tan_channel);
   4498 
   4499 
   4500   /**
   4501    * Attempt to solve new multi-factor authorization (MFA) challenge.
   4502    * Checks the solution against the code in the database and updates
   4503    * the solution state and (on failure) retry counter depending on
   4504    * the result.
   4505    *
   4506    * @param cls closure
   4507    * @param challenge_id challenge ID to be solved
   4508    * @param h_body body of the operation the challenge authorizes
   4509    * @param solution proposed solution to be checked against the actual code
   4510    * @param[out] solved set to true if the challenge was solved by
   4511    *             @a solution
   4512    * @param[out] retry_counter set to the number of attempts that remain
   4513    *             for solving the challenge (after this time)
   4514    * @return database result code
   4515    */
   4516   enum GNUNET_DB_QueryStatus
   4517     (*solve_mfa_challenge)(
   4518     void *cls,
   4519     uint64_t challenge_id,
   4520     const struct TALER_MERCHANT_MFA_BodyHash *h_body,
   4521     const char *solution,
   4522     bool *solved,
   4523     uint32_t *retry_counter);
   4524 
   4525 
   4526   /**
   4527    * Update the state of an MFA challenge as we have now
   4528    * retransmitted the challenge code.
   4529    *
   4530    * @param cls closure
   4531    * @param challenge_id challenge ID to be solved
   4532    * @param code new challenge code
   4533    * @param retry_counter number of attempts that remain
   4534    *             for solving the challenge
   4535    * @param expiration_date when should the challenge expire
   4536    * @param retransmission_date set to when a fresh challenge
   4537    *             may be transmitted next
   4538    * @return database result code
   4539    */
   4540   enum GNUNET_DB_QueryStatus
   4541     (*update_mfa_challenge)(
   4542     void *cls,
   4543     uint64_t challenge_id,
   4544     const char *code,
   4545     uint32_t retry_counter,
   4546     struct GNUNET_TIME_Absolute expiration_date,
   4547     struct GNUNET_TIME_Absolute retransmission_date);
   4548 
   4549 
   4550   /**
   4551    * Create new multi-factor authorization (MFA) challenge in the database.
   4552    *
   4553    * @param cls closure
   4554    * @param op operation that triggered the MFA request
   4555    * @param h_body hash of the request body
   4556    * @param salt salt used to compute @a h_body
   4557    * @param code challenge code sent to the user
   4558    * @param expiration_date when should the challenge expire
   4559    * @param retansmission_date when do we next allow retransmission
   4560    *        of the challenge
   4561    * @param tan_channel which channel was used
   4562    * @param required_address address
   4563    *        where the challenge is to be sent
   4564    * @param[out] challenge_id set to the ID of the new challenge
   4565    * @return database result code
   4566    */
   4567   enum GNUNET_DB_QueryStatus
   4568     (*create_mfa_challenge)(
   4569     void *cls,
   4570     enum TALER_MERCHANT_MFA_CriticalOperation op,
   4571     const struct TALER_MERCHANT_MFA_BodyHash *h_body,
   4572     const struct TALER_MERCHANT_MFA_BodySalt *salt,
   4573     const char *code,
   4574     struct GNUNET_TIME_Absolute expiration_date,
   4575     struct GNUNET_TIME_Absolute retransmission_date,
   4576     enum TALER_MERCHANT_MFA_Channel tan_channel,
   4577     const char *required_address,
   4578     uint64_t *challenge_id);
   4579 
   4580 
   4581 #ifdef HAVE_DONAU_DONAU_SERVICE_H
   4582   /**
   4583    * Insert information about a Donau instance.
   4584    *
   4585    * @param cls closure
   4586    * @param donau_url URL of the Donau instance
   4587    * @param charity details of the charity
   4588    * @param charity_id charity ID of the Donau instance
   4589    */
   4590   enum GNUNET_DB_QueryStatus
   4591     (*insert_donau_instance)(
   4592     void *cls,
   4593     const char *donau_url,
   4594     const struct DONAU_Charity *charity,
   4595     uint64_t charity_id
   4596     );
   4597 
   4598 
   4599   /**
   4600    * Check if information about a Donau instance exists.
   4601    *
   4602    * @param cls closure
   4603    * @param merchant_pub public key of the instance
   4604    * @param donau_url URL of the Donau instance
   4605    * @param charity_id charity ID of the Donau instance
   4606    */
   4607   enum GNUNET_DB_QueryStatus
   4608     (*check_donau_instance)(
   4609     void *cls,
   4610     const struct TALER_MerchantPublicKeyP *merchant_pub,
   4611     const char *donau_url,
   4612     uint64_t charity_id
   4613     );
   4614 
   4615   /**
   4616    * Select donau instance by serial number.
   4617    *
   4618    * @param cls closure
   4619    * @param serial serial number of the Donau instance in DB
   4620    * @param[out] donau_url set to the URL of the Donau instance
   4621    * @param[out] charity_id set to the charity ID of the Donau instance
   4622    */
   4623   enum GNUNET_DB_QueryStatus
   4624     (*select_donau_instance_by_serial)(
   4625     void *cls,
   4626     uint64_t serial,
   4627     char **donau_url,
   4628     uint64_t *charity_id);
   4629 
   4630   /**
   4631    * Select all Donau instances. Note that this callback only
   4632    * returns Donau instances for which we have successfully
   4633    * retrieved /keys.
   4634    *
   4635    * @param cls closure
   4636    * @param id instance to restrict to
   4637    * @param cb function to call on all Donau instances found
   4638    * @param cb_cls closure for @a cb
   4639    */
   4640   enum GNUNET_DB_QueryStatus
   4641     (*select_donau_instances)(
   4642     void *cls,
   4643     const char *id,
   4644     TALER_MERCHANTDB_DonauInstanceCallback cb,
   4645     void *cb_cls);
   4646 
   4647 
   4648   /**
   4649    * Select all Donau instances, regardless of instance and also
   4650    * regardless of whether we got a /keys response.
   4651    *
   4652    * @param cls closure
   4653    * @param cb function to call on all Donau instances found
   4654    * @param cb_cls closure for @a cb
   4655    */
   4656   enum GNUNET_DB_QueryStatus
   4657     (*select_all_donau_instances)(
   4658     void *cls,
   4659     TALER_MERCHANTDB_DonauInstanceCallback cb,
   4660     void *cb_cls);
   4661 
   4662 
   4663   /**
   4664    * Select all Donau instances, but only the donau_url
   4665    * and charity_max_per_year.
   4666    *
   4667    * @param cls closure
   4668    * @param cb function to call on all Donau instances found
   4669    * @param cb_cls closure for @a cb
   4670    */
   4671   enum GNUNET_DB_QueryStatus
   4672     (*select_donau_instances_filtered)(
   4673     void *cls,
   4674     const char *currency,
   4675     TALER_MERCHANTDB_DonauInstanceFilteredCallback cb,
   4676     void *cb_cls);
   4677 
   4678   /**
   4679    * Lookup Donau keys by URL.
   4680    *
   4681    * @param cls closure
   4682    * @param donau_url URL of the Donau instance
   4683    * @param[out] keys set to the Donau keys on success
   4684    */
   4685   enum GNUNET_DB_QueryStatus
   4686     (*lookup_donau_keys)(
   4687     void *cls,
   4688     const char *donau_url,
   4689     struct GNUNET_TIME_Absolute *first_retry,
   4690     struct DONAU_Keys **keys
   4691     );
   4692 
   4693   /**
   4694    * Lookup a Donau instance by its instance ID and URL.
   4695    *
   4696    * @param cls closure
   4697    * @param instance_id instance ID of the Donau instance
   4698    * @param donau_url URL of the Donau instance
   4699    * @param charity_id set to the charity ID of the Donau instance
   4700    * @param charity_priv set to the private key of the charity
   4701    * @param charity_max_per_year set to the maximum amount
   4702    *          the charity can receive per year
   4703    * @param charity_receipts_to_date set to the total amount
   4704    *         the charity has received to date
   4705    * @param donau_keys_json set to the JSON representation of the
   4706    *        Donau keys
   4707    */
   4708   enum GNUNET_DB_QueryStatus
   4709     (*lookup_order_charity)(
   4710     void *cls,
   4711     const char *instance_id,
   4712     const char *donau_url,
   4713     uint64_t *charity_id,
   4714     struct DONAU_CharityPrivateKeyP *charity_priv,
   4715     struct TALER_Amount *charity_max_per_year,
   4716     struct TALER_Amount *charity_receipts_to_date,
   4717     json_t **donau_keys_json,
   4718     uint64_t *donau_instance_serial
   4719     );
   4720 
   4721   /**
   4722    * Upsert Donau keys into the database.
   4723    *
   4724    * @param cls closure
   4725    * @param keys Donau keys to insert or update
   4726    */
   4727   enum GNUNET_DB_QueryStatus
   4728     (*upsert_donau_keys)(
   4729     void *cls,
   4730     const struct DONAU_Keys *keys,
   4731     struct GNUNET_TIME_Absolute first_retry
   4732     );
   4733 
   4734   /**
   4735    * Update information about a Donau instance.
   4736    *
   4737    * @param cls closure
   4738    * @param donau_url URL of the Donau instance
   4739    * @param charity details of the charity
   4740    * @param charity_id charity ID of the Donau instance
   4741    */
   4742   enum GNUNET_DB_QueryStatus
   4743     (*update_donau_instance)(
   4744     void *cls,
   4745     const char *donau_url,
   4746     const struct DONAU_Charity *charity,
   4747     uint64_t charity_id
   4748     );
   4749 
   4750 #endif
   4751 
   4752   /**
   4753    * Delete information about a Donau instance.
   4754    *
   4755    * @param cls closure
   4756    * @param charity_id charity ID of the Donau instance to delete
   4757    */
   4758   enum GNUNET_DB_QueryStatus
   4759     (*delete_donau_instance)(
   4760     void *cls,
   4761     const char *id,
   4762     uint64_t charity_id
   4763     );
   4764 
   4765   /**
   4766    * Lookup amount statistics for instance and slug by bucket.
   4767    *
   4768    * @param cls closure
   4769    * @param instance_id instance to lookup statistics for
   4770    * @param slug instance to lookup statistics for
   4771    * @param cb function to call on all token families found
   4772    * @param cb_cls closure for @a cb
   4773    * @return database result code
   4774    */
   4775   enum GNUNET_DB_QueryStatus
   4776     (*lookup_statistics_amount_by_bucket)(
   4777     void *cls,
   4778     const char *instance_id,
   4779     const char *slug,
   4780     TALER_MERCHANTDB_AmountByBucketStatisticsCallback cb,
   4781     void *cb_cls);
   4782 
   4783 
   4784   /**
   4785    * Lookup counter statistics for instance and slug by bucket.
   4786    *
   4787    * @param cls closure
   4788    * @param instance_id instance to lookup statistics for
   4789    * @param slug instance to lookup statistics for
   4790    * @param cb function to call on all token families found
   4791    * @param cb_cls closure for @a cb
   4792    * @return database result code
   4793    */
   4794   enum GNUNET_DB_QueryStatus
   4795     (*lookup_statistics_counter_by_bucket)(
   4796     void *cls,
   4797     const char *instance_id,
   4798     const char *slug,
   4799     TALER_MERCHANTDB_CounterByBucketStatisticsCallback cb,
   4800     void *cb_cls);
   4801 
   4802   /**
   4803    * Lookup amount statistics for instance and slug by interval.
   4804    *
   4805    * @param cls closure
   4806    * @param instance_id instance to lookup statistics for
   4807    * @param slug instance to lookup statistics for
   4808    * @param cb function to call on all token families found
   4809    * @param cb_cls closure for @a cb
   4810    * @return database result code
   4811    */
   4812   enum GNUNET_DB_QueryStatus
   4813     (*lookup_statistics_amount_by_interval)(
   4814     void *cls,
   4815     const char *instance_id,
   4816     const char *slug,
   4817     TALER_MERCHANTDB_AmountByIntervalStatisticsCallback cb,
   4818     void *cb_cls);
   4819   /**
   4820    * Lookup counter statistics for instance and slug by interval.
   4821    *
   4822    * @param cls closure
   4823    * @param instance_id instance to lookup statistics for
   4824    * @param slug instance to lookup statistics for
   4825    * @param cb function to call on all token families found
   4826    * @param cb_cls closure for @a cb
   4827    * @return database result code
   4828    */
   4829   enum GNUNET_DB_QueryStatus
   4830     (*lookup_statistics_counter_by_interval)(void *cls,
   4831                                              const char *instance_id,
   4832                                              const char *slug,
   4833                                              TALER_MERCHANTDB_CounterByIntervalStatisticsCallback
   4834                                              cb,
   4835                                              void *cb_cls);
   4836 };
   4837 
   4838 #endif