gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated: implement REST API for #9340


From: gnunet
Subject: [taler-exchange] branch master updated: implement REST API for #9340
Date: Wed, 27 Nov 2024 15:52:31 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new cebece5be implement REST API for #9340
cebece5be is described below

commit cebece5be0b6c8a333e727c6ac1fa198c3113b47
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Nov 27 15:52:16 2024 +0100

    implement REST API for #9340
---
 src/exchange/Makefile.am                           |   1 +
 src/exchange/taler-exchange-httpd.c                |   9 +-
 ...er-exchange-httpd_legitimization-measures-get.c | 202 ++++++++++++
 ...er-exchange-httpd_legitimization-measures-get.h |  43 +++
 src/exchangedb/Makefile.am                         | 339 ++++++++++----------
 src/exchangedb/plugin_exchangedb_postgres.c        | 343 +++++++++++----------
 src/include/taler_exchangedb_plugin.h              |  58 +++-
 7 files changed, 648 insertions(+), 347 deletions(-)

diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am
index 117264212..7672d2bac 100644
--- a/src/exchange/Makefile.am
+++ b/src/exchange/Makefile.am
@@ -157,6 +157,7 @@ taler_exchange_httpd_SOURCES = \
   taler-exchange-httpd_kyc-upload.c taler-exchange-httpd_kyc-upload.h \
   taler-exchange-httpd_kyc-wallet.c taler-exchange-httpd_kyc-wallet.h \
   taler-exchange-httpd_kyc-webhook.c taler-exchange-httpd_kyc-webhook.h \
+  taler-exchange-httpd_legitimization-measures-get.c 
taler-exchange-httpd_legitimization-measures-get.h \
   taler-exchange-httpd_link.c taler-exchange-httpd_link.h \
   taler-exchange-httpd_management.h \
   taler-exchange-httpd_management_aml-officers.c \
diff --git a/src/exchange/taler-exchange-httpd.c 
b/src/exchange/taler-exchange-httpd.c
index 2262532cd..ab0ec9114 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -54,6 +54,7 @@
 #include "taler-exchange-httpd_kyc-wallet.h"
 #include "taler-exchange-httpd_kyc-webhook.h"
 #include "taler-exchange-httpd_aml-decision.h"
+#include "taler-exchange-httpd_legitimization-measures-get.h"
 #include "taler-exchange-httpd_link.h"
 #include "taler-exchange-httpd_management.h"
 #include "taler-exchange-httpd_melt.h"
@@ -570,13 +571,17 @@ handle_get_aml (struct TEH_RequestContext *rc,
     AmlOpGetHandler handler;
 
   } h[] = {
+    {
+      .op = "attributes",
+      .handler = &TEH_handler_aml_attributes_get
+    },
     {
       .op = "decisions",
       .handler = &TEH_handler_aml_decisions_get
     },
     {
-      .op = "attributes",
-      .handler = &TEH_handler_aml_attributes_get
+      .op = "legitimizations",
+      .handler = &TEH_handler_legitimization_measures_get
     },
     {
       .op = "kyc-statistics",
diff --git a/src/exchange/taler-exchange-httpd_legitimization-measures-get.c 
b/src/exchange/taler-exchange-httpd_legitimization-measures-get.c
new file mode 100644
index 000000000..b8f6e7719
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_legitimization-measures-get.c
@@ -0,0 +1,202 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2024 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Affero General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more 
details.
+
+  You should have received a copy of the GNU Affero General Public License 
along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_legitimization-measures-get.c
+ * @brief Return information about legitimization measures
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_signatures.h"
+#include "taler-exchange-httpd.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler-exchange-httpd_legitimization-measures-get.h"
+#include "taler-exchange-httpd_metrics.h"
+
+/**
+ * Maximum number of measures we return in one request.
+ */
+#define MAX_MEASURES 1024
+
+/**
+ * Return LEGITIMIZATION measure.
+ *
+ * @param cls closure
+ * @param h_payto hash of account the measure applies to
+ * @param start_time when was the process started
+ * @param jmeasures array of measures that are active
+ * @param is_finished true if the measure was finished
+ * @param measure_serial_id row ID of the measure in the exchange table
+ */
+static void
+record_cb (
+  void *cls,
+  struct TALER_NormalizedPaytoHashP *h_payto,
+  struct GNUNET_TIME_Timestamp start_time,
+  const json_t *jmeasures,
+  bool is_finished,
+  uint64_t measure_serial_id)
+{
+  json_t *measures = cls;
+
+  GNUNET_assert (
+    0 ==
+    json_array_append_new (
+      measures,
+      GNUNET_JSON_PACK (
+        GNUNET_JSON_pack_data_auto ("h_payto",
+                                    h_payto),
+        GNUNET_JSON_pack_uint64 ("rowid",
+                                 measure_serial_id),
+        GNUNET_JSON_pack_timestamp ("start_time",
+                                    start_time),
+        GNUNET_JSON_pack_allow_null (
+          GNUNET_JSON_pack_array_incref ("measures",
+                                         (json_t *) jmeasures)),
+        GNUNET_JSON_pack_bool ("is_finished",
+                               is_finished)
+        )));
+}
+
+
+MHD_RESULT
+TEH_handler_legitimization_measures_get (
+  struct TEH_RequestContext *rc,
+  const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+  const char *const args[])
+{
+  int64_t limit = -20;
+  uint64_t offset;
+  struct TALER_NormalizedPaytoHashP h_payto;
+  bool have_payto = false;
+  enum TALER_EXCHANGE_YesNoAll active_filter;
+
+  if (NULL != args[0])
+  {
+    GNUNET_break_op (0);
+    return TALER_MHD_reply_with_error (
+      rc->connection,
+      MHD_HTTP_NOT_FOUND,
+      TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+      args[0]);
+  }
+  TALER_MHD_parse_request_snumber (rc->connection,
+                                   "limit",
+                                   &limit);
+  if (limit > 0)
+    offset = 0;
+  else
+    offset = INT64_MAX;
+  TALER_MHD_parse_request_number (rc->connection,
+                                  "offset",
+                                  &offset);
+  if (offset > INT64_MAX)
+  {
+    GNUNET_break_op (0); /* broken client */
+    offset = INT64_MAX;
+  }
+  TALER_MHD_parse_request_arg_auto (rc->connection,
+                                    "h_payto",
+                                    &h_payto,
+                                    have_payto);
+  TALER_MHD_parse_request_yna (rc->connection,
+                               "active",
+                               TALER_EXCHANGE_YNA_ALL,
+                               &active_filter);
+  {
+    enum GNUNET_DB_QueryStatus qs;
+
+    qs = TEH_plugin->test_aml_officer (TEH_plugin->cls,
+                                       officer_pub);
+    switch (qs)
+    {
+    case GNUNET_DB_STATUS_HARD_ERROR:
+    case GNUNET_DB_STATUS_SOFT_ERROR:
+      GNUNET_break (0);
+      return TALER_MHD_reply_with_error (
+        rc->connection,
+        MHD_HTTP_INTERNAL_SERVER_ERROR,
+        TALER_EC_GENERIC_DB_FETCH_FAILED,
+        "test_aml_officer");
+    case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+      GNUNET_break_op (0);
+      return TALER_MHD_reply_static (
+        rc->connection,
+        MHD_HTTP_FORBIDDEN,
+        NULL,
+        NULL,
+        0);
+    case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+      break;
+    }
+  }
+  {
+    json_t *measures;
+    enum GNUNET_DB_QueryStatus qs;
+
+    measures = json_array ();
+    GNUNET_assert (NULL != measures);
+    if (limit > MAX_MEASURES)
+      limit = MAX_MEASURES;
+    if (limit < -MAX_MEASURES)
+      limit = -MAX_MEASURES;
+    qs = TEH_plugin->select_aml_measures (
+      TEH_plugin->cls,
+      have_payto
+      ? &h_payto
+      : NULL,
+      active_filter,
+      offset,
+      limit,
+      &record_cb,
+      measures);
+    switch (qs)
+    {
+    case GNUNET_DB_STATUS_HARD_ERROR:
+    case GNUNET_DB_STATUS_SOFT_ERROR:
+      json_decref (measures);
+      GNUNET_break (0);
+      return TALER_MHD_reply_with_error (
+        rc->connection,
+        MHD_HTTP_INTERNAL_SERVER_ERROR,
+        TALER_EC_GENERIC_DB_FETCH_FAILED,
+        "select_aml_measures");
+    case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+      json_decref (measures);
+      return TALER_MHD_reply_static (
+        rc->connection,
+        MHD_HTTP_NO_CONTENT,
+        NULL,
+        NULL,
+        0);
+    case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+      break;
+    }
+    return TALER_MHD_REPLY_JSON_PACK (
+      rc->connection,
+      MHD_HTTP_OK,
+      GNUNET_JSON_pack_array_steal ("measures",
+                                    measures));
+  }
+}
+
+
+/* end of taler-exchange-httpd_legitimization-measures_get.c */
diff --git a/src/exchange/taler-exchange-httpd_legitimization-measures-get.h 
b/src/exchange/taler-exchange-httpd_legitimization-measures-get.h
new file mode 100644
index 000000000..c47ea1941
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_legitimization-measures-get.h
@@ -0,0 +1,43 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2023 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Affero General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more 
details.
+
+  You should have received a copy of the GNU Affero General Public License 
along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_legitimization-measures.h
+ * @brief Handle /aml/$OFFICER_PUB/legitimizations requests
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_LEGITIMIZATION_MEASURES_GET_H
+#define TALER_EXCHANGE_HTTPD_LEGITIMIZATION_MEASURES_GET_H
+
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+/**
+ * Handle a GET "/aml/$OFFICER_PUB/legitimizations" request.  Parses the 
request
+ * details, checks the signatures and if appropriately authorized returns
+ * the matching measuress.
+ *
+ * @param rc request context
+ * @param officer_pub public key of the AML officer who made the request
+ * @param args GET arguments (should be the state)
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_legitimization_measures_get (
+  struct TEH_RequestContext *rc,
+  const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+  const char *const args[]);
+
+#endif
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index 7050986ed..9560eefc8 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -122,204 +122,205 @@ plugin_LTLIBRARIES = \
 endif
 
 libtaler_plugin_exchangedb_postgres_la_SOURCES = \
-  plugin_exchangedb_common.c plugin_exchangedb_common.h \
+  pg_abort_shard.h pg_abort_shard.c \
+  pg_activate_signing_key.h pg_activate_signing_key.c \
+  pg_add_denomination_key.h pg_add_denomination_key.c \
+  pg_add_policy_fulfillment_proof.h pg_add_policy_fulfillment_proof.c \
+  pg_aggregate.h pg_aggregate.c \
+  pg_batch_ensure_coin_known.h pg_batch_ensure_coin_known.c \
+  pg_begin_revolving_shard.h pg_begin_revolving_shard.c \
+  pg_begin_shard.h pg_begin_shard.c \
+  pg_commit.h pg_commit.c \
+  pg_complete_shard.h pg_complete_shard.c \
   pg_compute_shard.h pg_compute_shard.c \
-  plugin_exchangedb_postgres.c plugin_exchangedb_postgres.h \
-  pg_helper.h \
-  pg_reserves_update.h pg_reserves_update.c \
-  pg_select_aggregation_amounts_for_kyc_check.h 
pg_select_aggregation_amounts_for_kyc_check.c \
-  pg_lookup_wire_fee_by_time.h pg_lookup_wire_fee_by_time.c \
-  pg_get_kyc_rules.h pg_get_kyc_rules.c \
-  pg_get_pending_kyc_requirement_process.h 
pg_get_pending_kyc_requirement_process.c \
-  pg_kyc_provider_account_lookup.h pg_kyc_provider_account_lookup.c \
-  pg_lookup_kyc_process_by_account.h pg_lookup_kyc_process_by_account.c \
-  pg_update_kyc_process_by_row.h pg_update_kyc_process_by_row.c \
-  pg_insert_kyc_requirement_process.h pg_insert_kyc_requirement_process.c \
-  pg_select_withdraw_amounts_for_kyc_check.h 
pg_select_withdraw_amounts_for_kyc_check.c \
-  pg_select_merge_amounts_for_kyc_check.h 
pg_select_merge_amounts_for_kyc_check.c \
-  pg_profit_drains_set_finished.h pg_profit_drains_set_finished.c \
-  pg_select_deposit_amounts_for_kyc_check.h 
pg_select_deposit_amounts_for_kyc_check.c \
-  pg_lookup_aml_history.h pg_lookup_aml_history.c \
-  pg_lookup_kyc_history.h pg_lookup_kyc_history.c \
-  pg_profit_drains_get_pending.h pg_profit_drains_get_pending.c \
-  pg_get_drain_profit.h pg_get_drain_profit.c \
-  pg_get_purse_deposit.h pg_get_purse_deposit.c \
-  pg_do_check_deposit_idempotent.h pg_do_check_deposit_idempotent.c \
-  pg_insert_contract.h pg_insert_contract.c \
-  pg_select_contract.h pg_select_contract.c \
-  pg_select_purse_merge.h pg_select_purse_merge.c \
-  pg_select_contract_by_purse.h pg_select_contract_by_purse.c \
-  pg_insert_drain_profit.h pg_insert_drain_profit.c \
-  pg_insert_kyc_failure.h pg_insert_kyc_failure.c \
-  pg_inject_auditor_triggers.h pg_inject_auditor_triggers.c \
+  pg_count_known_coins.h pg_count_known_coins.c \
+  pg_create_aggregation_transient.h pg_create_aggregation_transient.c \
   pg_create_tables.h pg_create_tables.c \
-  pg_event_listen.h pg_event_listen.c \
-  pg_event_listen_cancel.h pg_event_listen_cancel.c \
-  pg_event_notify.h pg_event_notify.c \
-  pg_get_denomination_info.h pg_get_denomination_info.c \
-  pg_iterate_denomination_info.h pg_iterate_denomination_info.c \
-  pg_iterate_denominations.h pg_iterate_denominations.c \
-  pg_iterate_active_auditors.h pg_iterate_active_auditors.c \
-  pg_iterate_auditor_denominations.h pg_iterate_auditor_denominations.c \
-  pg_reserves_get.h pg_reserves_get.c \
-  pg_lookup_rules_by_access_token.h pg_lookup_rules_by_access_token.c \
-  pg_reserves_get_origin.h pg_reserves_get_origin.c \
-  pg_drain_kyc_alert.h pg_drain_kyc_alert.c \
-  pg_reserves_in_insert.h pg_reserves_in_insert.c \
-  pg_get_withdraw_info.h pg_get_withdraw_info.c \
+  pg_delete_aggregation_transient.h pg_delete_aggregation_transient.c \
+  pg_delete_shard_locks.h pg_delete_shard_locks.c \
   pg_do_age_withdraw.h pg_do_age_withdraw.c \
-  pg_get_age_withdraw.h pg_get_age_withdraw.c \
-  pg_batch_ensure_coin_known.h pg_batch_ensure_coin_known.c \
   pg_do_batch_withdraw.h pg_do_batch_withdraw.c \
-  pg_get_policy_details.h pg_get_policy_details.c \
-  pg_persist_policy_details.h pg_persist_policy_details.c \
+  pg_do_batch_withdraw_insert.h pg_do_batch_withdraw_insert.c \
+  pg_do_check_deposit_idempotent.h pg_do_check_deposit_idempotent.c \
   pg_do_deposit.h pg_do_deposit.c \
-  pg_get_wire_hash_for_contract.h pg_get_wire_hash_for_contract.c \
-  pg_lookup_h_payto_by_access_token.h pg_lookup_h_payto_by_access_token.c \
-  pg_add_policy_fulfillment_proof.h pg_add_policy_fulfillment_proof.c \
   pg_do_melt.h pg_do_melt.c \
-  pg_do_refund.h pg_do_refund.c \
+  pg_do_purse_delete.c pg_do_purse_delete.h \
+  pg_do_purse_deposit.h pg_do_purse_deposit.c \
+  pg_do_purse_merge.h pg_do_purse_merge.c \
   pg_do_recoup.h pg_do_recoup.c \
   pg_do_recoup_refresh.h pg_do_recoup_refresh.c \
-  pg_get_reserve_balance.h pg_get_reserve_balance.c \
-  pg_select_aml_attributes.h pg_select_aml_attributes.c \
-  pg_count_known_coins.h pg_count_known_coins.c \
+  pg_do_refund.h pg_do_refund.c \
+  pg_do_reserve_open.c pg_do_reserve_open.h \
+  pg_do_reserve_purse.h pg_do_reserve_purse.c \
+  pg_drain_kyc_alert.h pg_drain_kyc_alert.c \
+  pg_drop_tables.h pg_drop_tables.c \
   pg_ensure_coin_known.h pg_ensure_coin_known.c \
+  pg_event_listen.h pg_event_listen.c \
+  pg_event_listen_cancel.h pg_event_listen_cancel.c \
+  pg_event_notify.h pg_event_notify.c \
+  pg_expire_purse.h pg_expire_purse.c \
+  pg_find_aggregation_transient.h pg_find_aggregation_transient.c \
+  pg_gc.h pg_gc.c \
+  pg_get_age_withdraw.h pg_get_age_withdraw.c \
+  pg_get_coin_denomination.h pg_get_coin_denomination.c \
+  pg_get_coin_transactions.c pg_get_coin_transactions.h \
+  pg_get_denomination_info.h pg_get_denomination_info.c \
+  pg_get_denomination_revocation.h pg_get_denomination_revocation.c \
+  pg_get_drain_profit.h pg_get_drain_profit.c \
+  pg_get_expired_reserves.c pg_get_expired_reserves.h \
+  pg_get_extension_manifest.h pg_get_extension_manifest.c \
+  pg_get_global_fee.h pg_get_global_fee.c \
+  pg_get_global_fees.h pg_get_global_fees.c \
   pg_get_known_coin.h pg_get_known_coin.c \
+  pg_get_kyc_rules.h pg_get_kyc_rules.c \
+  pg_get_link_data.h pg_get_link_data.c \
+  pg_get_melt.h pg_get_melt.c \
+  pg_get_old_coin_by_h_blind.h pg_get_old_coin_by_h_blind.c \
+  pg_get_pending_kyc_requirement_process.h 
pg_get_pending_kyc_requirement_process.c \
+  pg_get_policy_details.h pg_get_policy_details.c \
+  pg_get_purse_deposit.h pg_get_purse_deposit.c \
+  pg_get_purse_request.c pg_get_purse_request.h \
+  pg_get_ready_deposit.h pg_get_ready_deposit.c \
+  pg_get_refresh_reveal.h pg_get_refresh_reveal.c \
+  pg_get_reserve_balance.h pg_get_reserve_balance.c \
+  pg_get_reserve_by_h_blind.h pg_get_reserve_by_h_blind.c \
+  pg_get_reserve_history.c pg_get_reserve_history.h \
   pg_get_signature_for_known_coin.h pg_get_signature_for_known_coin.c \
-  pg_select_aml_statistics.h pg_select_aml_statistics.c \
-  pg_get_coin_denomination.h pg_get_coin_denomination.c \
-  pg_select_aml_decisions.h pg_select_aml_decisions.c \
+  pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \
+  pg_get_wire_accounts.h pg_get_wire_accounts.c \
+  pg_get_wire_fee.h pg_get_wire_fee.c \
+  pg_get_wire_fees.h pg_get_wire_fees.c \
+  pg_get_wire_hash_for_contract.h pg_get_wire_hash_for_contract.c \
+  pg_get_withdraw_info.h pg_get_withdraw_info.c \
   pg_have_deposit2.h pg_have_deposit2.c \
-  pg_aggregate.h pg_aggregate.c \
-  pg_create_aggregation_transient.h pg_create_aggregation_transient.c \
-  pg_insert_kyc_measure_result.h pg_insert_kyc_measure_result.c \
-  pg_select_kyc_attributes.h pg_select_kyc_attributes.c \
-  pg_insert_aml_officer.h pg_insert_aml_officer.c \
-  pg_test_aml_officer.h pg_test_aml_officer.c \
-  pg_lookup_aml_officer.h pg_lookup_aml_officer.c \
-  pg_lookup_pending_legitimization.h pg_lookup_pending_legitimization.c \
-  pg_lookup_completed_legitimization.h pg_lookup_completed_legitimization.c \
-  pg_lookup_active_legitimization.h pg_lookup_active_legitimization.c \
+  pg_helper.h \
+  pg_inject_auditor_triggers.h pg_inject_auditor_triggers.c \
+  pg_insert_active_legitimization_measure.h 
pg_insert_active_legitimization_measure.c \
   pg_insert_aml_decision.h pg_insert_aml_decision.c \
-  pg_insert_successor_measure.h pg_insert_successor_measure.c \
-  pg_select_aggregation_transient.h pg_select_aggregation_transient.c \
-  pg_find_aggregation_transient.h pg_find_aggregation_transient.c \
-  pg_update_aggregation_transient.h pg_update_aggregation_transient.c \
-  pg_get_ready_deposit.h pg_get_ready_deposit.c \
-  pg_insert_refund.h pg_insert_refund.c \
-  pg_select_refunds_by_coin.h pg_select_refunds_by_coin.c \
-  pg_get_melt.h pg_get_melt.c \
-  pg_insert_refresh_reveal.h pg_insert_refresh_reveal.c \
-  pg_get_refresh_reveal.h pg_get_refresh_reveal.c \
-  pg_lookup_wire_transfer.h pg_lookup_wire_transfer.c \
-  pg_lookup_transfer_by_deposit.h pg_lookup_transfer_by_deposit.c \
-  pg_insert_wire_fee.h pg_insert_wire_fee.c \
+  pg_insert_aml_officer.h pg_insert_aml_officer.c \
+  pg_insert_auditor.h pg_insert_auditor.c \
+  pg_insert_auditor_denom_sig.h pg_insert_auditor_denom_sig.c \
+  pg_insert_close_request.c pg_insert_close_request.h \
+  pg_insert_contract.h pg_insert_contract.c \
+  pg_insert_denomination_info.h pg_insert_denomination_info.c \
+  pg_insert_denomination_revocation.h pg_insert_denomination_revocation.c \
+  pg_insert_drain_profit.h pg_insert_drain_profit.c \
   pg_insert_global_fee.h pg_insert_global_fee.c \
-  pg_get_wire_fee.h pg_get_wire_fee.c \
-  pg_get_global_fee.h pg_get_global_fee.c \
-  pg_get_global_fees.h pg_get_global_fees.c \
+  pg_insert_kyc_failure.h pg_insert_kyc_failure.c \
+  pg_insert_kyc_measure_result.h pg_insert_kyc_measure_result.c \
+  pg_insert_kyc_requirement_process.h pg_insert_kyc_requirement_process.c \
+  pg_insert_partner.h pg_insert_partner.c \
+  pg_insert_purse_request.h pg_insert_purse_request.c \
+  pg_insert_records_by_table.c pg_insert_records_by_table.h \
+  pg_insert_refresh_reveal.h pg_insert_refresh_reveal.c \
+  pg_insert_refund.h pg_insert_refund.c \
   pg_insert_reserve_closed.h pg_insert_reserve_closed.c \
-  pg_wire_prepare_data_insert.h pg_wire_prepare_data_insert.c \
-  pg_wire_prepare_data_mark_finished.h pg_wire_prepare_data_mark_finished.c \
-  pg_wire_prepare_data_mark_failed.h pg_wire_prepare_data_mark_failed.c \
-  pg_wire_prepare_data_get.h pg_wire_prepare_data_get.c \
-  pg_start_deferred_wire_out.h pg_start_deferred_wire_out.c \
-  pg_insert_active_legitimization_measure.h 
pg_insert_active_legitimization_measure.c \
-  pg_store_wire_transfer_out.h pg_store_wire_transfer_out.c \
-  pg_gc.h pg_gc.c \
+  pg_insert_reserve_open_deposit.c pg_insert_reserve_open_deposit.h \
+  pg_insert_signkey_revocation.h pg_insert_signkey_revocation.c \
+  pg_insert_successor_measure.h pg_insert_successor_measure.c \
+  pg_insert_wire.h pg_insert_wire.c \
+  pg_insert_wire_fee.h pg_insert_wire_fee.c \
+  pg_iterate_active_auditors.h pg_iterate_active_auditors.c \
+  pg_iterate_active_signkeys.h pg_iterate_active_signkeys.c \
+  pg_iterate_auditor_denominations.h pg_iterate_auditor_denominations.c \
+  pg_iterate_denomination_info.h pg_iterate_denomination_info.c \
+  pg_iterate_denominations.h pg_iterate_denominations.c \
+  pg_iterate_kyc_reference.c pg_iterate_kyc_reference.h \
+  pg_iterate_reserve_close_info.c pg_iterate_reserve_close_info.h \
+  pg_kyc_provider_account_lookup.h pg_kyc_provider_account_lookup.c \
+  pg_kycauth_in_insert.h pg_kycauth_in_insert.c \
+  pg_lookup_active_legitimization.h pg_lookup_active_legitimization.c \
+  pg_lookup_aml_history.h pg_lookup_aml_history.c \
+  pg_lookup_aml_officer.h pg_lookup_aml_officer.c \
+  pg_lookup_auditor_status.h pg_lookup_auditor_status.c \
+  pg_lookup_auditor_timestamp.h pg_lookup_auditor_timestamp.c \
+  pg_lookup_completed_legitimization.h pg_lookup_completed_legitimization.c \
+  pg_lookup_denomination_key.h pg_lookup_denomination_key.c \
+  pg_lookup_global_fee_by_time.h pg_lookup_global_fee_by_time.c \
+  pg_lookup_h_payto_by_access_token.h pg_lookup_h_payto_by_access_token.c \
+  pg_lookup_kyc_history.h pg_lookup_kyc_history.c \
+  pg_lookup_kyc_process_by_account.h pg_lookup_kyc_process_by_account.c \
+  pg_lookup_kyc_requirement_by_row.h pg_lookup_kyc_requirement_by_row.c \
   pg_lookup_kyc_status_by_token.h pg_lookup_kyc_status_by_token.c \
+  pg_lookup_pending_legitimization.h pg_lookup_pending_legitimization.c \
+  pg_lookup_records_by_table.c pg_lookup_records_by_table.h \
+  pg_lookup_rules_by_access_token.h pg_lookup_rules_by_access_token.c \
+  pg_lookup_serial_by_table.c pg_lookup_serial_by_table.h \
+  pg_lookup_signing_key.h pg_lookup_signing_key.c \
+  pg_lookup_signkey_revocation.h pg_lookup_signkey_revocation.c \
+  pg_lookup_transfer_by_deposit.h pg_lookup_transfer_by_deposit.c \
+  pg_lookup_wire_fee_by_time.h pg_lookup_wire_fee_by_time.c \
+  pg_lookup_wire_timestamp.h pg_lookup_wire_timestamp.c \
+  pg_lookup_wire_transfer.h pg_lookup_wire_transfer.c \
+  pg_persist_policy_details.h pg_persist_policy_details.c \
+  pg_preflight.h pg_preflight.c \
+  pg_profit_drains_get_pending.h pg_profit_drains_get_pending.c \
+  pg_profit_drains_set_finished.h pg_profit_drains_set_finished.c \
+  pg_release_revolving_shard.h pg_release_revolving_shard.c \
+  pg_reserves_get.h pg_reserves_get.c \
+  pg_reserves_get_origin.h pg_reserves_get_origin.c \
+  pg_reserves_in_insert.h pg_reserves_in_insert.c \
+  pg_reserves_update.h pg_reserves_update.c \
+  pg_rollback.h pg_rollback.c \
+  pg_select_account_merges_above_serial_id.h 
pg_select_account_merges_above_serial_id.c \
+  pg_select_aggregation_amounts_for_kyc_check.h 
pg_select_aggregation_amounts_for_kyc_check.c \
+  pg_select_aggregation_transient.h pg_select_aggregation_transient.c \
+  pg_select_aggregations_above_serial.h pg_select_aggregations_above_serial.c \
+  pg_select_all_purse_decisions_above_serial_id.h 
pg_select_all_purse_decisions_above_serial_id.c \
+  pg_select_aml_attributes.h pg_select_aml_attributes.c \
+  pg_select_aml_decisions.h pg_select_aml_decisions.c \
+  pg_select_aml_measures.h pg_select_aml_measures.c \
+  pg_select_aml_statistics.h pg_select_aml_statistics.c \
+  pg_select_auditor_denom_sig.h pg_select_auditor_denom_sig.c \
+  pg_select_batch_deposits_missing_wire.h 
pg_select_batch_deposits_missing_wire.c \
   pg_select_coin_deposits_above_serial_id.h 
pg_select_coin_deposits_above_serial_id.c \
+  pg_select_contract.h pg_select_contract.c \
+  pg_select_contract_by_purse.h pg_select_contract_by_purse.c \
+  pg_select_deposit_amounts_for_kyc_check.h 
pg_select_deposit_amounts_for_kyc_check.c \
+  pg_select_kyc_attributes.h pg_select_kyc_attributes.c \
+  pg_select_merge_amounts_for_kyc_check.h 
pg_select_merge_amounts_for_kyc_check.c \
+  pg_select_purse.h pg_select_purse.c \
+  pg_select_purse_by_merge_pub.h pg_select_purse_by_merge_pub.c \
   pg_select_purse_decisions_above_serial_id.h 
pg_select_purse_decisions_above_serial_id.c \
+  pg_select_purse_deposits_above_serial_id.h 
pg_select_purse_deposits_above_serial_id.c \
   pg_select_purse_deposits_by_purse.h pg_select_purse_deposits_by_purse.c \
+  pg_select_purse_merge.h pg_select_purse_merge.c \
+  pg_select_purse_merges_above_serial_id.h 
pg_select_purse_merges_above_serial_id.c \
+  pg_select_purse_requests_above_serial_id.h 
pg_select_purse_requests_above_serial_id.c \
+  pg_select_recoup_above_serial_id.h pg_select_recoup_above_serial_id.c \
+  pg_select_recoup_refresh_above_serial_id.h 
pg_select_recoup_refresh_above_serial_id.c \
   pg_select_refreshes_above_serial_id.h pg_select_refreshes_above_serial_id.c \
   pg_select_refunds_above_serial_id.h pg_select_refunds_above_serial_id.c \
+  pg_select_refunds_by_coin.h pg_select_refunds_by_coin.c \
+  pg_select_reserve_close_info.c pg_select_reserve_close_info.h \
+  pg_select_reserve_closed_above_serial_id.c 
pg_select_reserve_closed_above_serial_id.h \
+  pg_select_reserve_open_above_serial_id.c 
pg_select_reserve_open_above_serial_id.h \
   pg_select_reserves_in_above_serial_id.h 
pg_select_reserves_in_above_serial_id.c \
-  pg_trigger_kyc_rule_for_account.h pg_trigger_kyc_rule_for_account.c \
   pg_select_reserves_in_above_serial_id_by_account.h 
pg_select_reserves_in_above_serial_id_by_account.c \
-  pg_select_withdrawals_above_serial_id.h 
pg_select_withdrawals_above_serial_id.c \
   pg_select_wire_out_above_serial_id.h pg_select_wire_out_above_serial_id.c \
   pg_select_wire_out_above_serial_id_by_account.h 
pg_select_wire_out_above_serial_id_by_account.c \
-  pg_select_recoup_above_serial_id.h pg_select_recoup_above_serial_id.c \
-  pg_select_recoup_refresh_above_serial_id.h 
pg_select_recoup_refresh_above_serial_id.c \
-  pg_get_reserve_by_h_blind.h pg_get_reserve_by_h_blind.c \
-  pg_get_old_coin_by_h_blind.h pg_get_old_coin_by_h_blind.c \
-  pg_insert_denomination_revocation.h pg_insert_denomination_revocation.c \
-  pg_get_denomination_revocation.h pg_get_denomination_revocation.c \
-  pg_select_batch_deposits_missing_wire.h 
pg_select_batch_deposits_missing_wire.c \
-  pg_select_aggregations_above_serial.h pg_select_aggregations_above_serial.c \
-  pg_lookup_auditor_timestamp.h pg_lookup_auditor_timestamp.c \
-  pg_lookup_auditor_status.h pg_lookup_auditor_status.c \
-  pg_insert_auditor.h pg_insert_auditor.c \
-  pg_lookup_wire_timestamp.h pg_lookup_wire_timestamp.c \
-  pg_wad_in_insert.h pg_wad_in_insert.c \
-  pg_kycauth_in_insert.h pg_kycauth_in_insert.c \
-  pg_insert_wire.h pg_insert_wire.c \
-  pg_update_wire.h pg_update_wire.c \
-  pg_get_wire_accounts.h pg_get_wire_accounts.c \
-  pg_get_wire_fees.h pg_get_wire_fees.c \
-  pg_insert_signkey_revocation.h pg_insert_signkey_revocation.c \
-  pg_lookup_signkey_revocation.h pg_lookup_signkey_revocation.c \
-  pg_lookup_denomination_key.h pg_lookup_denomination_key.c \
-  pg_insert_auditor_denom_sig.h pg_insert_auditor_denom_sig.c \
-  pg_select_auditor_denom_sig.h pg_select_auditor_denom_sig.c \
-  pg_add_denomination_key.h pg_add_denomination_key.c \
-  pg_lookup_signing_key.h pg_lookup_signing_key.c \
-  pg_begin_shard.h pg_begin_shard.c \
-  pg_abort_shard.h pg_abort_shard.c \
-  pg_complete_shard.h pg_complete_shard.c \
-  pg_release_revolving_shard.h pg_release_revolving_shard.c \
-  pg_delete_shard_locks.h pg_delete_shard_locks.c \
+  pg_select_withdraw_amounts_for_kyc_check.h 
pg_select_withdraw_amounts_for_kyc_check.c \
+  pg_select_withdrawals_above_serial_id.h 
pg_select_withdrawals_above_serial_id.c \
   pg_set_extension_manifest.h pg_set_extension_manifest.c \
-  pg_insert_partner.h pg_insert_partner.c \
-  pg_expire_purse.h pg_expire_purse.c \
-  pg_select_purse_by_merge_pub.h pg_select_purse_by_merge_pub.c \
   pg_set_purse_balance.h pg_set_purse_balance.c \
-  pg_do_reserve_purse.h pg_do_reserve_purse.c \
-  pg_lookup_global_fee_by_time.h pg_lookup_global_fee_by_time.c \
-  pg_do_purse_deposit.h pg_do_purse_deposit.c \
-  pg_activate_signing_key.h pg_activate_signing_key.c \
-  pg_update_auditor.h pg_update_auditor.c \
-  pg_begin_revolving_shard.h pg_begin_revolving_shard.c \
-  pg_get_extension_manifest.h pg_get_extension_manifest.c \
-  pg_do_purse_merge.h pg_do_purse_merge.c \
+  pg_start.h pg_start.c \
+  pg_start_deferred_wire_out.h pg_start_deferred_wire_out.c \
   pg_start_read_committed.h pg_start_read_committed.c \
   pg_start_read_only.h pg_start_read_only.c \
-  pg_insert_denomination_info.h pg_insert_denomination_info.c \
-  pg_do_batch_withdraw_insert.h pg_do_batch_withdraw_insert.c \
-  pg_do_reserve_open.c pg_do_reserve_open.h \
-  pg_do_purse_delete.c pg_do_purse_delete.h \
-  pg_preflight.h pg_preflight.c \
-  pg_iterate_active_signkeys.h pg_iterate_active_signkeys.c \
-  pg_commit.h pg_commit.c \
-  pg_get_coin_transactions.c pg_get_coin_transactions.h \
-  pg_get_expired_reserves.c pg_get_expired_reserves.h \
-  pg_start.h pg_start.c \
-  pg_rollback.h pg_rollback.c \
-  pg_get_purse_request.c pg_get_purse_request.h \
-  pg_get_reserve_history.c pg_get_reserve_history.h \
-  pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \
-  pg_insert_close_request.c pg_insert_close_request.h \
-  pg_delete_aggregation_transient.h pg_delete_aggregation_transient.c \
-  pg_get_link_data.h pg_get_link_data.c \
-  pg_drop_tables.h pg_drop_tables.c \
-  pg_insert_purse_request.h pg_insert_purse_request.c \
-  pg_insert_records_by_table.c pg_insert_records_by_table.h \
-  pg_insert_reserve_open_deposit.c pg_insert_reserve_open_deposit.h \
-  pg_iterate_kyc_reference.c pg_iterate_kyc_reference.h \
-  pg_iterate_reserve_close_info.c pg_iterate_reserve_close_info.h \
-  pg_lookup_records_by_table.c pg_lookup_records_by_table.h \
-  pg_lookup_serial_by_table.c pg_lookup_serial_by_table.h \
-  pg_select_reserve_close_info.c pg_select_reserve_close_info.h \
-  pg_select_reserve_closed_above_serial_id.c 
pg_select_reserve_closed_above_serial_id.h \
-  pg_select_purse.h pg_select_purse.c \
-  pg_select_purse_requests_above_serial_id.h 
pg_select_purse_requests_above_serial_id.c \
-  pg_select_purse_merges_above_serial_id.h 
pg_select_purse_merges_above_serial_id.c \
-  pg_select_purse_deposits_above_serial_id.h 
pg_select_purse_deposits_above_serial_id.c \
-  pg_select_account_merges_above_serial_id.h 
pg_select_account_merges_above_serial_id.c \
-  pg_select_all_purse_decisions_above_serial_id.h 
pg_select_all_purse_decisions_above_serial_id.c \
-  pg_lookup_kyc_requirement_by_row.h pg_lookup_kyc_requirement_by_row.c \
-  pg_select_reserve_open_above_serial_id.c 
pg_select_reserve_open_above_serial_id.h
+  pg_store_wire_transfer_out.h pg_store_wire_transfer_out.c \
+  pg_test_aml_officer.h pg_test_aml_officer.c \
+  pg_trigger_kyc_rule_for_account.h pg_trigger_kyc_rule_for_account.c \
+  pg_update_aggregation_transient.h pg_update_aggregation_transient.c \
+  pg_update_auditor.h pg_update_auditor.c \
+  pg_update_kyc_process_by_row.h pg_update_kyc_process_by_row.c \
+  pg_update_wire.h pg_update_wire.c \
+  pg_wad_in_insert.h pg_wad_in_insert.c \
+  pg_wire_prepare_data_get.h pg_wire_prepare_data_get.c \
+  pg_wire_prepare_data_insert.h pg_wire_prepare_data_insert.c \
+  pg_wire_prepare_data_mark_failed.h pg_wire_prepare_data_mark_failed.c \
+  pg_wire_prepare_data_mark_finished.h pg_wire_prepare_data_mark_finished.c \
+  plugin_exchangedb_common.c plugin_exchangedb_common.h \
+  plugin_exchangedb_postgres.c plugin_exchangedb_postgres.h
 
 
 libtaler_plugin_exchangedb_postgres_la_LDFLAGS = \
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 05e37efe9..9806bb2fa 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -27,210 +27,211 @@
 #include <poll.h>
 #include <pthread.h>
 #include <libpq-fe.h>
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_exchangedb_plugin.h"
-#include "pg_select_aml_decisions.h"
-#include "plugin_exchangedb_common.h"
+#include "pg_abort_shard.h"
+#include "pg_activate_signing_key.h"
+#include "pg_add_denomination_key.h"
+#include "pg_add_policy_fulfillment_proof.h"
+#include "pg_aggregate.h"
+#include "pg_batch_ensure_coin_known.h"
+#include "pg_begin_revolving_shard.h"
+#include "pg_begin_shard.h"
+#include "pg_commit.h"
+#include "pg_complete_shard.h"
+#include "pg_compute_shard.h"
+#include "pg_count_known_coins.h"
+#include "pg_create_aggregation_transient.h"
+#include "pg_create_tables.h"
 #include "pg_delete_aggregation_transient.h"
-#include "pg_get_link_data.h"
-#include "pg_helper.h"
+#include "pg_delete_shard_locks.h"
+#include "pg_do_age_withdraw.h"
+#include "pg_do_batch_withdraw.h"
+#include "pg_do_batch_withdraw_insert.h"
 #include "pg_do_check_deposit_idempotent.h"
+#include "pg_do_deposit.h"
+#include "pg_do_melt.h"
+#include "pg_do_purse_delete.h"
+#include "pg_do_purse_deposit.h"
+#include "pg_do_purse_merge.h"
+#include "pg_do_recoup.h"
+#include "pg_do_recoup_refresh.h"
+#include "pg_do_refund.h"
 #include "pg_do_reserve_open.h"
+#include "pg_do_reserve_purse.h"
+#include "pg_drain_kyc_alert.h"
+#include "pg_drop_tables.h"
+#include "pg_ensure_coin_known.h"
+#include "pg_event_listen.h"
+#include "pg_event_listen_cancel.h"
+#include "pg_event_notify.h"
+#include "pg_expire_purse.h"
+#include "pg_find_aggregation_transient.h"
+#include "pg_gc.h"
+#include "pg_get_age_withdraw.h"
+#include "pg_get_coin_denomination.h"
 #include "pg_get_coin_transactions.h"
+#include "pg_get_denomination_info.h"
+#include "pg_get_denomination_revocation.h"
+#include "pg_get_drain_profit.h"
 #include "pg_get_expired_reserves.h"
-#include "pg_lookup_rules_by_access_token.h"
-#include "pg_lookup_h_payto_by_access_token.h"
+#include "pg_get_extension_manifest.h"
+#include "pg_get_global_fee.h"
+#include "pg_get_global_fees.h"
+#include "pg_get_known_coin.h"
+#include "pg_get_kyc_rules.h"
+#include "pg_get_link_data.h"
+#include "pg_get_melt.h"
+#include "pg_get_old_coin_by_h_blind.h"
+#include "pg_get_pending_kyc_requirement_process.h"
+#include "pg_get_policy_details.h"
+#include "pg_get_purse_deposit.h"
 #include "pg_get_purse_request.h"
+#include "pg_get_ready_deposit.h"
+#include "pg_get_refresh_reveal.h"
+#include "pg_get_reserve_balance.h"
+#include "pg_get_reserve_by_h_blind.h"
 #include "pg_get_reserve_history.h"
+#include "pg_get_signature_for_known_coin.h"
 #include "pg_get_unfinished_close_requests.h"
+#include "pg_get_wire_accounts.h"
+#include "pg_get_wire_fee.h"
+#include "pg_get_wire_fees.h"
+#include "pg_get_wire_hash_for_contract.h"
+#include "pg_get_withdraw_info.h"
+#include "pg_have_deposit2.h"
+#include "pg_helper.h"
+#include "pg_inject_auditor_triggers.h"
+#include "pg_insert_active_legitimization_measure.h"
+#include "pg_insert_aml_decision.h"
+#include "pg_insert_aml_officer.h"
+#include "pg_insert_auditor.h"
+#include "pg_insert_auditor_denom_sig.h"
 #include "pg_insert_close_request.h"
+#include "pg_insert_contract.h"
+#include "pg_insert_denomination_info.h"
+#include "pg_insert_denomination_revocation.h"
+#include "pg_insert_drain_profit.h"
+#include "pg_insert_global_fee.h"
+#include "pg_insert_kyc_failure.h"
+#include "pg_insert_kyc_measure_result.h"
+#include "pg_insert_kyc_requirement_process.h"
+#include "pg_insert_partner.h"
+#include "pg_insert_purse_request.h"
 #include "pg_insert_records_by_table.h"
+#include "pg_insert_refresh_reveal.h"
+#include "pg_insert_refund.h"
+#include "pg_insert_reserve_closed.h"
 #include "pg_insert_reserve_open_deposit.h"
-#include "pg_get_pending_kyc_requirement_process.h"
+#include "pg_insert_signkey_revocation.h"
+#include "pg_insert_successor_measure.h"
+#include "pg_insert_wire.h"
+#include "pg_insert_wire_fee.h"
+#include "pg_iterate_active_auditors.h"
+#include "pg_iterate_active_signkeys.h"
+#include "pg_iterate_auditor_denominations.h"
+#include "pg_iterate_denomination_info.h"
+#include "pg_iterate_denominations.h"
 #include "pg_iterate_kyc_reference.h"
 #include "pg_iterate_reserve_close_info.h"
-#include "pg_lookup_records_by_table.h"
-#include "pg_lookup_kyc_status_by_token.h"
-#include "pg_lookup_serial_by_table.h"
-#include "pg_select_deposit_amounts_for_kyc_check.h"
-#include "pg_lookup_pending_legitimization.h"
-#include "pg_lookup_completed_legitimization.h"
-#include "pg_lookup_active_legitimization.h"
-#include "pg_select_account_merges_above_serial_id.h"
-#include "pg_select_all_purse_decisions_above_serial_id.h"
-#include "pg_select_purse.h"
-#include "pg_select_aml_attributes.h"
-#include "pg_trigger_kyc_rule_for_account.h"
-#include "pg_select_purse_deposits_above_serial_id.h"
-#include "pg_select_purse_merges_above_serial_id.h"
-#include "pg_select_purse_requests_above_serial_id.h"
-#include "pg_select_reserve_close_info.h"
-#include "pg_select_reserve_closed_above_serial_id.h"
-#include "pg_select_reserve_open_above_serial_id.h"
-#include "pg_insert_purse_request.h"
-#include "pg_iterate_active_signkeys.h"
-#include "pg_preflight.h"
-#include "pg_select_aml_statistics.h"
-#include "pg_commit.h"
-#include "pg_wad_in_insert.h"
-#include "pg_kycauth_in_insert.h"
-#include "pg_drop_tables.h"
-#include "pg_get_kyc_rules.h"
-#include "pg_select_aggregation_amounts_for_kyc_check.h"
 #include "pg_kyc_provider_account_lookup.h"
-#include "pg_lookup_kyc_process_by_account.h"
-#include "pg_update_kyc_process_by_row.h"
-#include "pg_insert_kyc_requirement_process.h"
-#include "pg_select_withdraw_amounts_for_kyc_check.h"
-#include "pg_insert_active_legitimization_measure.h"
-#include "pg_select_merge_amounts_for_kyc_check.h"
-#include "pg_profit_drains_set_finished.h"
-#include "pg_profit_drains_get_pending.h"
-#include "pg_get_drain_profit.h"
-#include "pg_get_purse_deposit.h"
-#include "pg_insert_contract.h"
-#include "pg_insert_kyc_failure.h"
-#include "pg_select_contract.h"
-#include "pg_select_purse_merge.h"
-#include "pg_select_contract_by_purse.h"
-#include "pg_insert_drain_profit.h"
-#include "pg_do_reserve_purse.h"
+#include "pg_kycauth_in_insert.h"
+#include "pg_lookup_active_legitimization.h"
 #include "pg_lookup_aml_history.h"
-#include "pg_lookup_kyc_history.h"
+#include "pg_lookup_aml_officer.h"
+#include "pg_lookup_auditor_status.h"
+#include "pg_lookup_auditor_timestamp.h"
+#include "pg_lookup_completed_legitimization.h"
+#include "pg_lookup_denomination_key.h"
 #include "pg_lookup_global_fee_by_time.h"
-#include "pg_do_purse_deposit.h"
-#include "pg_activate_signing_key.h"
-#include "pg_update_auditor.h"
-#include "pg_begin_revolving_shard.h"
-#include "pg_get_extension_manifest.h"
-#include "pg_do_purse_delete.h"
-#include "pg_do_purse_merge.h"
-#include "pg_start_read_committed.h"
-#include "pg_start_read_only.h"
-#include "pg_insert_denomination_info.h"
-#include "pg_do_batch_withdraw_insert.h"
+#include "pg_lookup_h_payto_by_access_token.h"
+#include "pg_lookup_kyc_history.h"
+#include "pg_lookup_kyc_process_by_account.h"
+#include "pg_lookup_kyc_requirement_by_row.h"
+#include "pg_lookup_kyc_status_by_token.h"
+#include "pg_lookup_pending_legitimization.h"
+#include "pg_lookup_records_by_table.h"
+#include "pg_lookup_rules_by_access_token.h"
+#include "pg_lookup_serial_by_table.h"
+#include "pg_lookup_signing_key.h"
+#include "pg_lookup_signkey_revocation.h"
+#include "pg_lookup_transfer_by_deposit.h"
 #include "pg_lookup_wire_fee_by_time.h"
-#include "pg_start.h"
-#include "pg_rollback.h"
-#include "pg_create_tables.h"
-#include "pg_event_listen.h"
-#include "pg_event_listen_cancel.h"
-#include "pg_event_notify.h"
-#include "pg_get_denomination_info.h"
-#include "pg_iterate_denomination_info.h"
-#include "pg_iterate_denominations.h"
-#include "pg_iterate_active_auditors.h"
-#include "pg_iterate_auditor_denominations.h"
+#include "pg_lookup_wire_timestamp.h"
+#include "pg_lookup_wire_transfer.h"
+#include "pg_persist_policy_details.h"
+#include "pg_preflight.h"
+#include "pg_profit_drains_get_pending.h"
+#include "pg_profit_drains_set_finished.h"
+#include "pg_release_revolving_shard.h"
 #include "pg_reserves_get.h"
 #include "pg_reserves_get_origin.h"
-#include "pg_drain_kyc_alert.h"
 #include "pg_reserves_in_insert.h"
-#include "pg_get_withdraw_info.h"
-#include "pg_get_age_withdraw.h"
-#include "pg_do_batch_withdraw.h"
-#include "pg_do_age_withdraw.h"
-#include "pg_get_policy_details.h"
-#include "pg_persist_policy_details.h"
-#include "pg_do_deposit.h"
-#include "pg_get_wire_hash_for_contract.h"
-#include "pg_add_policy_fulfillment_proof.h"
-#include "pg_do_melt.h"
-#include "pg_do_refund.h"
-#include "pg_do_recoup.h"
-#include "pg_do_recoup_refresh.h"
-#include "pg_get_reserve_balance.h"
-#include "pg_count_known_coins.h"
-#include "pg_ensure_coin_known.h"
-#include "pg_get_known_coin.h"
-#include "pg_get_signature_for_known_coin.h"
-#include "pg_get_coin_denomination.h"
-#include "pg_have_deposit2.h"
-#include "pg_aggregate.h"
-#include "pg_create_aggregation_transient.h"
+#include "pg_reserves_update.h"
+#include "pg_rollback.h"
+#include "pg_select_account_merges_above_serial_id.h"
+#include "pg_select_aggregation_amounts_for_kyc_check.h"
 #include "pg_select_aggregation_transient.h"
-#include "pg_find_aggregation_transient.h"
-#include "pg_update_aggregation_transient.h"
-#include "pg_get_ready_deposit.h"
-#include "pg_insert_refund.h"
-#include "pg_select_refunds_by_coin.h"
-#include "pg_get_melt.h"
-#include "pg_insert_refresh_reveal.h"
-#include "pg_get_refresh_reveal.h"
-#include "pg_lookup_wire_transfer.h"
-#include "pg_lookup_transfer_by_deposit.h"
-#include "pg_insert_wire_fee.h"
-#include "pg_insert_global_fee.h"
-#include "pg_get_wire_fee.h"
-#include "pg_get_global_fee.h"
-#include "pg_get_global_fees.h"
-#include "pg_insert_reserve_closed.h"
-#include "pg_wire_prepare_data_insert.h"
-#include "pg_wire_prepare_data_mark_finished.h"
-#include "pg_wire_prepare_data_mark_failed.h"
-#include "pg_wire_prepare_data_get.h"
-#include "pg_start_deferred_wire_out.h"
-#include "pg_store_wire_transfer_out.h"
-#include "pg_gc.h"
-#include "pg_inject_auditor_triggers.h"
+#include "pg_select_aggregations_above_serial.h"
+#include "pg_select_all_purse_decisions_above_serial_id.h"
+#include "pg_select_aml_attributes.h"
+#include "pg_select_aml_decisions.h"
+#include "pg_select_aml_measures.h"
+#include "pg_select_aml_statistics.h"
+#include "pg_select_auditor_denom_sig.h"
+#include "pg_select_batch_deposits_missing_wire.h"
 #include "pg_select_coin_deposits_above_serial_id.h"
+#include "pg_select_contract.h"
+#include "pg_select_contract_by_purse.h"
+#include "pg_select_deposit_amounts_for_kyc_check.h"
+#include "pg_select_kyc_attributes.h"
+#include "pg_select_merge_amounts_for_kyc_check.h"
+#include "pg_select_purse.h"
+#include "pg_select_purse_by_merge_pub.h"
 #include "pg_select_purse_decisions_above_serial_id.h"
+#include "pg_select_purse_deposits_above_serial_id.h"
 #include "pg_select_purse_deposits_by_purse.h"
+#include "pg_select_purse_merge.h"
+#include "pg_select_purse_merges_above_serial_id.h"
+#include "pg_select_purse_requests_above_serial_id.h"
+#include "pg_select_recoup_above_serial_id.h"
+#include "pg_select_recoup_refresh_above_serial_id.h"
 #include "pg_select_refreshes_above_serial_id.h"
 #include "pg_select_refunds_above_serial_id.h"
+#include "pg_select_refunds_by_coin.h"
+#include "pg_select_reserve_close_info.h"
+#include "pg_select_reserve_closed_above_serial_id.h"
+#include "pg_select_reserve_open_above_serial_id.h"
 #include "pg_select_reserves_in_above_serial_id.h"
 #include "pg_select_reserves_in_above_serial_id_by_account.h"
-#include "pg_select_withdrawals_above_serial_id.h"
 #include "pg_select_wire_out_above_serial_id.h"
 #include "pg_select_wire_out_above_serial_id_by_account.h"
-#include "pg_select_recoup_above_serial_id.h"
-#include "pg_select_recoup_refresh_above_serial_id.h"
-#include "pg_get_reserve_by_h_blind.h"
-#include "pg_get_old_coin_by_h_blind.h"
-#include "pg_insert_denomination_revocation.h"
-#include "pg_get_denomination_revocation.h"
-#include "pg_select_batch_deposits_missing_wire.h"
-#include "pg_select_aggregations_above_serial.h"
-#include "pg_lookup_auditor_timestamp.h"
-#include "pg_lookup_auditor_status.h"
-#include "pg_insert_auditor.h"
-#include "pg_lookup_wire_timestamp.h"
-#include "pg_insert_wire.h"
-#include "pg_update_wire.h"
-#include "pg_get_wire_accounts.h"
-#include "pg_get_wire_fees.h"
-#include "pg_insert_signkey_revocation.h"
-#include "pg_lookup_signkey_revocation.h"
-#include "pg_lookup_denomination_key.h"
-#include "pg_insert_auditor_denom_sig.h"
-#include "pg_select_auditor_denom_sig.h"
-#include "pg_add_denomination_key.h"
-#include "pg_lookup_signing_key.h"
-#include "pg_begin_shard.h"
-#include "pg_abort_shard.h"
-#include "pg_complete_shard.h"
-#include "pg_release_revolving_shard.h"
-#include "pg_delete_shard_locks.h"
+#include "pg_select_withdraw_amounts_for_kyc_check.h"
+#include "pg_select_withdrawals_above_serial_id.h"
 #include "pg_set_extension_manifest.h"
-#include "pg_insert_partner.h"
-#include "pg_expire_purse.h"
-#include "pg_select_purse_by_merge_pub.h"
 #include "pg_set_purse_balance.h"
-#include "pg_reserves_update.h"
-#include "pg_compute_shard.h"
-#include "pg_insert_kyc_measure_result.h"
-#include "pg_select_kyc_attributes.h"
-#include "pg_insert_aml_officer.h"
+#include "pg_start.h"
+#include "pg_start_deferred_wire_out.h"
+#include "pg_start_read_committed.h"
+#include "pg_start_read_only.h"
+#include "pg_store_wire_transfer_out.h"
 #include "pg_test_aml_officer.h"
-#include "pg_lookup_aml_officer.h"
-#include "pg_lookup_kyc_requirement_by_row.h"
-#include "pg_insert_aml_decision.h"
-#include "pg_insert_successor_measure.h"
-#include "pg_batch_ensure_coin_known.h"
+#include "pg_trigger_kyc_rule_for_account.h"
+#include "pg_update_aggregation_transient.h"
+#include "pg_update_auditor.h"
+#include "pg_update_kyc_process_by_row.h"
+#include "pg_update_wire.h"
+#include "pg_wad_in_insert.h"
+#include "pg_wire_prepare_data_get.h"
+#include "pg_wire_prepare_data_insert.h"
+#include "pg_wire_prepare_data_mark_failed.h"
+#include "pg_wire_prepare_data_mark_finished.h"
+#include "plugin_exchangedb_common.h"
 #include "plugin_exchangedb_postgres.h"
+#include "taler_dbevents.h"
+#include "taler_error_codes.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler_json_lib.h"
+#include "taler_pq_lib.h"
+#include "taler_util.h"
 
 /**
  * Set to 1 to enable Postgres auto_explain module. This will
@@ -588,6 +589,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
     = &TEH_PG_insert_refund;
   plugin->select_refunds_by_coin
     = &TEH_PG_select_refunds_by_coin;
+  plugin->select_aml_measures
+    = &TEH_PG_select_aml_measures;
   plugin->get_melt
     = &TEH_PG_get_melt;
   plugin->insert_refresh_reveal
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index fd750ff3d..3b155dab7 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -3172,6 +3172,26 @@ typedef void
   const void *encrypted_attributes);
 
 
+/**
+ * Function called with legitimization measures.
+ *
+ * @param cls closure
+ * @param h_payto hash of account the measure applies to
+ * @param start_time when was the process started
+ * @param jmeasures array of measures that are active
+ * @param is_finished true if the measure was finished
+ * @param measure_serial_id row ID of the measure in the exchange table
+ */
+typedef void
+(*TALER_EXCHANGEDB_LegitimizationMeasureCallback) (
+  void *cls,
+  struct TALER_NormalizedPaytoHashP *h_payto,
+  struct GNUNET_TIME_Timestamp start_time,
+  const json_t *jmeasures,
+  bool is_finished,
+  uint64_t measure_serial_id);
+
+
 /**
  * Provide information about wire fees.
  *
@@ -3341,12 +3361,13 @@ typedef bool
  * @return #GNUNET_OK to continue, #GNUNET_SYSERR to stop iteration
  */
 typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_WirePreparationCallback)(void *cls,
-                                            uint64_t rowid,
-                                            const char *wire_method,
-                                            const char *buf,
-                                            size_t buf_size,
-                                            int finished);
+(*TALER_EXCHANGEDB_WirePreparationCallback)(
+  void *cls,
+  uint64_t rowid,
+  const char *wire_method,
+  const char *buf,
+  size_t buf_size,
+  int finished);
 
 
 /**
@@ -7348,6 +7369,31 @@ struct TALER_EXCHANGEDB_Plugin
     void *cb_cls);
 
 
+  /**
+   * Lookup legitimization measures.
+   *
+   * @param cls closure
+   * @param h_payto account for which the attribute data is stored,
+   *                NULL to select for all accounts
+   * @param finished_only select only measures that are finished
+   * @param offset row offset to select from
+   * @param limit number of results to return, negative to
+   *               return in descending order from @a offset
+   * @param cb callback to invoke on each match
+   * @param cb_cls closure for @a cb
+   * @return database transaction status
+   */
+  enum GNUNET_DB_QueryStatus
+    (*select_aml_measures)(
+    void *cls,
+    const struct TALER_NormalizedPaytoHashP *h_payto,
+    enum TALER_EXCHANGE_YesNoAll active_only,
+    uint64_t offset,
+    int64_t limit,
+    TALER_EXCHANGEDB_LegitimizationMeasureCallback cb,
+    void *cb_cls);
+
+
   /**
    * Insert AML staff record.
    *

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]