gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated (e5e2e394 -> b3cc2c38)


From: gnunet
Subject: [taler-merchant] branch master updated (e5e2e394 -> b3cc2c38)
Date: Thu, 19 Oct 2023 05:26:18 +0200

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

ivan-avalos pushed a change to branch master
in repository merchant.

    from e5e2e394 Factor out 15 new functions (shit job)
     new 36bbe89f Factor out 16 new functions (shit job)
     new b3cc2c38 Factor out last 6 functions (shit job)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backenddb/Makefile.am                          |   19 +
 ...k_order_wired.c => pg_delete_pending_webhook.c} |   22 +-
 ...e_login_token.h => pg_delete_pending_webhook.h} |   24 +-
 .../{pg_delete_transfer.c => pg_delete_reserve.c}  |   32 +-
 .../{pg_lookup_account.h => pg_delete_reserve.h}   |   25 +-
 .../{pg_delete_otp.c => pg_delete_webhook.c}       |   31 +-
 .../{pg_delete_product.h => pg_delete_webhook.h}   |   23 +-
 src/backenddb/pg_insert_pending_webhook.c          |   70 +
 ...ccount_by_uri.h => pg_insert_pending_webhook.h} |   33 +-
 ...ansfer.c => pg_insert_pickup_blind_signature.c} |   41 +-
 ...eserve.h => pg_insert_pickup_blind_signature.h} |   34 +-
 src/backenddb/pg_insert_reserve.c                  |   16 +
 .../{pg_insert_template.c => pg_insert_webhook.c}  |   54 +-
 .../{pg_lookup_account.h => pg_insert_webhook.h}   |   24 +-
 src/backenddb/pg_lookup_pending_reserves.c         |  146 ++
 ..._order_wired.h => pg_lookup_pending_reserves.h} |   18 +-
 src/backenddb/pg_lookup_pending_webhooks.c         |  261 +++
 src/backenddb/pg_lookup_pending_webhooks.h         |   78 +
 src/backenddb/pg_lookup_pickup.c                   |  174 ++
 src/backenddb/pg_lookup_pickup.h                   |   52 +
 src/backenddb/pg_lookup_reserve.c                  |  241 +++
 .../{pg_lookup_account.h => pg_lookup_reserve.h}   |   26 +-
 src/backenddb/pg_lookup_reward.c                   |   84 +
 src/backenddb/pg_lookup_reward.h                   |   53 +
 src/backenddb/pg_lookup_reward_details.c           |  208 ++
 src/backenddb/pg_lookup_reward_details.h           |   57 +
 src/backenddb/pg_lookup_rewards.c                  |  221 +++
 .../{pg_lookup_account.h => pg_lookup_rewards.h}   |   31 +-
 src/backenddb/pg_lookup_webhook.c                  |   92 +
 .../{pg_lookup_account.h => pg_lookup_webhook.h}   |   25 +-
 src/backenddb/pg_lookup_webhook_by_event.c         |  158 ++
 ...sfer_details.h => pg_lookup_webhook_by_event.h} |   34 +-
 .../{pg_lookup_products.c => pg_lookup_webhooks.c} |   64 +-
 .../{pg_lookup_products.h => pg_lookup_webhooks.h} |   20 +-
 ...{pg_delete_login_token.c => pg_purge_reserve.c} |   33 +-
 .../{pg_mark_order_wired.h => pg_purge_reserve.h}  |   23 +-
 ...k_order_wired.c => pg_update_pending_webhook.c} |   25 +-
 ...e_login_token.h => pg_update_pending_webhook.h} |   25 +-
 .../{pg_update_account.c => pg_update_webhook.c}   |   55 +-
 .../{pg_update_template.h => pg_update_webhook.h}  |   31 +-
 src/backenddb/plugin_merchantdb_postgres.c         | 2069 +-------------------
 41 files changed, 2383 insertions(+), 2369 deletions(-)
 copy src/backenddb/{pg_mark_order_wired.c => pg_delete_pending_webhook.c} (68%)
 copy src/backenddb/{pg_delete_login_token.h => pg_delete_pending_webhook.h} 
(63%)
 copy src/backenddb/{pg_delete_transfer.c => pg_delete_reserve.c} (65%)
 copy src/backenddb/{pg_lookup_account.h => pg_delete_reserve.h} (62%)
 copy src/backenddb/{pg_delete_otp.c => pg_delete_webhook.c} (68%)
 copy src/backenddb/{pg_delete_product.h => pg_delete_webhook.h} (64%)
 create mode 100644 src/backenddb/pg_insert_pending_webhook.c
 copy src/backenddb/{pg_select_account_by_uri.h => pg_insert_pending_webhook.h} 
(50%)
 copy src/backenddb/{pg_delete_transfer.c => 
pg_insert_pickup_blind_signature.c} (53%)
 copy src/backenddb/{pg_activate_reserve.h => 
pg_insert_pickup_blind_signature.h} (51%)
 copy src/backenddb/{pg_insert_template.c => pg_insert_webhook.c} (54%)
 copy src/backenddb/{pg_lookup_account.h => pg_insert_webhook.h} (63%)
 create mode 100644 src/backenddb/pg_lookup_pending_reserves.c
 copy src/backenddb/{pg_mark_order_wired.h => pg_lookup_pending_reserves.h} 
(64%)
 create mode 100644 src/backenddb/pg_lookup_pending_webhooks.c
 create mode 100644 src/backenddb/pg_lookup_pending_webhooks.h
 create mode 100644 src/backenddb/pg_lookup_pickup.c
 create mode 100644 src/backenddb/pg_lookup_pickup.h
 create mode 100644 src/backenddb/pg_lookup_reserve.c
 copy src/backenddb/{pg_lookup_account.h => pg_lookup_reserve.h} (57%)
 create mode 100644 src/backenddb/pg_lookup_reward.c
 create mode 100644 src/backenddb/pg_lookup_reward.h
 create mode 100644 src/backenddb/pg_lookup_reward_details.c
 create mode 100644 src/backenddb/pg_lookup_reward_details.h
 create mode 100644 src/backenddb/pg_lookup_rewards.c
 copy src/backenddb/{pg_lookup_account.h => pg_lookup_rewards.h} (54%)
 create mode 100644 src/backenddb/pg_lookup_webhook.c
 copy src/backenddb/{pg_lookup_account.h => pg_lookup_webhook.h} (60%)
 create mode 100644 src/backenddb/pg_lookup_webhook_by_event.c
 copy src/backenddb/{pg_lookup_transfer_details.h => 
pg_lookup_webhook_by_event.h} (55%)
 copy src/backenddb/{pg_lookup_products.c => pg_lookup_webhooks.c} (62%)
 copy src/backenddb/{pg_lookup_products.h => pg_lookup_webhooks.h} (68%)
 copy src/backenddb/{pg_delete_login_token.c => pg_purge_reserve.c} (66%)
 copy src/backenddb/{pg_mark_order_wired.h => pg_purge_reserve.h} (57%)
 copy src/backenddb/{pg_mark_order_wired.c => pg_update_pending_webhook.c} (61%)
 copy src/backenddb/{pg_delete_login_token.h => pg_update_pending_webhook.h} 
(60%)
 copy src/backenddb/{pg_update_account.c => pg_update_webhook.c} (52%)
 copy src/backenddb/{pg_update_template.h => pg_update_webhook.h} (58%)

diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
index ddf24df7..258ddb75 100644
--- a/src/backenddb/Makefile.am
+++ b/src/backenddb/Makefile.am
@@ -147,6 +147,25 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \
   pg_lookup_transfer.h pg_lookup_transfer.c \
   pg_lookup_transfer_summary.h pg_lookup_transfer_summary.c \
   pg_lookup_transfer_details.h pg_lookup_transfer_details.c \
+  pg_lookup_pending_reserves.h pg_lookup_pending_reserves.c \
+  pg_lookup_reserve.h pg_lookup_reserve.c \
+  pg_delete_reserve.h pg_delete_reserve.c \
+  pg_purge_reserve.h pg_purge_reserve.c \
+  pg_lookup_pickup.h pg_lookup_pickup.c \
+  pg_lookup_reward.h pg_lookup_reward.c \
+  pg_lookup_rewards.h pg_lookup_rewards.c \
+  pg_lookup_reward_details.h pg_lookup_reward_details.c \
+  pg_insert_pickup_blind_signature.h pg_insert_pickup_blind_signature.c \
+  pg_lookup_webhooks.h pg_lookup_webhooks.c \
+  pg_lookup_webhook.h pg_lookup_webhook.c \
+  pg_delete_webhook.h pg_delete_webhook.c \
+  pg_insert_webhook.h pg_insert_webhook.c \
+  pg_update_webhook.h pg_update_webhook.c \
+  pg_lookup_webhook_by_event.h pg_lookup_webhook_by_event.c \
+  pg_delete_pending_webhook.h pg_delete_pending_webhook.c \
+  pg_insert_pending_webhook.h pg_insert_pending_webhook.c \
+  pg_update_pending_webhook.h pg_update_pending_webhook.c \
+  pg_lookup_pending_webhooks.h pg_lookup_pending_webhooks.c \
   plugin_merchantdb_postgres.c \
   pg_helper.h pg_helper.c
 libtaler_plugin_merchantdb_postgres_la_LIBADD = \
diff --git a/src/backenddb/pg_mark_order_wired.c 
b/src/backenddb/pg_delete_pending_webhook.c
similarity index 68%
copy from src/backenddb/pg_mark_order_wired.c
copy to src/backenddb/pg_delete_pending_webhook.c
index fde1ecc7..9121fe41 100644
--- a/src/backenddb/pg_mark_order_wired.c
+++ b/src/backenddb/pg_delete_pending_webhook.c
@@ -14,35 +14,35 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_mark_order_wired.c
- * @brief Implementation of the mark_order_wired function for Postgres
+ * @file backenddb/pg_delete_pending_webhook.c
+ * @brief Implementation of the delete_pending_webhook function for Postgres
  * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_mark_order_wired.h"
+#include "pg_delete_pending_webhook.h"
 #include "pg_helper.h"
 
 enum GNUNET_DB_QueryStatus
-TMH_PG_mark_order_wired (void *cls,
-                         uint64_t order_serial)
+TMH_PG_delete_pending_webhook (void *cls,
+                               uint64_t webhook_pending_serial)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_uint64 (&order_serial),
+    GNUNET_PQ_query_param_uint64 (&webhook_pending_serial),
     GNUNET_PQ_query_param_end
   };
 
   check_connection (pg);
   PREPARE (pg,
-           "mark_order_wired",
-           "UPDATE merchant_contract_terms SET"
-           " wired=TRUE"
-           " WHERE order_serial=$1");
+           "delete_pending_webhook",
+           "DELETE"
+           " FROM merchant_pending_webhooks"
+           " WHERE webhook_pending_serial=$1");
 
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "mark_order_wired",
+                                             "delete_pending_webhook",
                                              params);
 }
diff --git a/src/backenddb/pg_delete_login_token.h 
b/src/backenddb/pg_delete_pending_webhook.h
similarity index 63%
copy from src/backenddb/pg_delete_login_token.h
copy to src/backenddb/pg_delete_pending_webhook.h
index 0ae9f56b..1247cf4e 100644
--- a/src/backenddb/pg_delete_login_token.h
+++ b/src/backenddb/pg_delete_pending_webhook.h
@@ -14,31 +14,27 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_delete_login_token.h
- * @brief implementation of the delete_login_token function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_delete_pending_webhook.h
+ * @brief implementation of the delete_pending_webhook function for Postgres
+ * @author Iván Ávalos
  */
-#ifndef PG_DELETE_LOGIN_TOKEN_H
-#define PG_DELETE_LOGIN_TOKEN_H
+#ifndef PG_DELETE_PENDING_WEBHOOK_H
+#define PG_DELETE_PENDING_WEBHOOK_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
-
 /**
- * Delete login token from database.
+ * Delete a webhook in the pending webhook after the
+ * webhook was completed successfully.
  *
  * @param cls closure
- * @param id identifier of the instance
- * @param token value of the token
+ * @param webhook_pending_serial identifies the row that needs to be deleted 
in the pending webhook table
  * @return database result code
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_delete_login_token (
-  void *cls,
-  const char *id,
-  const struct TALER_MERCHANTDB_LoginTokenP *token);
-
+TMH_PG_delete_pending_webhook (void *cls,
+                               uint64_t webhook_pending_serial);
 
 #endif
diff --git a/src/backenddb/pg_delete_transfer.c 
b/src/backenddb/pg_delete_reserve.c
similarity index 65%
copy from src/backenddb/pg_delete_transfer.c
copy to src/backenddb/pg_delete_reserve.c
index f23d97fa..f31e7c7a 100644
--- a/src/backenddb/pg_delete_transfer.c
+++ b/src/backenddb/pg_delete_reserve.c
@@ -14,44 +14,44 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_delete_transfer.c
- * @brief Implementation of the delete_transfer function for Postgres
+ * @file backenddb/pg_delete_reserve.c
+ * @brief Implementation of the delete_reserve function for Postgres
  * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_delete_transfer.h"
+#include "pg_delete_reserve.h"
 #include "pg_helper.h"
 
 enum GNUNET_DB_QueryStatus
-TMH_PG_delete_transfer (void *cls,
-                        const char *instance_id,
-                        uint64_t transfer_serial_id)
+TMH_PG_delete_reserve (void *cls,
+                       const char *instance_id,
+                       const struct TALER_ReservePublicKeyP *reserve_pub)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_uint64 (&transfer_serial_id),
+    GNUNET_PQ_query_param_auto_from_type (reserve_pub),
     GNUNET_PQ_query_param_end
   };
 
   check_connection (pg);
   PREPARE (pg,
-           "delete_transfer",
-           "DELETE FROM merchant_transfers"
-           " WHERE"
-           "   credit_serial=$2"
-           "  AND account_serial IN "
-           "  (SELECT account_serial "
-           "     FROM merchant_accounts"
-           "    WHERE merchant_serial="
+           "delete_reserve",
+           "DELETE"
+           " FROM merchant_reward_reserve_keys"
+           " WHERE reserve_serial="
+           "   (SELECT reserve_serial"
+           "      FROM merchant_reward_reserves"
+           "       WHERE reserve_pub=$2"
+           "         AND merchant_serial="
            "     (SELECT merchant_serial"
            "        FROM merchant_instances"
            "       WHERE merchant_id=$1))");
 
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "delete_transfer",
+                                             "delete_reserve",
                                              params);
 }
diff --git a/src/backenddb/pg_lookup_account.h 
b/src/backenddb/pg_delete_reserve.h
similarity index 62%
copy from src/backenddb/pg_lookup_account.h
copy to src/backenddb/pg_delete_reserve.h
index 63b0aa73..f3aa2403 100644
--- a/src/backenddb/pg_lookup_account.h
+++ b/src/backenddb/pg_delete_reserve.h
@@ -14,30 +14,29 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_account.h
- * @brief implementation of the lookup_account function for Postgres
+ * @file backenddb/pg_delete_reserve.h
+ * @brief implementation of the delete_reserve function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_LOOKUP_ACCOUNT_H
-#define PG_LOOKUP_ACCOUNT_H
+#ifndef PG_DELETE_RESERVE_H
+#define PG_DELETE_RESERVE_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Lookup account serial by payto URI.
+ * Delete a reserve's private key.
  *
- * @param cls closure
- * @param instance_id instance to lookup the account from
- * @param payto_uri what is the merchant's bank account to lookup
- * @param[out] account_serial serial number of the account
- * @return transaction status
+ * @param cls closure, typically a connection to the db
+ * @param instance_id which instance is the reserve tied to
+ * @param reserve_pub which reserve is to be deleted
+ * @return transaction status, usually
+ *      #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_account (void *cls,
+TMH_PG_delete_reserve (void *cls,
                        const char *instance_id,
-                       const char *payto_uri,
-                       uint64_t *account_serial);
+                       const struct TALER_ReservePublicKeyP *reserve_pub);
 
 #endif
diff --git a/src/backenddb/pg_delete_otp.c b/src/backenddb/pg_delete_webhook.c
similarity index 68%
copy from src/backenddb/pg_delete_otp.c
copy to src/backenddb/pg_delete_webhook.c
index 7d32b3fb..ba2173cb 100644
--- a/src/backenddb/pg_delete_otp.c
+++ b/src/backenddb/pg_delete_webhook.c
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2023 Taler Systems SA
 
    TALER is free software; you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free Software
@@ -14,42 +14,41 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_delete_otp.c
- * @brief Implementation of the delete_otp function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_delete_webhook.c
+ * @brief Implementation of the delete_webhook function for Postgres
+ * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_delete_otp.h"
+#include "pg_delete_webhook.h"
 #include "pg_helper.h"
 
-
 enum GNUNET_DB_QueryStatus
-TMH_PG_delete_otp (void *cls,
-                   const char *instance_id,
-                   const char *otp_id)
+TMH_PG_delete_webhook (void *cls,
+                       const char *instance_id,
+                       const char *webhook_id)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_string (otp_id),
+    GNUNET_PQ_query_param_string (webhook_id),
     GNUNET_PQ_query_param_end
   };
 
   check_connection (pg);
   PREPARE (pg,
-           "delete_otp",
+           "delete_webhook",
            "DELETE"
-           " FROM merchant_otp_devices"
-           " WHERE merchant_otp_devices.merchant_serial="
+           " FROM merchant_webhook"
+           " WHERE merchant_webhook.merchant_serial="
            "     (SELECT merchant_serial "
            "        FROM merchant_instances"
            "        WHERE merchant_id=$1)"
-           "   AND merchant_otp_devices.template_id=$2");
+           "   AND merchant_webhook.webhook_id=$2");
+
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "delete_otp",
+                                             "delete_webhook",
                                              params);
 }
-
diff --git a/src/backenddb/pg_delete_product.h 
b/src/backenddb/pg_delete_webhook.h
similarity index 64%
copy from src/backenddb/pg_delete_product.h
copy to src/backenddb/pg_delete_webhook.h
index c88e46f4..02f021ab 100644
--- a/src/backenddb/pg_delete_product.h
+++ b/src/backenddb/pg_delete_webhook.h
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2023 Taler Systems SA
 
    TALER is free software; you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free Software
@@ -14,30 +14,29 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_delete_product.h
- * @brief implementation of the delete_product function for Postgres
+ * @file backenddb/pg_delete_webhook.h
+ * @brief implementation of the delete_webhook function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_DELETE_PRODUCT_H
-#define PG_DELETE_PRODUCT_H
+#ifndef PG_DELETE_WEBHOOK_H
+#define PG_DELETE_WEBHOOK_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Delete information about a product.  Note that the transaction must
- * enforce that no stocks are currently locked.
+ * Delete information about a webhook.
  *
  * @param cls closure
- * @param instance_id instance to delete product of
- * @param product_id product to delete
+ * @param instance_id instance to delete webhook of
+ * @param webhook_id webhook to delete
  * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
- *           if locks prevent deletion OR product unknown
+ *           if webhook unknown.
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_delete_product (void *cls,
+TMH_PG_delete_webhook (void *cls,
                        const char *instance_id,
-                       const char *product_id);
+                       const char *webhook_id);
 
 #endif
diff --git a/src/backenddb/pg_insert_pending_webhook.c 
b/src/backenddb/pg_insert_pending_webhook.c
new file mode 100644
index 00000000..abb3234f
--- /dev/null
+++ b/src/backenddb/pg_insert_pending_webhook.c
@@ -0,0 +1,70 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_insert_pending_webhook.c
+ * @brief Implementation of the insert_pending_webhook function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_insert_pending_webhook.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_insert_pending_webhook (void *cls,
+                               const char *instance_id,
+                               uint64_t webhook_serial,
+                               const char *url,
+                               const char *http_method,
+                               const char *header,
+                               const char *body)
+{
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_uint64 (&webhook_serial),
+    GNUNET_PQ_query_param_string (url),
+    GNUNET_PQ_query_param_string (http_method),
+    NULL == header
+    ? GNUNET_PQ_query_param_null ()
+    : GNUNET_PQ_query_param_string (header),
+    NULL == body
+    ? GNUNET_PQ_query_param_null ()
+    : GNUNET_PQ_query_param_string (body),
+    GNUNET_PQ_query_param_end
+  };
+  check_connection (pg);
+  PREPARE (pg,
+           "insert_pending_webhook",
+           "INSERT INTO merchant_pending_webhooks"
+           "(merchant_serial"
+           ",webhook_serial"
+           ",url"
+           ",http_method"
+           ",header"
+           ",body"
+           ")"
+           " SELECT mi.merchant_serial,"
+           " $2, $3, $4, $5, $6"
+           " FROM merchant_instances mi"
+           " WHERE mi.merchant_id=$1");
+
+  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+                                             "insert_pending_webhook",
+                                             params);
+}
diff --git a/src/backenddb/pg_select_account_by_uri.h 
b/src/backenddb/pg_insert_pending_webhook.h
similarity index 50%
copy from src/backenddb/pg_select_account_by_uri.h
copy to src/backenddb/pg_insert_pending_webhook.h
index 718209be..0107fd2c 100644
--- a/src/backenddb/pg_select_account_by_uri.h
+++ b/src/backenddb/pg_insert_pending_webhook.h
@@ -14,31 +14,36 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_select_account_by_uri.h
- * @brief implementation of the select_account_by_uri function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_insert_pending_webhook.h
+ * @brief implementation of the insert_pending_webhook function for Postgres
+ * @author Iván Ávalos
  */
-#ifndef PG_SELECT_ACCOUNT_BY_URI_H
-#define PG_SELECT_ACCOUNT_BY_URI_H
+#ifndef PG_INSERT_PENDING_WEBHOOK_H
+#define PG_INSERT_PENDING_WEBHOOK_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
-
 /**
- * Obtain information about an instance's accounts.
+ * Insert webhook in the pending webhook.
  *
  * @param cls closure
- * @param id identifier of the instance
- * @param payto_uri URI of the account
- * @param[out] ad account details returned
+ * @param instance_id instance to insert webhook for
+ * @param webhook_serial webhook to insert in the pending webhook
+ * @param url to make the request to
+ * @param http_method for the webhook
+ * @param header of the webhook
+ * @param body of the webhook
  * @return database result code
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_select_account_by_uri (void *cls,
-                              const char *id,
-                              const char *payto_uri,
-                              struct TALER_MERCHANTDB_AccountDetails *ad);
+TMH_PG_insert_pending_webhook (void *cls,
+                               const char *instance_id,
+                               uint64_t webhook_serial,
+                               const char *url,
+                               const char *http_method,
+                               const char *header,
+                               const char *body);
 
 #endif
diff --git a/src/backenddb/pg_delete_transfer.c 
b/src/backenddb/pg_insert_pickup_blind_signature.c
similarity index 53%
copy from src/backenddb/pg_delete_transfer.c
copy to src/backenddb/pg_insert_pickup_blind_signature.c
index f23d97fa..89d51346 100644
--- a/src/backenddb/pg_delete_transfer.c
+++ b/src/backenddb/pg_insert_pickup_blind_signature.c
@@ -14,44 +14,45 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_delete_transfer.c
- * @brief Implementation of the delete_transfer function for Postgres
+ * @file backenddb/pg_insert_pickup_blind_signature.c
+ * @brief Implementation of the insert_pickup_blind_signature function for 
Postgres
  * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_delete_transfer.h"
+#include "pg_insert_pickup_blind_signature.h"
 #include "pg_helper.h"
 
 enum GNUNET_DB_QueryStatus
-TMH_PG_delete_transfer (void *cls,
-                        const char *instance_id,
-                        uint64_t transfer_serial_id)
+TMH_PG_insert_pickup_blind_signature (void *cls,
+                                      const struct TALER_PickupIdentifierP 
*pickup_id,
+                                      uint32_t offset,
+                                      const struct 
TALER_BlindedDenominationSignature *blind_sig)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_uint64 (&transfer_serial_id),
+    GNUNET_PQ_query_param_auto_from_type (pickup_id),
+    GNUNET_PQ_query_param_uint32 (&offset),
+    TALER_PQ_query_param_blinded_denom_sig (blind_sig),
     GNUNET_PQ_query_param_end
   };
 
   check_connection (pg);
   PREPARE (pg,
-           "delete_transfer",
-           "DELETE FROM merchant_transfers"
-           " WHERE"
-           "   credit_serial=$2"
-           "  AND account_serial IN "
-           "  (SELECT account_serial "
-           "     FROM merchant_accounts"
-           "    WHERE merchant_serial="
-           "     (SELECT merchant_serial"
-           "        FROM merchant_instances"
-           "       WHERE merchant_id=$1))");
+           "insert_pickup_blind_signature",
+           "INSERT INTO merchant_reward_pickup_signatures"
+           "(pickup_serial"
+           ",coin_offset"
+           ",blind_sig"
+           ") "
+           "SELECT"
+           " pickup_serial, $2, $3"
+           " FROM merchant_reward_pickups"
+           " WHERE pickup_id=$1");
 
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "delete_transfer",
+                                             "insert_pickup_blind_signature",
                                              params);
 }
diff --git a/src/backenddb/pg_activate_reserve.h 
b/src/backenddb/pg_insert_pickup_blind_signature.h
similarity index 51%
copy from src/backenddb/pg_activate_reserve.h
copy to src/backenddb/pg_insert_pickup_blind_signature.h
index 3b7c8a3d..a4f98275 100644
--- a/src/backenddb/pg_activate_reserve.h
+++ b/src/backenddb/pg_insert_pickup_blind_signature.h
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2023 Taler Systems SA
 
    TALER is free software; you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free Software
@@ -14,35 +14,33 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_activate_reserve.h
- * @brief implementation of the activate_reserve function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_insert_pickup_blind_signature.h
+ * @brief implementation of the insert_pickup_blind_signature function for 
Postgres
+ * @author Iván Ávalos
  */
-#ifndef PG_ACTIVATE_RESERVE_H
-#define PG_ACTIVATE_RESERVE_H
+#ifndef PG_INSERT_PICKUP_BLIND_SIGNATURE_H
+#define PG_INSERT_PICKUP_BLIND_SIGNATURE_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
-
 /**
- * Confirms @a credit as the amount the exchange claims to have received and
- * thus really 'activates' the reserve.  This has to happen before rewards can
- * be authorized.
+ * Insert blind signature obtained from the exchange during a
+ * reward pickup operation.
  *
  * @param cls closure, typically a connection to the db
- * @param instance_id which instance is the reserve tied to
- * @param reserve_pub which reserve is topped up or created
- * @param initial_exchange_balance how much money was be added to the reserve
- *           according to the exchange
+ * @param pickup_id unique ID for the operation
+ * @param offset offset of the blind signature for the pickup
+ * @param blind_sig the blind signature
  * @return transaction status, usually
  *      #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success
+ *      #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a credit_uuid already known
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_activate_reserve (void *cls,
-                         const char *instance_id,
-                         const struct TALER_ReservePublicKeyP *reserve_pub,
-                         const struct TALER_Amount *initial_exchange_balance);
+TMH_PG_insert_pickup_blind_signature (void *cls,
+                                      const struct TALER_PickupIdentifierP 
*pickup_id,
+                                      uint32_t offset,
+                                      const struct 
TALER_BlindedDenominationSignature *blind_sig);
 
 #endif
diff --git a/src/backenddb/pg_insert_reserve.c 
b/src/backenddb/pg_insert_reserve.c
index 67e2652a..173d9304 100644
--- a/src/backenddb/pg_insert_reserve.c
+++ b/src/backenddb/pg_insert_reserve.c
@@ -115,6 +115,22 @@ RETRY:
       GNUNET_PQ_query_param_end
     };
 
+    PREPARE(pg,
+            "insert_reserve_key",
+            "INSERT INTO merchant_reward_reserve_keys"
+            "(reserve_serial"
+            ",reserve_priv"
+            ",exchange_url"
+            ",master_pub"
+            ")"
+            "SELECT reserve_serial, $3, $4, $5"
+            " FROM merchant_reward_reserves"
+            " WHERE reserve_pub=$2"
+            "   AND merchant_serial="
+            "     (SELECT merchant_serial"
+            "        FROM merchant_instances"
+            "       WHERE merchant_id=$1)");
+
     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_reserve_key",
                                              params);
diff --git a/src/backenddb/pg_insert_template.c 
b/src/backenddb/pg_insert_webhook.c
similarity index 54%
copy from src/backenddb/pg_insert_template.c
copy to src/backenddb/pg_insert_webhook.c
index 5fc76a1d..53049a43 100644
--- a/src/backenddb/pg_insert_template.c
+++ b/src/backenddb/pg_insert_webhook.c
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2023 Taler Systems SA
 
    TALER is free software; you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free Software
@@ -14,53 +14,57 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_insert_template.c
- * @brief Implementation of the insert_template function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_insert_webhook.c
+ * @brief Implementation of the insert_webhook function for Postgres
+ * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_insert_template.h"
+#include "pg_insert_webhook.h"
 #include "pg_helper.h"
 
-
 enum GNUNET_DB_QueryStatus
-TMH_PG_insert_template (void *cls,
-                        const char *instance_id,
-                        const char *template_id,
-                        uint64_t otp_serial_id,
-                        const struct TALER_MERCHANTDB_TemplateDetails *td)
+TMH_PG_insert_webhook (void *cls,
+                       const char *instance_id,
+                       const char *webhook_id,
+                       const struct TALER_MERCHANTDB_WebhookDetails *wb)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_string (template_id),
-    GNUNET_PQ_query_param_string (td->template_description),
-    (0 == otp_serial_id)
+    GNUNET_PQ_query_param_string (webhook_id),
+    GNUNET_PQ_query_param_string (wb->event_type),
+    GNUNET_PQ_query_param_string (wb->url),
+    GNUNET_PQ_query_param_string (wb->http_method),
+    (NULL == wb->header_template)
+    ? GNUNET_PQ_query_param_null ()
+    : GNUNET_PQ_query_param_string (wb->header_template),
+    (NULL == wb->body_template)
     ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_uint64 (&otp_serial_id),
-    TALER_PQ_query_param_json (td->template_contract),
+    : GNUNET_PQ_query_param_string (wb->body_template),
     GNUNET_PQ_query_param_end
   };
 
   check_connection (pg);
   PREPARE (pg,
-           "insert_template",
-           "INSERT INTO merchant_template"
+           "insert_webhook",
+           "INSERT INTO merchant_webhook"
            "(merchant_serial"
-           ",template_id"
-           ",template_description"
-           ",otp_device_id"
-           ",template_contract"
+           ",webhook_id"
+           ",event_type"
+           ",url"
+           ",http_method"
+           ",header_template"
+           ",body_template"
            ")"
            " SELECT merchant_serial,"
-           " $2, $3, $4, $5"
+           " $2, $3, $4, $5, $6, $7"
            " FROM merchant_instances"
            " WHERE merchant_id=$1");
+
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "insert_template",
+                                             "insert_webhook",
                                              params);
 }
-
diff --git a/src/backenddb/pg_lookup_account.h 
b/src/backenddb/pg_insert_webhook.h
similarity index 63%
copy from src/backenddb/pg_lookup_account.h
copy to src/backenddb/pg_insert_webhook.h
index 63b0aa73..fe89d113 100644
--- a/src/backenddb/pg_lookup_account.h
+++ b/src/backenddb/pg_insert_webhook.h
@@ -14,30 +14,30 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_account.h
- * @brief implementation of the lookup_account function for Postgres
+ * @file backenddb/pg_insert_webhook.h
+ * @brief implementation of the insert_webhook function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_LOOKUP_ACCOUNT_H
-#define PG_LOOKUP_ACCOUNT_H
+#ifndef PG_INSERT_WEBHOOK_H
+#define PG_INSERT_WEBHOOK_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Lookup account serial by payto URI.
+ * Insert details about a particular webhook.
  *
  * @param cls closure
- * @param instance_id instance to lookup the account from
- * @param payto_uri what is the merchant's bank account to lookup
- * @param[out] account_serial serial number of the account
- * @return transaction status
+ * @param instance_id instance to insert webhook for
+ * @param webhook_id webhook identifier of webhook to insert
+ * @param wb the webhook details to insert
+ * @return database result code
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_account (void *cls,
+TMH_PG_insert_webhook (void *cls,
                        const char *instance_id,
-                       const char *payto_uri,
-                       uint64_t *account_serial);
+                       const char *webhook_id,
+                       const struct TALER_MERCHANTDB_WebhookDetails *wb);
 
 #endif
diff --git a/src/backenddb/pg_lookup_pending_reserves.c 
b/src/backenddb/pg_lookup_pending_reserves.c
new file mode 100644
index 00000000..f35021c6
--- /dev/null
+++ b/src/backenddb/pg_lookup_pending_reserves.c
@@ -0,0 +1,146 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_pending_reserves.c
+ * @brief Implementation of the lookup_pending_reserves function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_pending_reserves.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #lookup_pending_reserves_cb.
+ */
+struct LookupPendingReservesContext
+{
+  /**
+   * Postgres context.
+   */
+  struct PostgresClosure *pg;
+
+  /**
+   * Function to call with the results
+   */
+  TALER_MERCHANTDB_PendingReservesCallback cb;
+
+  /**
+   * Closure for @e cb
+   */
+  void *cb_cls;
+
+  /**
+   * Set in case of errors.
+   */
+  enum GNUNET_DB_QueryStatus qs;
+
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about accounts.
+ *
+ * @param[in,out] cls of type `struct LookupReservesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_pending_reserves_cb (void *cls,
+                            PGresult *result,
+                            unsigned int num_results)
+{
+  struct LookupPendingReservesContext *lrc = cls;
+
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    struct TALER_ReservePublicKeyP reserve_pub;
+    struct TALER_Amount merchant_initial_balance;
+    char *exchange_url;
+    char *instance_id;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+                                            &reserve_pub),
+      GNUNET_PQ_result_spec_string ("merchant_id",
+                                    &instance_id),
+      GNUNET_PQ_result_spec_string ("exchange_url",
+                                    &exchange_url),
+      TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance",
+                                                 &merchant_initial_balance),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      lrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+      return;
+    }
+    lrc->cb (lrc->cb_cls,
+             instance_id,
+             exchange_url,
+             &reserve_pub,
+             &merchant_initial_balance);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_pending_reserves (void *cls,
+                                TALER_MERCHANTDB_PendingReservesCallback cb,
+                                void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct LookupPendingReservesContext lrc = {
+    .pg = pg,
+    .cb = cb,
+    .cb_cls = cb_cls
+  };
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_end
+  };
+  enum GNUNET_DB_QueryStatus qs;
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_pending_reserves",
+           "SELECT"
+           " reserve_pub"
+           ",merchant_id"
+           ",exchange_url"
+           ",merchant_initial_balance"
+           " FROM merchant_reward_reserves mrr"
+           " JOIN merchant_instances USING (merchant_serial)"
+           " JOIN merchant_reward_reserve_keys USING (reserve_serial)"
+           " WHERE (mrr.exchange_initial_balance).val=0"
+           "   AND (mrr.exchange_initial_balance).frac=0");
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             "lookup_pending_reserves",
+                                             params,
+                                             &lookup_pending_reserves_cb,
+                                             &lrc);
+  if (lrc.qs < 0)
+    return lrc.qs;
+  return qs;
+}
diff --git a/src/backenddb/pg_mark_order_wired.h 
b/src/backenddb/pg_lookup_pending_reserves.h
similarity index 64%
copy from src/backenddb/pg_mark_order_wired.h
copy to src/backenddb/pg_lookup_pending_reserves.h
index dd7cc97f..4ffff78f 100644
--- a/src/backenddb/pg_mark_order_wired.h
+++ b/src/backenddb/pg_lookup_pending_reserves.h
@@ -14,26 +14,28 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_mark_order_wired.h
- * @brief implementation of the mark_order_wired function for Postgres
+ * @file backenddb/pg_lookup_pending_reserves.h
+ * @brief implementation of the lookup_pending_reserves function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_MARK_ORDER_WIRED_H
-#define PG_MARK_ORDER_WIRED_H
+#ifndef PG_LOOKUP_PENDING_RESERVES_H
+#define PG_LOOKUP_PENDING_RESERVES_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Set 'wired' status for an order to 'true'.
+ * Lookup reserves pending activation across all instances.
  *
  * @param cls closure
- * @param order_serial serial number of the order
+ * @param cb function to call with reserve summary data
+ * @param cb_cls closure for @a cb
  * @return transaction status
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_mark_order_wired (void *cls,
-                         uint64_t order_serial);
+TMH_PG_lookup_pending_reserves (void *cls,
+                                TALER_MERCHANTDB_PendingReservesCallback cb,
+                                void *cb_cls);
 
 #endif
diff --git a/src/backenddb/pg_lookup_pending_webhooks.c 
b/src/backenddb/pg_lookup_pending_webhooks.c
new file mode 100644
index 00000000..d1d3eda9
--- /dev/null
+++ b/src/backenddb/pg_lookup_pending_webhooks.c
@@ -0,0 +1,261 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_pending_webhooks.c
+ * @brief Implementation of the lookup_pending_webhooks function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_pending_webhooks.h"
+#include "pg_helper.h"
+
+/**
+ * Context used for lookup_pending_webhooks_cb().
+ */
+struct LookupPendingWebhookContext
+{
+  /**
+   * Function to call with the results.
+   */
+  TALER_MERCHANTDB_PendingWebhooksCallback cb;
+
+  /**
+   * Closure for @a cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Did database result extraction fail?
+   */
+  bool extract_failed;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about webhook.
+ *
+ * @param[in,out] cls of type `struct LookupPendingWebhookContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_pending_webhooks_cb (void *cls,
+                            PGresult *result,
+                            unsigned int num_results)
+{
+  struct LookupPendingWebhookContext *pwlc = cls;
+
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    uint64_t webhook_pending_serial;
+    struct GNUNET_TIME_Absolute next_attempt;
+    uint32_t retries;
+    char *url;
+    char *http_method;
+    char *header = NULL;
+    char *body = NULL;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_uint64 ("webhook_pending_serial",
+                                    &webhook_pending_serial),
+      GNUNET_PQ_result_spec_absolute_time ("next_attempt",
+                                           &next_attempt),
+      GNUNET_PQ_result_spec_uint32 ("retries",
+                                    &retries),
+      GNUNET_PQ_result_spec_string ("url",
+                                    &url),
+      GNUNET_PQ_result_spec_string ("http_method",
+                                    &http_method),
+      GNUNET_PQ_result_spec_allow_null (
+        GNUNET_PQ_result_spec_string ("header",
+                                      &header),
+        NULL),
+      GNUNET_PQ_result_spec_allow_null (
+        GNUNET_PQ_result_spec_string ("body",
+                                      &body),
+        NULL),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      pwlc->extract_failed = true;
+      return;
+    }
+    pwlc->cb (pwlc->cb_cls,
+              webhook_pending_serial,
+              next_attempt,
+              retries,
+              url,
+              http_method,
+              header,
+              body);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_pending_webhooks (void *cls,
+                                TALER_MERCHANTDB_PendingWebhooksCallback cb,
+                                void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct LookupPendingWebhookContext pwlc = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .extract_failed = false,
+  };
+  struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+  struct GNUNET_PQ_QueryParam params_null[] = {
+    GNUNET_PQ_query_param_absolute_time (&now),
+    GNUNET_PQ_query_param_end
+  };
+
+  enum GNUNET_DB_QueryStatus qs;
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_pending_webhooks",
+           "SELECT"
+           " webhook_pending_serial"
+           ",next_attempt"
+           ",retries"
+           ",url"
+           ",http_method"
+           ",header"
+           ",body"
+           " FROM merchant_pending_webhooks"
+           " WHERE next_attempt <= $1"
+           "   ORDER BY next_attempt ASC"
+           );
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             "lookup_pending_webhooks",
+                                             params_null,
+                                             &lookup_pending_webhooks_cb,
+                                             &pwlc);
+
+  if (pwlc.extract_failed)
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  return qs;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_future_webhook (void *cls,
+                              TALER_MERCHANTDB_PendingWebhooksCallback cb,
+                              void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct LookupPendingWebhookContext pwlc = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .extract_failed = false,
+  };
+  struct GNUNET_PQ_QueryParam params_null[] = {
+    GNUNET_PQ_query_param_end
+  };
+
+  enum GNUNET_DB_QueryStatus qs;
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_future_webhook",
+           "SELECT"
+           " webhook_pending_serial"
+           ",next_attempt"
+           ",retries"
+           ",url"
+           ",http_method"
+           ",header"
+           ",body"
+           " FROM merchant_pending_webhooks"
+           " ORDER BY next_attempt ASC LIMIT 1"
+           );
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             "lookup_future_webhook",
+                                             params_null,
+                                             &lookup_pending_webhooks_cb,
+                                             &pwlc);
+
+  if (pwlc.extract_failed)
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  return qs;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_all_webhooks (void *cls,
+                            const char *instance_id,
+                            uint64_t min_row,
+                            uint32_t max_results,
+                            TALER_MERCHANTDB_PendingWebhooksCallback cb,
+                            void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct LookupPendingWebhookContext pwlc = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .extract_failed = false,
+  };
+  uint64_t max_results64 = max_results;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_uint64 (&min_row),
+    GNUNET_PQ_query_param_uint64 (&max_results64),
+    GNUNET_PQ_query_param_end
+  };
+
+  enum GNUNET_DB_QueryStatus qs;
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_all_webhooks",
+           " SELECT"
+           " webhook_pending_serial"
+           ",next_attempt"
+           ",retries"
+           ",url"
+           ",http_method"
+           ",header"
+           ",body"
+           " FROM merchant_pending_webhooks"
+           " JOIN merchant_instances"
+           "   USING (merchant_serial)"
+           " WHERE merchant_instances.merchant_id=$1"
+           " AND webhook_pending_serial > $2"
+           "  ORDER BY webhook_pending_serial"
+           "   ASC LIMIT $3");
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             "lookup_all_webhooks",
+                                             params,
+                                             &lookup_pending_webhooks_cb,
+                                             &pwlc);
+
+  if (pwlc.extract_failed)
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  return qs;
+}
diff --git a/src/backenddb/pg_lookup_pending_webhooks.h 
b/src/backenddb/pg_lookup_pending_webhooks.h
new file mode 100644
index 00000000..d7322f56
--- /dev/null
+++ b/src/backenddb/pg_lookup_pending_webhooks.h
@@ -0,0 +1,78 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_pending_webhooks.h
+ * @brief implementation of the lookup_pending_webhooks function for Postgres
+ * @author Iván Ávalos
+ */
+#ifndef PG_LOOKUP_PENDING_WEBHOOKS_H
+#define PG_LOOKUP_PENDING_WEBHOOKS_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Lookup the webhook that need to be send in priority.
+ * send.
+ *
+ * @param cls closure
+ * @param cb pending webhook callback
+ * @param cb_cls callback closure
+ */
+// WHERE next_attempt <= now ORDER BY next_attempt ASC
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_pending_webhooks (void *cls,
+                                TALER_MERCHANTDB_PendingWebhooksCallback cb,
+                                void *cb_cls);
+
+
+/**
+ * Lookup future webhook in the pending webhook that need to be send.
+ * With that we can know how long the system can 'sleep'.
+ *
+ * @param cls closure
+ * @param cb pending webhook callback
+ * @param cb_cls callback closure
+ */
+// ORDER BY next_attempt ASC LIMIT 1
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_future_webhook (void *cls,
+                              TALER_MERCHANTDB_PendingWebhooksCallback cb,
+                              void *cb_cls);
+
+
+/**
+   * Lookup all the webhooks in the pending webhook.
+   * Use by the administrator
+   *
+   * @param cls closure
+   * @param instance_id to lookup webhooks for this instance particularly
+   * @param min_row to see the list of the pending webhook that it is started 
with this minimum row.
+   * @param max_results to see the list of the pending webhook that it is end 
with this max results.
+   * @param cb pending webhook callback
+   * @param cb_cls callback closure
+   */
+// WHERE webhook_pending_serial > min_row ORDER BY webhook_pending_serial ASC 
LIMIT max_results
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_all_webhooks (void *cls,
+                            const char *instance_id,
+                            uint64_t min_row,
+                            uint32_t max_results,
+                            TALER_MERCHANTDB_PendingWebhooksCallback cb,
+                            void *cb_cls);
+
+#endif
diff --git a/src/backenddb/pg_lookup_pickup.c b/src/backenddb/pg_lookup_pickup.c
new file mode 100644
index 00000000..f10b948b
--- /dev/null
+++ b/src/backenddb/pg_lookup_pickup.c
@@ -0,0 +1,174 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_pickup.c
+ * @brief Implementation of the lookup_pickup function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_pickup.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #lookup_signatures_cb().
+ */
+struct LookupSignaturesContext
+{
+  /**
+   * Length of the @e sigs array
+   */
+  unsigned int sigs_length;
+
+  /**
+   * Where to store the signatures.
+   */
+  struct TALER_BlindedDenominationSignature *sigs;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about accounts.
+ *
+ * @param[in,out] cls of type `struct LookupSignaturesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_signatures_cb (void *cls,
+                      PGresult *result,
+                      unsigned int num_results)
+{
+  struct LookupSignaturesContext *lsc = cls;
+
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    uint32_t offset;
+    struct TALER_BlindedDenominationSignature bsig;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_uint32 ("coin_offset",
+                                    &offset),
+      TALER_PQ_result_spec_blinded_denom_sig ("blind_sig",
+                                              &bsig),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      return;
+    }
+    if (offset >= lsc->sigs_length)
+    {
+      GNUNET_break_op (0);
+      GNUNET_PQ_cleanup_result (rs);
+      continue;
+    }
+    /* Must be NULL due to UNIQUE constraint on offset and
+       requirement that client launched us with 'sigs'
+       pre-initialized to NULL. */
+    lsc->sigs[offset] = bsig;
+  }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_pickup (void *cls,
+                      const char *instance_id,
+                      const struct TALER_RewardIdentifierP *reward_id,
+                      const struct TALER_PickupIdentifierP *pickup_id,
+                      char **exchange_url,
+                      struct TALER_ReservePrivateKeyP *reserve_priv,
+                      unsigned int sigs_length,
+                      struct TALER_BlindedDenominationSignature sigs[])
+{
+  struct PostgresClosure *pg = cls;
+  uint64_t pickup_serial;
+
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_string (instance_id),
+      GNUNET_PQ_query_param_auto_from_type (reward_id),
+      GNUNET_PQ_query_param_auto_from_type (pickup_id),
+      GNUNET_PQ_query_param_end
+    };
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_string ("exchange_url",
+                                    exchange_url),
+      GNUNET_PQ_result_spec_auto_from_type ("reserve_priv",
+                                            reserve_priv),
+      GNUNET_PQ_result_spec_uint64 ("pickup_serial",
+                                    &pickup_serial),
+      GNUNET_PQ_result_spec_end
+    };
+    enum GNUNET_DB_QueryStatus qs;
+
+    check_connection (pg);
+    PREPARE (pg,
+             "lookup_pickup",
+             "SELECT"
+             " exchange_url"
+             ",reserve_priv"
+             ",pickup_serial"
+             " FROM merchant_reward_pickups"
+             " JOIN merchant_rewards USING (reward_serial)"
+             " JOIN merchant_reward_reserves USING (reserve_serial)"
+             " JOIN merchant_reward_reserve_keys USING (reserve_serial)"
+             " WHERE pickup_id = $3"
+             "   AND reward_id = $2"
+             "   AND merchant_serial ="
+             "     (SELECT merchant_serial"
+             "        FROM merchant_instances"
+             "       WHERE merchant_id=$1)");
+
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   "lookup_pickup",
+                                                   params,
+                                                   rs);
+    if (qs <= 0)
+      return qs;
+  }
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_uint64 (&pickup_serial),
+      GNUNET_PQ_query_param_end
+    };
+    struct LookupSignaturesContext lsc = {
+      .sigs_length = sigs_length,
+      .sigs = sigs
+    };
+
+    PREPARE (pg,
+             "lookup_pickup_signatures",
+             "SELECT"
+             " coin_offset"
+             ",blind_sig"
+             " FROM merchant_reward_pickup_signatures"
+             " WHERE pickup_serial = $1");
+
+    return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                                 "lookup_pickup_signatures",
+                                                 params,
+                                                 &lookup_signatures_cb,
+                                                 &lsc);
+  }
+}
diff --git a/src/backenddb/pg_lookup_pickup.h b/src/backenddb/pg_lookup_pickup.h
new file mode 100644
index 00000000..b3814731
--- /dev/null
+++ b/src/backenddb/pg_lookup_pickup.h
@@ -0,0 +1,52 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_pickup.h
+ * @brief implementation of the lookup_pickup function for Postgres
+ * @author Iván Ávalos
+ */
+#ifndef PG_LOOKUP_PICKUP_H
+#define PG_LOOKUP_PICKUP_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Lookup pickup details for pickup @a pickup_id.
+ *
+ * @param cls closure, typically a connection to the db
+ * @param instance_id which instance should we lookup reward details for
+ * @param reward_id which reward should we lookup details on
+ * @param pickup_id which pickup should we lookup details on
+ * @param[out] exchange_url which exchange is the reward withdrawn from
+ * @param[out] reserve_priv private key the reward is withdrawn from (set if 
still available!)
+ * @param sigs_length length of the @a sigs array
+ * @param[out] sigs set to the (blind) signatures we have for this @a 
pickup_id,
+ *              those that are unavailable are left at NULL
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_pickup (void *cls,
+                      const char *instance_id,
+                      const struct TALER_RewardIdentifierP *reward_id,
+                      const struct TALER_PickupIdentifierP *pickup_id,
+                      char **exchange_url,
+                      struct TALER_ReservePrivateKeyP *reserve_priv,
+                      unsigned int sigs_length,
+                      struct TALER_BlindedDenominationSignature sigs[]);
+
+#endif
diff --git a/src/backenddb/pg_lookup_reserve.c 
b/src/backenddb/pg_lookup_reserve.c
new file mode 100644
index 00000000..392db057
--- /dev/null
+++ b/src/backenddb/pg_lookup_reserve.c
@@ -0,0 +1,241 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_reserve.c
+ * @brief Implementation of the lookup_reserve function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_reserve.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #lookup_reserve_rewards_cb().
+ */
+struct LookupRewardsContext
+{
+  /**
+   * Postgres context.
+   */
+  struct PostgresClosure *pg;
+
+  /**
+   * Array with information about rewards generated from this reserve.
+   */
+  struct TALER_MERCHANTDB_RewardDetails *rewards;
+
+  /**
+   * Length of the @e rewards array.
+   */
+  unsigned int rewards_length;
+
+  /**
+   * Set in case of errors.
+   */
+  enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about accounts.
+ *
+ * @param[in,out] cls of type `struct LookupRewardsContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_reserve_rewards_cb (void *cls,
+                           PGresult *result,
+                           unsigned int num_results)
+{
+  struct LookupRewardsContext *ltc = cls;
+
+  GNUNET_array_grow (ltc->rewards,
+                     ltc->rewards_length,
+                     num_results);
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    struct TALER_MERCHANTDB_RewardDetails *td = &ltc->rewards[i];
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_string ("justification",
+                                    &td->reason),
+      GNUNET_PQ_result_spec_auto_from_type ("reward_id",
+                                            &td->reward_id),
+      TALER_PQ_result_spec_amount_with_currency ("amount",
+                                                 &td->total_amount),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      ltc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+      return;
+    }
+  }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_reserve (void *cls,
+                       const char *instance_id,
+                       const struct TALER_ReservePublicKeyP *reserve_pub,
+                       bool fetch_rewards,
+                       TALER_MERCHANTDB_ReserveDetailsCallback cb,
+                       void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct LookupRewardsContext ltc = {
+    .pg = pg,
+    .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
+  };
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+    GNUNET_PQ_query_param_end
+  };
+  struct GNUNET_TIME_Timestamp creation_time;
+  struct GNUNET_TIME_Timestamp expiration_time;
+  struct TALER_Amount merchant_initial_balance;
+  struct TALER_Amount exchange_initial_balance;
+  struct TALER_Amount pickup_amount;
+  struct TALER_Amount committed_amount;
+  struct TALER_MasterPublicKeyP master_pub;
+  bool active;
+  char *exchange_url = NULL;
+  struct GNUNET_PQ_ResultSpec rs[] = {
+    GNUNET_PQ_result_spec_timestamp ("creation_time",
+                                     &creation_time),
+    GNUNET_PQ_result_spec_timestamp ("expiration",
+                                     &expiration_time),
+    TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance",
+                                               &merchant_initial_balance),
+    TALER_PQ_result_spec_amount_with_currency ("exchange_initial_balance",
+                                               &exchange_initial_balance),
+    TALER_PQ_result_spec_amount_with_currency ("rewards_picked_up",
+                                               &pickup_amount),
+    TALER_PQ_result_spec_amount_with_currency ("rewards_committed",
+                                               &committed_amount),
+    GNUNET_PQ_result_spec_auto_from_type ("master_pub",
+                                          &master_pub),
+    GNUNET_PQ_result_spec_bool ("active",
+                                &active),
+    GNUNET_PQ_result_spec_allow_null (
+      GNUNET_PQ_result_spec_string ("exchange_url",
+                                    &exchange_url),
+      NULL),
+    GNUNET_PQ_result_spec_end
+  };
+  enum GNUNET_DB_QueryStatus qs;
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_reserve",
+           "SELECT"
+           " creation_time"
+           ",expiration"
+           ",merchant_initial_balance"
+           ",exchange_initial_balance"
+           ",rewards_committed"
+           ",rewards_picked_up"
+           ",reserve_priv IS NOT NULL AS active"
+           ",exchange_url"
+           ",master_pub"
+           " FROM merchant_reward_reserves"
+           " FULL OUTER JOIN merchant_reward_reserve_keys USING 
(reserve_serial)"
+           " WHERE reserve_pub = $2"
+           "   AND merchant_serial ="
+           "     (SELECT merchant_serial"
+           "        FROM merchant_instances"
+           "       WHERE merchant_id=$1)");
+
+  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                 "lookup_reserve",
+                                                 params,
+                                                 rs);
+  if (qs < 0)
+    return qs;
+  if (! fetch_rewards)
+  {
+    cb (cb_cls,
+        creation_time,
+        expiration_time,
+        &merchant_initial_balance,
+        &exchange_initial_balance,
+        &pickup_amount,
+        &committed_amount,
+        active,
+        &master_pub,
+        exchange_url,
+        0,
+        NULL);
+    GNUNET_PQ_cleanup_result (rs);
+    return qs;
+  }
+
+  PREPARE (pg,
+           "lookup_reserve_rewards",
+           "SELECT"
+           " justification"
+           ",reward_id"
+           ",amount"
+           " FROM merchant_rewards"
+           " WHERE reserve_serial ="
+           "  (SELECT reserve_serial"
+           "     FROM merchant_reward_reserves"
+           "      WHERE reserve_pub=$2"
+           "        AND merchant_serial ="
+           "       (SELECT merchant_serial"
+           "          FROM merchant_instances"
+           "         WHERE merchant_id=$1))");
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             "lookup_reserve_rewards",
+                                             params,
+                                             &lookup_reserve_rewards_cb,
+                                             &ltc);
+  if (qs < 0)
+    return qs;
+  if (ltc.qs >= 0)
+  {
+    cb (cb_cls,
+        creation_time,
+        expiration_time,
+        &merchant_initial_balance,
+        &exchange_initial_balance,
+        &pickup_amount,
+        &committed_amount,
+        active,
+        &master_pub,
+        exchange_url,
+        ltc.rewards_length,
+        ltc.rewards);
+  }
+  for (unsigned int i = 0; i<ltc.rewards_length; i++)
+    GNUNET_free (ltc.rewards[i].reason);
+  GNUNET_array_grow (ltc.rewards,
+                     ltc.rewards_length,
+                     0);
+  GNUNET_PQ_cleanup_result (rs);
+  return ltc.qs;
+}
diff --git a/src/backenddb/pg_lookup_account.h 
b/src/backenddb/pg_lookup_reserve.h
similarity index 57%
copy from src/backenddb/pg_lookup_account.h
copy to src/backenddb/pg_lookup_reserve.h
index 63b0aa73..53bb05f8 100644
--- a/src/backenddb/pg_lookup_account.h
+++ b/src/backenddb/pg_lookup_reserve.h
@@ -14,30 +14,34 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_account.h
- * @brief implementation of the lookup_account function for Postgres
+ * @file backenddb/pg_lookup_reserve.h
+ * @brief implementation of the lookup_reserve function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_LOOKUP_ACCOUNT_H
-#define PG_LOOKUP_ACCOUNT_H
+#ifndef PG_LOOKUP_RESERVE_H
+#define PG_LOOKUP_RESERVE_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Lookup account serial by payto URI.
+ * Lookup reserve details.
  *
  * @param cls closure
- * @param instance_id instance to lookup the account from
- * @param payto_uri what is the merchant's bank account to lookup
- * @param[out] account_serial serial number of the account
+ * @param instance_id instance to lookup payments for
+ * @param reserve_pub public key of the reserve to inspect
+ * @param fetch_rewards if true, also return information about rewards
+ * @param cb function to call with reserve summary data
+ * @param cb_cls closure for @a cb
  * @return transaction status
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_account (void *cls,
+TMH_PG_lookup_reserve (void *cls,
                        const char *instance_id,
-                       const char *payto_uri,
-                       uint64_t *account_serial);
+                       const struct TALER_ReservePublicKeyP *reserve_pub,
+                       bool fetch_rewards,
+                       TALER_MERCHANTDB_ReserveDetailsCallback cb,
+                       void *cb_cls);
 
 #endif
diff --git a/src/backenddb/pg_lookup_reward.c b/src/backenddb/pg_lookup_reward.c
new file mode 100644
index 00000000..cb887586
--- /dev/null
+++ b/src/backenddb/pg_lookup_reward.c
@@ -0,0 +1,84 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_reward.c
+ * @brief Implementation of the lookup_reward function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_reward.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_reward (void *cls,
+                      const char *instance_id,
+                      const struct TALER_RewardIdentifierP *reward_id,
+                      struct TALER_Amount *total_authorized,
+                      struct TALER_Amount *total_picked_up,
+                      struct GNUNET_TIME_Timestamp *expiration,
+                      char **exchange_url,
+                      char **next_url,
+                      struct TALER_ReservePrivateKeyP *reserve_priv)
+{
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_auto_from_type (reward_id),
+    GNUNET_PQ_query_param_end
+  };
+  struct GNUNET_PQ_ResultSpec rs[] = {
+    TALER_PQ_result_spec_amount_with_currency ("amount",
+                                               total_authorized),
+    TALER_PQ_result_spec_amount_with_currency ("picked_up",
+                                               total_picked_up),
+    GNUNET_PQ_result_spec_timestamp ("expiration",
+                                     expiration),
+    GNUNET_PQ_result_spec_string ("exchange_url",
+                                  exchange_url),
+    GNUNET_PQ_result_spec_string ("next_url",
+                                  next_url),
+    GNUNET_PQ_result_spec_auto_from_type ("reserve_priv",
+                                          reserve_priv),
+    GNUNET_PQ_result_spec_end
+  };
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_reward",
+           "SELECT"
+           " amount"
+           ",picked_up"
+           ",merchant_rewards.expiration"
+           ",exchange_url"
+           ",next_url"
+           ",reserve_priv"
+           " FROM merchant_rewards"
+           " JOIN merchant_reward_reserves USING (reserve_serial)"
+           " JOIN merchant_reward_reserve_keys USING (reserve_serial)"
+           " WHERE reward_id = $2"
+           "   AND merchant_serial ="
+           "     (SELECT merchant_serial"
+           "        FROM merchant_instances"
+           "       WHERE merchant_id=$1)");
+
+  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   "lookup_reward",
+                                                   params,
+                                                   rs);
+}
diff --git a/src/backenddb/pg_lookup_reward.h b/src/backenddb/pg_lookup_reward.h
new file mode 100644
index 00000000..fc23c9ea
--- /dev/null
+++ b/src/backenddb/pg_lookup_reward.h
@@ -0,0 +1,53 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_reward.h
+ * @brief implementation of the lookup_reward function for Postgres
+ * @author Iván Ávalos
+ */
+#ifndef PG_LOOKUP_REWARD_H
+#define PG_LOOKUP_REWARD_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Lookup reward details for reward @a reward_id.
+ *
+ * @param cls closure, typically a connection to the db
+ * @param instance_id which instance should we lookup reward details for
+ * @param reward_id which reward should we lookup details on
+ * @param[out] total_authorized amount how high is the reward (with fees)
+ * @param[out] total_picked_up how much of the reward was so far picked up 
(with fees)
+ * @param[out] expiration set to when the reward expires
+ * @param[out] exchange_url set to the exchange URL where the reserve is
+ * @param[out] next_url set to the URL where the wallet should navigate after 
getting the reward
+ * @param[out] reserve_priv set to private key of reserve to be debited
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_reward (void *cls,
+                      const char *instance_id,
+                      const struct TALER_RewardIdentifierP *reward_id,
+                      struct TALER_Amount *total_authorized,
+                      struct TALER_Amount *total_picked_up,
+                      struct GNUNET_TIME_Timestamp *expiration,
+                      char **exchange_url,
+                      char **next_url,
+                      struct TALER_ReservePrivateKeyP *reserve_priv);
+
+#endif
diff --git a/src/backenddb/pg_lookup_reward_details.c 
b/src/backenddb/pg_lookup_reward_details.c
new file mode 100644
index 00000000..062fbdd4
--- /dev/null
+++ b/src/backenddb/pg_lookup_reward_details.c
@@ -0,0 +1,208 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_reward_details.c
+ * @brief Implementation of the lookup_reward_details function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_reward_details.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #lookup_pickup_details_cb().
+ */
+struct LookupRewardDetailsContext
+{
+  /**
+   * Length of the @e sigs array
+   */
+  unsigned int *pickups_length;
+
+  /**
+   * Where to store the signatures.
+   */
+  struct TALER_MERCHANTDB_PickupDetails **pickups;
+
+  /**
+   * Database handle.
+   */
+  struct PostgresClosure *pg;
+
+  /**
+   * Transaction status.
+   */
+  enum GNUNET_DB_QueryStatus qs;
+
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about pickups.
+ *
+ * @param[in,out] cls of type `struct LookupRewardDetailsContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_pickup_details_cb (void *cls,
+                          PGresult *result,
+                          unsigned int num_results)
+{
+  struct LookupRewardDetailsContext *ltdc = cls;
+
+  *ltdc->pickups_length = num_results;
+  *ltdc->pickups = GNUNET_new_array (num_results,
+                                     struct TALER_MERCHANTDB_PickupDetails);
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    struct TALER_MERCHANTDB_PickupDetails *pd = &((*ltdc->pickups)[i]);
+    uint64_t num_planchets = 0;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_auto_from_type ("pickup_id",
+                                            &pd->pickup_id),
+      TALER_PQ_result_spec_amount_with_currency ("amount",
+                                                 &pd->requested_amount),
+      GNUNET_PQ_result_spec_uint64 ("num_planchets",
+                                    &num_planchets),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      ltdc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+      GNUNET_array_grow (*ltdc->pickups,
+                         *ltdc->pickups_length,
+                         0);
+      return;
+    }
+
+    pd->num_planchets = num_planchets;
+  }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_reward_details (void *cls,
+                              const char *instance_id,
+                              const struct TALER_RewardIdentifierP *reward_id,
+                              bool fpu,
+                              struct TALER_Amount *total_authorized,
+                              struct TALER_Amount *total_picked_up,
+                              char **justification,
+                              struct GNUNET_TIME_Timestamp *expiration,
+                              struct TALER_ReservePublicKeyP *reserve_pub,
+                              unsigned int *pickups_length,
+                              struct TALER_MERCHANTDB_PickupDetails **pickups)
+{
+  struct PostgresClosure *pg = cls;
+  uint64_t reward_serial;
+  enum GNUNET_DB_QueryStatus qs;
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_string (instance_id),
+      GNUNET_PQ_query_param_auto_from_type (reward_id),
+      GNUNET_PQ_query_param_end
+    };
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_uint64 ("reward_serial",
+                                    &reward_serial),
+      TALER_PQ_result_spec_amount_with_currency ("amount",
+                                                 total_authorized),
+      TALER_PQ_result_spec_amount_with_currency ("picked_up",
+                                                 total_picked_up),
+      GNUNET_PQ_result_spec_string ("justification",
+                                    justification),
+      GNUNET_PQ_result_spec_timestamp ("expiration",
+                                       expiration),
+      GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+                                            reserve_pub),
+      GNUNET_PQ_result_spec_end
+    };
+
+    check_connection (pg);
+    PREPARE (pg,
+             "lookup_reward_details",
+             "SELECT"
+             " reward_serial"
+             ",amount"
+             ",picked_up"
+             ",justification"
+             ",merchant_rewards.expiration"
+             ",reserve_pub"
+             " FROM merchant_rewards"
+             " JOIN merchant_reward_reserves USING (reserve_serial)"
+             " WHERE reward_id = $2"
+             "   AND merchant_serial ="
+             "     (SELECT merchant_serial"
+             "        FROM merchant_instances"
+             "       WHERE merchant_id=$1)");
+
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   "lookup_reward_details",
+                                                   params,
+                                                   rs);
+    if (qs <= 0)
+      return qs;
+    if (! fpu)
+    {
+      *pickups_length = 0;
+      *pickups = NULL;
+      return qs;
+    }
+  }
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_uint64 (&reward_serial),
+      GNUNET_PQ_query_param_end
+    };
+
+    struct LookupRewardDetailsContext ltdc = {
+      .pickups_length = pickups_length,
+      .pickups = pickups,
+      .pg = pg,
+      .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
+    };
+
+    PREPARE (pg,
+             "lookup_pickup_details",
+             "SELECT"
+             " pickup_id"
+             ",amount"
+             ",COUNT(blind_sig) AS num_planchets"
+             " FROM merchant_reward_pickups"
+             " JOIN merchant_reward_pickup_signatures USING (pickup_serial)"
+             " WHERE reward_serial = $1"
+             " GROUP BY pickup_serial");
+
+    qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                               "lookup_pickup_details",
+                                               params,
+                                               &lookup_pickup_details_cb,
+                                               &ltdc);
+    if (qs < 0)
+      return qs;
+    return ltdc.qs;
+  }
+}
diff --git a/src/backenddb/pg_lookup_reward_details.h 
b/src/backenddb/pg_lookup_reward_details.h
new file mode 100644
index 00000000..61ff301f
--- /dev/null
+++ b/src/backenddb/pg_lookup_reward_details.h
@@ -0,0 +1,57 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_reward_details.h
+ * @brief implementation of the lookup_reward_details function for Postgres
+ * @author Iván Ávalos
+ */
+#ifndef PG_LOOKUP_REWARD_DETAILS_H
+#define PG_LOOKUP_REWARD_DETAILS_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Lookup reward details for reward @a reward_id.
+ *
+ * @param cls closure, typically a connection to the db
+ * @param instance_id which instance should we lookup reward details for
+ * @param reward_id which reward should we lookup details on
+ * @param fpu should we fetch details about individual pickups
+ * @param[out] total_authorized amount how high is the reward (with fees)
+ * @param[out] total_picked_up how much of the reward was so far picked up 
(with fees)
+ * @param[out] justification why was the reward approved
+ * @param[out] expiration set to when the reward expires
+ * @param[out] reserve_pub set to which reserve is debited
+ * @param[out] pickups_length set to the length of @e pickups
+ * @param[out] pickups if @a fpu is true, set to details about the pickup 
operations
+ * @return transaction status,
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_reward_details (void *cls,
+                              const char *instance_id,
+                              const struct TALER_RewardIdentifierP *reward_id,
+                              bool fpu,
+                              struct TALER_Amount *total_authorized,
+                              struct TALER_Amount *total_picked_up,
+                              char **justification,
+                              struct GNUNET_TIME_Timestamp *expiration,
+                              struct TALER_ReservePublicKeyP *reserve_pub,
+                              unsigned int *pickups_length,
+                              struct TALER_MERCHANTDB_PickupDetails **pickups);
+
+#endif
diff --git a/src/backenddb/pg_lookup_rewards.c 
b/src/backenddb/pg_lookup_rewards.c
new file mode 100644
index 00000000..4914ad58
--- /dev/null
+++ b/src/backenddb/pg_lookup_rewards.c
@@ -0,0 +1,221 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_rewards.c
+ * @brief Implementation of the lookup_rewards function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_rewards.h"
+#include "pg_helper.h"
+
+/**
+ * Context used for postgres_lookup_rewards().
+ */
+struct LookupMerchantRewardsContext
+{
+  /**
+   * Postgres context.
+   */
+  struct PostgresClosure *pg;
+
+  /**
+   * Function to call with the results.
+   */
+  TALER_MERCHANTDB_RewardsCallback cb;
+
+  /**
+   * Closure for @a cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Internal result.
+   */
+  enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about rewards.
+ *
+ * @param[in,out] cls of type `struct LookupRewardsContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_rewards_cb (void *cls,
+                   PGresult *result,
+                   unsigned int num_results)
+{
+  struct LookupMerchantRewardsContext *plc = cls;
+
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    uint64_t row_id;
+    struct TALER_RewardIdentifierP reward_id;
+    struct TALER_Amount reward_amount;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_uint64 ("reward_serial",
+                                    &row_id),
+      GNUNET_PQ_result_spec_auto_from_type ("reward_id",
+                                            &reward_id),
+      TALER_PQ_result_spec_amount_with_currency ("amount",
+                                                 &reward_amount),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      plc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+      return;
+    }
+    plc->cb (plc->cb_cls,
+             row_id,
+             reward_id,
+             reward_amount);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_rewards (void *cls,
+                       const char *instance_id,
+                       enum TALER_EXCHANGE_YesNoAll expired,
+                       int64_t limit,
+                       uint64_t offset,
+                       TALER_MERCHANTDB_RewardsCallback cb,
+                       void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct LookupMerchantRewardsContext plc = {
+    .pg = pg,
+    .cb = cb,
+    .cb_cls = cb_cls
+  };
+  uint64_t ulimit = (limit > 0) ? limit : -limit;
+  uint8_t bexpired;
+  struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_uint64 (&ulimit),
+    GNUNET_PQ_query_param_uint64 (&offset),
+    GNUNET_PQ_query_param_absolute_time (&now),
+    GNUNET_PQ_query_param_auto_from_type (&bexpired),
+    GNUNET_PQ_query_param_end
+  };
+  enum GNUNET_DB_QueryStatus qs;
+  char stmt[128];
+
+  bexpired = (TALER_EXCHANGE_YNA_YES == expired);
+  GNUNET_snprintf (stmt,
+                   sizeof (stmt),
+                   "lookup_rewards_%s%s",
+                   (limit > 0) ? "inc" : "dec",
+                   (TALER_EXCHANGE_YNA_ALL == expired) ? "" : "_expired");
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_rewards_inc",
+           "SELECT"
+           " reward_serial"
+           ",reward_id"
+           ",amount"
+           ",CAST($4 as BIGINT)" /* otherwise $4 is unused and Postgres 
unhappy */
+           ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy 
*/
+           " FROM merchant_rewards"
+           " JOIN merchant_reward_reserves USING (reserve_serial)"
+           " WHERE merchant_serial ="
+           "     (SELECT merchant_serial"
+           "        FROM merchant_instances"
+           "       WHERE merchant_id=$1)"
+           "   AND"
+           "    reward_serial > $3"
+           " ORDER BY reward_serial ASC"
+           " LIMIT $2");
+  PREPARE (pg,
+           "lookup_rewards_dec",
+           "SELECT"
+           " reward_serial"
+           ",reward_id"
+           ",amount"
+           ",CAST($4 as BIGINT)" /* otherwise $4 is unused and Postgres 
unhappy */
+           ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy 
*/
+           " FROM merchant_rewards"
+           " JOIN merchant_reward_reserves USING (reserve_serial)"
+           " WHERE merchant_serial ="
+           "     (SELECT merchant_serial"
+           "        FROM merchant_instances"
+           "       WHERE merchant_id=$1)"
+           "   AND"
+           "    reward_serial < $3"
+           " ORDER BY reward_serial DESC"
+           " LIMIT $2");
+  PREPARE (pg,
+           "lookup_rewards_inc_expired",
+           "SELECT"
+           " reward_serial"
+           ",reward_id"
+           ",amount"
+           " FROM merchant_rewards"
+           " JOIN merchant_reward_reserves USING (reserve_serial)"
+           " WHERE merchant_serial ="
+           "     (SELECT merchant_serial"
+           "        FROM merchant_instances"
+           "       WHERE merchant_id=$1)"
+           "   AND"
+           "    reward_serial > $3"
+           "   AND"
+           "    CAST($5 as BOOL) = (merchant_rewards.expiration < $4)"
+           " ORDER BY reward_serial ASC"
+           " LIMIT $2");
+  PREPARE (pg,
+           "lookup_rewards_dec_expired",
+           "SELECT"
+           " reward_serial"
+           ",reward_id"
+           ",amount"
+           " FROM merchant_rewards"
+           " JOIN merchant_reward_reserves USING (reserve_serial)"
+           " WHERE merchant_serial ="
+           "     (SELECT merchant_serial"
+           "        FROM merchant_instances"
+           "       WHERE merchant_id=$1)"
+           "   AND"
+           "    reward_serial < $3"
+           "   AND"
+           "    CAST($5 as BOOL) = (merchant_rewards.expiration < $4)"
+           " ORDER BY reward_serial DESC"
+           " LIMIT $2");
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             stmt,
+                                             params,
+                                             &lookup_rewards_cb,
+                                             &plc);
+  if (0 != plc.qs)
+    return plc.qs;
+  return qs;
+}
diff --git a/src/backenddb/pg_lookup_account.h 
b/src/backenddb/pg_lookup_rewards.h
similarity index 54%
copy from src/backenddb/pg_lookup_account.h
copy to src/backenddb/pg_lookup_rewards.h
index 63b0aa73..a4fc61ec 100644
--- a/src/backenddb/pg_lookup_account.h
+++ b/src/backenddb/pg_lookup_rewards.h
@@ -14,30 +14,37 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_account.h
- * @brief implementation of the lookup_account function for Postgres
+ * @file backenddb/pg_lookup_rewards.h
+ * @brief implementation of the lookup_rewards function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_LOOKUP_ACCOUNT_H
-#define PG_LOOKUP_ACCOUNT_H
+#ifndef PG_LOOKUP_REWARDS_H
+#define PG_LOOKUP_REWARDS_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Lookup account serial by payto URI.
+ * Lookup rewards
  *
- * @param cls closure
- * @param instance_id instance to lookup the account from
- * @param payto_uri what is the merchant's bank account to lookup
- * @param[out] account_serial serial number of the account
+ * @param cls closure, typically a connection to the db
+ * @param instance_id which instance should we lookup rewards for
+ * @param expired should we include expired rewards?
+ * @param limit maximum number of results to return, positive for
+ *   ascending row id, negative for descending
+ * @param offset row id to start returning results from
+ * @param cb function to call with reward data
+ * @param cb_cls closure for @a cb
  * @return transaction status
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_account (void *cls,
+TMH_PG_lookup_rewards (void *cls,
                        const char *instance_id,
-                       const char *payto_uri,
-                       uint64_t *account_serial);
+                       enum TALER_EXCHANGE_YesNoAll expired,
+                       int64_t limit,
+                       uint64_t offset,
+                       TALER_MERCHANTDB_RewardsCallback cb,
+                       void *cb_cls);
 
 #endif
diff --git a/src/backenddb/pg_lookup_webhook.c 
b/src/backenddb/pg_lookup_webhook.c
new file mode 100644
index 00000000..3dcf396c
--- /dev/null
+++ b/src/backenddb/pg_lookup_webhook.c
@@ -0,0 +1,92 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_webhook.c
+ * @brief Implementation of the lookup_webhook function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_webhook.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_webhook (void *cls,
+                       const char *instance_id,
+                       const char *webhook_id,
+                       struct TALER_MERCHANTDB_WebhookDetails *wb)
+{
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_string (webhook_id),
+    GNUNET_PQ_query_param_end
+  };
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_webhook",
+           "SELECT"
+           " event_type"
+           ",url"
+           ",http_method"
+           ",header_template"
+           ",body_template"
+           " FROM merchant_webhook"
+           " JOIN merchant_instances"
+           "   USING (merchant_serial)"
+           " WHERE merchant_instances.merchant_id=$1"
+           "   AND merchant_webhook.webhook_id=$2");
+
+  if (NULL == wb)
+  {
+    struct GNUNET_PQ_ResultSpec rs_null[] = {
+      GNUNET_PQ_result_spec_end
+    };
+
+    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                     "lookup_webhook",
+                                                     params,
+                                                     rs_null);
+  }
+  else
+  {
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_string ("event_type",
+                                    &wb->event_type),
+      GNUNET_PQ_result_spec_string ("url",
+                                    &wb->url),
+      GNUNET_PQ_result_spec_string ("http_method",
+                                    &wb->http_method),
+      GNUNET_PQ_result_spec_allow_null (
+        GNUNET_PQ_result_spec_string ("header_template",
+                                      &wb->header_template),
+        NULL),
+      GNUNET_PQ_result_spec_allow_null (
+        GNUNET_PQ_result_spec_string ("body_template",
+                                      &wb->body_template),
+        NULL),
+      GNUNET_PQ_result_spec_end
+    };
+
+    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                     "lookup_webhook",
+                                                     params,
+                                                     rs);
+  }
+}
diff --git a/src/backenddb/pg_lookup_account.h 
b/src/backenddb/pg_lookup_webhook.h
similarity index 60%
copy from src/backenddb/pg_lookup_account.h
copy to src/backenddb/pg_lookup_webhook.h
index 63b0aa73..d39828f1 100644
--- a/src/backenddb/pg_lookup_account.h
+++ b/src/backenddb/pg_lookup_webhook.h
@@ -14,30 +14,31 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_account.h
- * @brief implementation of the lookup_account function for Postgres
+ * @file backenddb/pg_lookup_webhook.h
+ * @brief implementation of the lookup_webhook function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_LOOKUP_ACCOUNT_H
-#define PG_LOOKUP_ACCOUNT_H
+#ifndef PG_LOOKUP_WEBHOOK_H
+#define PG_LOOKUP_WEBHOOK_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Lookup account serial by payto URI.
+ * Lookup details about a particular webhook.
  *
  * @param cls closure
- * @param instance_id instance to lookup the account from
- * @param payto_uri what is the merchant's bank account to lookup
- * @param[out] account_serial serial number of the account
- * @return transaction status
+ * @param instance_id instance to lookup webhook for
+ * @param webhook_id webhook to lookup
+ * @param[out] wb set to the webhook details on success, can be NULL
+ *             (in that case we only want to check if the webhook exists)
+ * @return database result code
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_account (void *cls,
+TMH_PG_lookup_webhook (void *cls,
                        const char *instance_id,
-                       const char *payto_uri,
-                       uint64_t *account_serial);
+                       const char *webhook_id,
+                       struct TALER_MERCHANTDB_WebhookDetails *wb);
 
 #endif
diff --git a/src/backenddb/pg_lookup_webhook_by_event.c 
b/src/backenddb/pg_lookup_webhook_by_event.c
new file mode 100644
index 00000000..97960bbe
--- /dev/null
+++ b/src/backenddb/pg_lookup_webhook_by_event.c
@@ -0,0 +1,158 @@
+/*
+   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 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_webhook_by_event.c
+ * @brief Implementation of the lookup_webhook_by_event function for Postgres
+ * @author Iván Ávalos
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_webhook_by_event.h"
+#include "pg_helper.h"
+
+/**
+ * Context used for lookup_webhook_by_event_cb().
+ */
+struct LookupWebhookDetailContext
+{
+  /**
+   * Function to call with the results.
+   */
+  TALER_MERCHANTDB_WebhookDetailCallback cb;
+
+  /**
+   * Closure for @a cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Did database result extraction fail?
+   */
+  bool extract_failed;
+};
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about webhook.
+ *
+ * @param[in,out] cls of type `struct LookupPendingWebhookContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_webhook_by_event_cb (void *cls,
+                            PGresult *result,
+                            unsigned int num_results)
+{
+  struct LookupWebhookDetailContext *wlc = cls;
+
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    uint64_t webhook_serial;
+    char *event_type;
+    char *url;
+    char *http_method;
+    char *header_template;
+    char *body_template;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_uint64 ("webhook_serial",
+                                    &webhook_serial),
+      GNUNET_PQ_result_spec_string ("event_type",
+                                    &event_type),
+      GNUNET_PQ_result_spec_string ("url",
+                                    &url),
+      GNUNET_PQ_result_spec_string ("http_method",
+                                    &http_method),
+      GNUNET_PQ_result_spec_allow_null (
+        GNUNET_PQ_result_spec_string ("header_template",
+                                      &header_template),
+        NULL),
+      GNUNET_PQ_result_spec_allow_null (
+        GNUNET_PQ_result_spec_string ("body_template",
+                                      &body_template),
+        NULL),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      wlc->extract_failed = true;
+      return;
+    }
+    wlc->cb (wlc->cb_cls,
+             webhook_serial,
+             event_type,
+             url,
+             http_method,
+             header_template,
+             body_template);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_webhook_by_event (void *cls,
+                                const char *instance_id,
+                                const char *event_type,
+                                TALER_MERCHANTDB_WebhookDetailCallback cb,
+                                void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct LookupWebhookDetailContext wlc = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .extract_failed = false,
+  };
+
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_string (event_type),
+    GNUNET_PQ_query_param_end
+  };
+  enum GNUNET_DB_QueryStatus qs;
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_webhook_by_event",
+           "SELECT"
+           " webhook_serial"
+           ",event_type"
+           ",url"
+           ",http_method"
+           ",header_template"
+           ",body_template"
+           " FROM merchant_webhook"
+           " JOIN merchant_instances"
+           "   USING (merchant_serial)"
+           " WHERE merchant_instances.merchant_id=$1"
+           "  AND event_type=$2");
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             "lookup_webhook_by_event",
+                                             params,
+                                             &lookup_webhook_by_event_cb,
+                                             &wlc);
+
+  if (wlc.extract_failed)
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  return qs;
+}
diff --git a/src/backenddb/pg_lookup_transfer_details.h 
b/src/backenddb/pg_lookup_webhook_by_event.h
similarity index 55%
copy from src/backenddb/pg_lookup_transfer_details.h
copy to src/backenddb/pg_lookup_webhook_by_event.h
index 3f99fc67..ccabc1ec 100644
--- a/src/backenddb/pg_lookup_transfer_details.h
+++ b/src/backenddb/pg_lookup_webhook_by_event.h
@@ -14,32 +14,32 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_transfer_details.h
- * @brief implementation of the lookup_transfer_details function for Postgres
+ * @file backenddb/pg_lookup_webhook_by_event.h
+ * @brief implementation of the lookup_webhook_by_event function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_LOOKUP_TRANSFER_DETAILS_H
-#define PG_LOOKUP_TRANSFER_DETAILS_H
+#ifndef PG_LOOKUP_WEBHOOK_BY_EVENT_H
+#define PG_LOOKUP_WEBHOOK_BY_EVENT_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Lookup transfer details.
- *
- * @param cls closure
- * @param exchange_url the exchange that made the transfer
- * @param wtid wire transfer subject
- * @param cb function to call with detailed transfer data
- * @param cb_cls closure for @a cb
- * @return transaction status
- */
+   * Lookup webhook by event
+   *
+   * @param cls closure
+   * @param instance_id instance to lookup webhook for
+   * @param event_type event that we need to put in the pending webhook
+   * @param[out] cb set to the webhook details on success
+   * @param cb_cls callback closure
+   * @return database result code
+   */
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_transfer_details (void *cls,
-                                const char *exchange_url,
-                                const struct TALER_WireTransferIdentifierRawP 
*wtid,
-                                TALER_MERCHANTDB_TransferDetailsCallback cb,
+TMH_PG_lookup_webhook_by_event (void *cls,
+                                const char *instance_id,
+                                const char *event_type,
+                                TALER_MERCHANTDB_WebhookDetailCallback cb,
                                 void *cb_cls);
 
 #endif
diff --git a/src/backenddb/pg_lookup_products.c 
b/src/backenddb/pg_lookup_webhooks.c
similarity index 62%
copy from src/backenddb/pg_lookup_products.c
copy to src/backenddb/pg_lookup_webhooks.c
index d16aeb8d..0a85d527 100644
--- a/src/backenddb/pg_lookup_products.c
+++ b/src/backenddb/pg_lookup_webhooks.c
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2023 Taler Systems SA
 
    TALER is free software; you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free Software
@@ -14,26 +14,26 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_products.c
- * @brief Implementation of the lookup_products function for Postgres
+ * @file backenddb/pg_lookup_webhooks.c
+ * @brief Implementation of the lookup_webhooks function for Postgres
  * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_lookup_products.h"
+#include "pg_lookup_webhooks.h"
 #include "pg_helper.h"
 
 /**
- * Context used for TMH_PG_lookup_products().
+ * Context used for postgres_lookup_webhooks().
  */
-struct LookupProductsContext
+struct LookupWebhookContext
 {
   /**
    * Function to call with the results.
    */
-  TALER_MERCHANTDB_ProductsCallback cb;
+  TALER_MERCHANTDB_WebhooksCallback cb;
 
   /**
    * Closure for @a cb.
@@ -49,25 +49,28 @@ struct LookupProductsContext
 
 /**
  * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about products.
+ * that has returned @a num_results results about webhook.
  *
- * @param[in,out] cls of type `struct LookupProductsContext *`
+ * @param[in,out] cls of type `struct LookupWebhookContext *`
  * @param result the postgres result
  * @param num_results the number of results in @a result
  */
 static void
-lookup_products_cb (void *cls,
+lookup_webhooks_cb (void *cls,
                     PGresult *result,
                     unsigned int num_results)
 {
-  struct LookupProductsContext *plc = cls;
+  struct LookupWebhookContext *wlc = cls;
 
   for (unsigned int i = 0; i < num_results; i++)
   {
-    char *product_id;
+    char *webhook_id;
+    char *event_type;
     struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_string ("product_id",
-                                    &product_id),
+      GNUNET_PQ_result_spec_string ("webhook_id",
+                                    &webhook_id),
+      GNUNET_PQ_result_spec_string ("event_type",
+                                    &event_type),
       GNUNET_PQ_result_spec_end
     };
 
@@ -77,27 +80,28 @@ lookup_products_cb (void *cls,
                                   i))
     {
       GNUNET_break (0);
-      plc->extract_failed = true;
+      wlc->extract_failed = true;
       return;
     }
-    plc->cb (plc->cb_cls,
-             product_id);
+    wlc->cb (wlc->cb_cls,
+             webhook_id,
+             event_type);
     GNUNET_PQ_cleanup_result (rs);
   }
 }
 
 
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_products (void *cls,
+TMH_PG_lookup_webhooks (void *cls,
                         const char *instance_id,
-                        TALER_MERCHANTDB_ProductsCallback cb,
+                        TALER_MERCHANTDB_WebhooksCallback cb,
                         void *cb_cls)
 {
   struct PostgresClosure *pg = cls;
-  struct LookupProductsContext plc = {
+  struct LookupWebhookContext wlc = {
     .cb = cb,
     .cb_cls = cb_cls,
-    /* Can be overwritten by the lookup_products_cb */
+    /* Can be overwritten by the lookup_webhook_cb */
     .extract_failed = false,
   };
   struct GNUNET_PQ_QueryParam params[] = {
@@ -108,20 +112,22 @@ TMH_PG_lookup_products (void *cls,
 
   check_connection (pg);
   PREPARE (pg,
-           "lookup_products",
+           "lookup_webhooks",
            "SELECT"
-           " product_id"
-           " FROM merchant_inventory"
+           " webhook_id"
+           ",event_type"
+           " FROM merchant_webhook"
            " JOIN merchant_instances"
            "   USING (merchant_serial)"
            " WHERE merchant_instances.merchant_id=$1");
+
   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             "lookup_products",
+                                             "lookup_webhooks",
                                              params,
-                                             &lookup_products_cb,
-                                             &plc);
-  /* If there was an error inside lookup_products_cb, return a hard error. */
-  if (plc.extract_failed)
+                                             &lookup_webhooks_cb,
+                                             &wlc);
+  /* If there was an error inside lookup_webhook_cb, return a hard error. */
+  if (wlc.extract_failed)
     return GNUNET_DB_STATUS_HARD_ERROR;
   return qs;
 }
diff --git a/src/backenddb/pg_lookup_products.h 
b/src/backenddb/pg_lookup_webhooks.h
similarity index 68%
copy from src/backenddb/pg_lookup_products.h
copy to src/backenddb/pg_lookup_webhooks.h
index 398b5eac..84509267 100644
--- a/src/backenddb/pg_lookup_products.h
+++ b/src/backenddb/pg_lookup_webhooks.h
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2023 Taler Systems SA
 
    TALER is free software; you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free Software
@@ -14,30 +14,30 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_products.h
- * @brief implementation of the lookup_products function for Postgres
+ * @file backenddb/pg_lookup_webhooks.h
+ * @brief implementation of the lookup_webhooks function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_LOOKUP_PRODUCTS_H
-#define PG_LOOKUP_PRODUCTS_H
+#ifndef PG_LOOKUP_WEBHOOKS_H
+#define PG_LOOKUP_WEBHOOKS_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Lookup all of the products the given instance has configured.
+ * Lookup all of the webhooks the given instance has configured.
  *
  * @param cls closure
- * @param instance_id instance to lookup products for
- * @param cb function to call on all products found
+ * @param instance_id instance to lookup webhook for
+ * @param cb function to call on all webhook found
  * @param cb_cls closure for @a cb
  * @return database result code
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_products (void *cls,
+TMH_PG_lookup_webhooks (void *cls,
                         const char *instance_id,
-                        TALER_MERCHANTDB_ProductsCallback cb,
+                        TALER_MERCHANTDB_WebhooksCallback cb,
                         void *cb_cls);
 
 #endif
diff --git a/src/backenddb/pg_delete_login_token.c 
b/src/backenddb/pg_purge_reserve.c
similarity index 66%
copy from src/backenddb/pg_delete_login_token.c
copy to src/backenddb/pg_purge_reserve.c
index d23e541e..cb01069a 100644
--- a/src/backenddb/pg_delete_login_token.c
+++ b/src/backenddb/pg_purge_reserve.c
@@ -14,42 +14,41 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_delete_login_token.c
- * @brief Implementation of the delete_login_token function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_purge_reserve.c
+ * @brief Implementation of the purge_reserve function for Postgres
+ * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_delete_login_token.h"
+#include "pg_purge_reserve.h"
 #include "pg_helper.h"
 
-
 enum GNUNET_DB_QueryStatus
-TMH_PG_delete_login_token (
-  void *cls,
-  const char *id,
-  const struct TALER_MERCHANTDB_LoginTokenP *token)
+TMH_PG_purge_reserve (void *cls,
+                      const char *instance_id,
+                      const struct TALER_ReservePublicKeyP *reserve_pub)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (id),
-    GNUNET_PQ_query_param_auto_from_type (token),
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_auto_from_type (reserve_pub),
     GNUNET_PQ_query_param_end
   };
 
   check_connection (pg);
   PREPARE (pg,
-           "delete_login_token",
-           "DELETE FROM merchant_login_tokens"
-           " WHERE token=$2"
-           "   AND merchant_serial="
+           "purge_reserve",
+           "DELETE"
+           "   FROM merchant_reward_reserves"
+           "  WHERE reserve_pub=$2"
+           "    AND merchant_serial="
            "    (SELECT merchant_serial"
            "       FROM merchant_instances"
            "      WHERE merchant_id=$1)");
+
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "delete_login_token",
+                                             "purge_reserve",
                                              params);
 }
-
diff --git a/src/backenddb/pg_mark_order_wired.h 
b/src/backenddb/pg_purge_reserve.h
similarity index 57%
copy from src/backenddb/pg_mark_order_wired.h
copy to src/backenddb/pg_purge_reserve.h
index dd7cc97f..83c1b44f 100644
--- a/src/backenddb/pg_mark_order_wired.h
+++ b/src/backenddb/pg_purge_reserve.h
@@ -14,26 +14,29 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_mark_order_wired.h
- * @brief implementation of the mark_order_wired function for Postgres
+ * @file backenddb/pg_purge_reserve.h
+ * @brief implementation of the purge_reserve function for Postgres
  * @author Iván Ávalos
  */
-#ifndef PG_MARK_ORDER_WIRED_H
-#define PG_MARK_ORDER_WIRED_H
+#ifndef PG_PURGE_RESERVE_H
+#define PG_PURGE_RESERVE_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
 /**
- * Set 'wired' status for an order to 'true'.
+ * Purge all of the information about a reserve, including rewards.
  *
- * @param cls closure
- * @param order_serial serial number of the order
- * @return transaction status
+ * @param cls closure, typically a connection to the db
+ * @param instance_id which instance is the reserve tied to
+ * @param reserve_pub which reserve is to be purged
+ * @return transaction status, usually
+ *      #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_mark_order_wired (void *cls,
-                         uint64_t order_serial);
+TMH_PG_purge_reserve (void *cls,
+                      const char *instance_id,
+                      const struct TALER_ReservePublicKeyP *reserve_pub);
 
 #endif
diff --git a/src/backenddb/pg_mark_order_wired.c 
b/src/backenddb/pg_update_pending_webhook.c
similarity index 61%
copy from src/backenddb/pg_mark_order_wired.c
copy to src/backenddb/pg_update_pending_webhook.c
index fde1ecc7..23ef5f04 100644
--- a/src/backenddb/pg_mark_order_wired.c
+++ b/src/backenddb/pg_update_pending_webhook.c
@@ -14,35 +14,38 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_mark_order_wired.c
- * @brief Implementation of the mark_order_wired function for Postgres
+ * @file backenddb/pg_update_pending_webhook.c
+ * @brief Implementation of the update_pending_webhook function for Postgres
  * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_mark_order_wired.h"
+#include "pg_update_pending_webhook.h"
 #include "pg_helper.h"
 
 enum GNUNET_DB_QueryStatus
-TMH_PG_mark_order_wired (void *cls,
-                         uint64_t order_serial)
+TMH_PG_update_pending_webhook (void *cls,
+                               uint64_t webhook_pending_serial,
+                               struct GNUNET_TIME_Absolute next_attempt)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_uint64 (&order_serial),
+    GNUNET_PQ_query_param_uint64 (&webhook_pending_serial),
+    GNUNET_PQ_query_param_absolute_time (&next_attempt),
     GNUNET_PQ_query_param_end
   };
 
   check_connection (pg);
   PREPARE (pg,
-           "mark_order_wired",
-           "UPDATE merchant_contract_terms SET"
-           " wired=TRUE"
-           " WHERE order_serial=$1");
+           "update_pending_webhook",
+           "UPDATE merchant_pending_webhooks SET"
+           " retries=retries+1"
+           ",next_attempt=$2"
+           " WHERE webhook_pending_serial=$1");
 
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "mark_order_wired",
+                                             "update_pending_webhook",
                                              params);
 }
diff --git a/src/backenddb/pg_delete_login_token.h 
b/src/backenddb/pg_update_pending_webhook.h
similarity index 60%
copy from src/backenddb/pg_delete_login_token.h
copy to src/backenddb/pg_update_pending_webhook.h
index 0ae9f56b..2ccf519e 100644
--- a/src/backenddb/pg_delete_login_token.h
+++ b/src/backenddb/pg_update_pending_webhook.h
@@ -14,31 +14,28 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_delete_login_token.h
- * @brief implementation of the delete_login_token function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_update_pending_webhook.h
+ * @brief implementation of the update_pending_webhook function for Postgres
+ * @author Iván Ávalos
  */
-#ifndef PG_DELETE_LOGIN_TOKEN_H
-#define PG_DELETE_LOGIN_TOKEN_H
+#ifndef PG_UPDATE_PENDING_WEBHOOK_H
+#define PG_UPDATE_PENDING_WEBHOOK_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
-
 /**
- * Delete login token from database.
+ * Update the pending webhook. It is use if the webhook can't be send.
  *
  * @param cls closure
- * @param id identifier of the instance
- * @param token value of the token
+ * @param webhook_pending_serial pending_webhook that need to be update
+ * @param next_attempt when to try the webhook next
  * @return database result code
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_delete_login_token (
-  void *cls,
-  const char *id,
-  const struct TALER_MERCHANTDB_LoginTokenP *token);
-
+TMH_PG_update_pending_webhook (void *cls,
+                               uint64_t webhook_pending_serial,
+                               struct GNUNET_TIME_Absolute next_attempt);
 
 #endif
diff --git a/src/backenddb/pg_update_account.c 
b/src/backenddb/pg_update_webhook.c
similarity index 52%
copy from src/backenddb/pg_update_account.c
copy to src/backenddb/pg_update_webhook.c
index 7458c095..c12ae9e3 100644
--- a/src/backenddb/pg_update_account.c
+++ b/src/backenddb/pg_update_webhook.c
@@ -14,51 +14,56 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_update_account.c
- * @brief Implementation of the update_account function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_update_webhook.c
+ * @brief Implementation of the update_webhook function for Postgres
+ * @author Iván Ávalos
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
-#include "pg_update_account.h"
+#include "pg_update_webhook.h"
 #include "pg_helper.h"
 
-
 enum GNUNET_DB_QueryStatus
-TMH_PG_update_account (
-  void *cls,
-  const char *id,
-  const struct TALER_MerchantWireHashP *h_wire,
-  const char *credit_facade_url,
-  const json_t *credit_facade_credentials)
+TMH_PG_update_webhook (void *cls,
+                       const char *instance_id,
+                       const char *webhook_id,
+                       const struct TALER_MERCHANTDB_WebhookDetails *wb)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (id),
-    GNUNET_PQ_query_param_auto_from_type (h_wire),
-    NULL == credit_facade_url
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_string (webhook_id),
+    GNUNET_PQ_query_param_string (wb->event_type),
+    GNUNET_PQ_query_param_string (wb->url),
+    GNUNET_PQ_query_param_string (wb->http_method),
+    (NULL == wb->header_template)
     ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_string (credit_facade_url),
-    NULL == credit_facade_credentials
+    : GNUNET_PQ_query_param_string (wb->header_template),
+    (NULL == wb->body_template)
     ? GNUNET_PQ_query_param_null ()
-    : TALER_PQ_query_param_json (credit_facade_credentials),
+    : GNUNET_PQ_query_param_string (wb->body_template),
     GNUNET_PQ_query_param_end
   };
 
+
   check_connection (pg);
   PREPARE (pg,
-           "update_account",
-           "UPDATE merchant_accounts SET"
-           " credit_facade_url=$3"
-           ",credit_facade_credentials=COALESCE($4,credit_facade_credentials)"
-           " WHERE h_wire=$2"
-           "   AND merchant_serial="
+           "update_webhook",
+           "UPDATE merchant_webhook SET"
+           " event_type=$3"
+           ",url=$4"
+           ",http_method=$5"
+           ",header_template=$6"
+           ",body_template=$7"
+           " WHERE merchant_serial="
            "   (SELECT merchant_serial"
            "      FROM merchant_instances"
-           "      WHERE merchant_id=$1);");
+           "      WHERE merchant_id=$1)"
+           "   AND webhook_id=$2");
+
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "update_account",
+                                             "update_webhook",
                                              params);
 }
diff --git a/src/backenddb/pg_update_template.h 
b/src/backenddb/pg_update_webhook.h
similarity index 58%
copy from src/backenddb/pg_update_template.h
copy to src/backenddb/pg_update_webhook.h
index 26b932a2..a34eb598 100644
--- a/src/backenddb/pg_update_template.h
+++ b/src/backenddb/pg_update_webhook.h
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2023 Taler Systems SA
 
    TALER is free software; you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free Software
@@ -14,33 +14,32 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_update_template.h
- * @brief implementation of the update_template function for Postgres
- * @author Christian Grothoff
+ * @file backenddb/pg_update_webhook.h
+ * @brief implementation of the update_webhook function for Postgres
+ * @author Iván Ávalos
  */
-#ifndef PG_UPDATE_TEMPLATE_H
-#define PG_UPDATE_TEMPLATE_H
+#ifndef PG_UPDATE_WEBHOOK_H
+#define PG_UPDATE_WEBHOOK_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
 #include "taler_merchantdb_plugin.h"
 
-
 /**
- * Update details about a particular template.
+ * Update details about a particular webhook.
  *
  * @param cls closure
  * @param instance_id instance to update template for
- * @param template_id template to update
- * @param td update to the template details on success, can be NULL
- *             (in that case we only want to check if the template exists)
- * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the 
template
+ * @param webhook_id webhook to update
+ * @param wb update to the webhook details on success, can be NULL
+ *             (in that case we only want to check if the webhook exists)
+ * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the 
webhook
  *         does not yet exist.
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_update_template (void *cls,
-                        const char *instance_id,
-                        const char *template_id,
-                        const struct TALER_MERCHANTDB_TemplateDetails *td);
+TMH_PG_update_webhook (void *cls,
+                       const char *instance_id,
+                       const char *webhook_id,
+                       const struct TALER_MERCHANTDB_WebhookDetails *wb);
 
 #endif
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 214902dd..1f1f54c6 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -112,6 +112,27 @@
 #include "pg_lookup_transfer.h"
 #include "pg_lookup_transfer_summary.h"
 #include "pg_lookup_transfer_details.h"
+#include "pg_lookup_pending_reserves.h"
+#include "pg_lookup_reserve.h"
+#include "pg_delete_reserve.h"
+#include "pg_purge_reserve.h"
+#include "pg_lookup_pickup.h"
+#include "pg_lookup_reward.h"
+#include "pg_lookup_rewards.h"
+#include "pg_lookup_reward_details.h"
+#include "pg_insert_pickup_blind_signature.h"
+#include "pg_lookup_webhooks.h"
+#include "pg_lookup_webhook.h"
+#include "pg_delete_webhook.h"
+#include "pg_insert_webhook.h"
+#include "pg_update_webhook.h"
+#include "pg_lookup_webhook_by_event.h"
+#include "pg_delete_pending_webhook.h"
+#include "pg_insert_pending_webhook.h"
+#include "pg_update_pending_webhook.h"
+#include "pg_lookup_pending_webhooks.h"
+// ^^^^^ + lookup_future_webhook
+// ^^^^^ + lookup_all_webhooks
 #include "pg_set_transfer_status_to_confirmed.h"
 #include "pg_insert_exchange_keys.h"
 #include "pg_select_exchange_keys.h"
@@ -274,1619 +295,6 @@ check_connection (struct PostgresClosure *pg)
   GNUNET_PQ_reconnect_if_down (pg->conn);
 }
 
-
-/**
- * Closure for #lookup_pending_reserves_cb.
- */
-struct LookupPendingReservesContext
-{
-  /**
-   * Postgres context.
-   */
-  struct PostgresClosure *pg;
-
-  /**
-   * Function to call with the results
-   */
-  TALER_MERCHANTDB_PendingReservesCallback cb;
-
-  /**
-   * Closure for @e cb
-   */
-  void *cb_cls;
-
-  /**
-   * Set in case of errors.
-   */
-  enum GNUNET_DB_QueryStatus qs;
-
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about accounts.
- *
- * @param[in,out] cls of type `struct LookupReservesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_pending_reserves_cb (void *cls,
-                            PGresult *result,
-                            unsigned int num_results)
-{
-  struct LookupPendingReservesContext *lrc = cls;
-
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    struct TALER_ReservePublicKeyP reserve_pub;
-    struct TALER_Amount merchant_initial_balance;
-    char *exchange_url;
-    char *instance_id;
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
-                                            &reserve_pub),
-      GNUNET_PQ_result_spec_string ("merchant_id",
-                                    &instance_id),
-      GNUNET_PQ_result_spec_string ("exchange_url",
-                                    &exchange_url),
-      TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance",
-                                                 &merchant_initial_balance),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      lrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
-      return;
-    }
-    lrc->cb (lrc->cb_cls,
-             instance_id,
-             exchange_url,
-             &reserve_pub,
-             &merchant_initial_balance);
-    GNUNET_PQ_cleanup_result (rs);
-  }
-}
-
-
-/**
- * Lookup reserves pending activation across all instances.
- *
- * @param cls closure
- * @param cb function to call with reserve summary data
- * @param cb_cls closure for @a cb
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_pending_reserves (void *cls,
-                                  TALER_MERCHANTDB_PendingReservesCallback cb,
-                                  void *cb_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct LookupPendingReservesContext lrc = {
-    .pg = pg,
-    .cb = cb,
-    .cb_cls = cb_cls
-  };
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_end
-  };
-  enum GNUNET_DB_QueryStatus qs;
-
-  check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             "lookup_pending_reserves",
-                                             params,
-                                             &lookup_pending_reserves_cb,
-                                             &lrc);
-  if (lrc.qs < 0)
-    return lrc.qs;
-  return qs;
-}
-
-
-/**
- * Closure for #lookup_reserve_rewards_cb().
- */
-struct LookupRewardsContext
-{
-  /**
-   * Postgres context.
-   */
-  struct PostgresClosure *pg;
-
-  /**
-   * Array with information about rewards generated from this reserve.
-   */
-  struct TALER_MERCHANTDB_RewardDetails *rewards;
-
-  /**
-   * Length of the @e rewards array.
-   */
-  unsigned int rewards_length;
-
-  /**
-   * Set in case of errors.
-   */
-  enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about accounts.
- *
- * @param[in,out] cls of type `struct LookupRewardsContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_reserve_rewards_cb (void *cls,
-                           PGresult *result,
-                           unsigned int num_results)
-{
-  struct LookupRewardsContext *ltc = cls;
-
-  GNUNET_array_grow (ltc->rewards,
-                     ltc->rewards_length,
-                     num_results);
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    struct TALER_MERCHANTDB_RewardDetails *td = &ltc->rewards[i];
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_string ("justification",
-                                    &td->reason),
-      GNUNET_PQ_result_spec_auto_from_type ("reward_id",
-                                            &td->reward_id),
-      TALER_PQ_result_spec_amount_with_currency ("amount",
-                                                 &td->total_amount),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      ltc->qs = GNUNET_DB_STATUS_HARD_ERROR;
-      return;
-    }
-  }
-}
-
-
-/**
- * Lookup reserve details.
- *
- * @param cls closure
- * @param instance_id instance to lookup payments for
- * @param reserve_pub public key of the reserve to inspect
- * @param fetch_rewards if true, also return information about rewards
- * @param cb function to call with reserve summary data
- * @param cb_cls closure for @a cb
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_reserve (void *cls,
-                         const char *instance_id,
-                         const struct TALER_ReservePublicKeyP *reserve_pub,
-                         bool fetch_rewards,
-                         TALER_MERCHANTDB_ReserveDetailsCallback cb,
-                         void *cb_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct LookupRewardsContext ltc = {
-    .pg = pg,
-    .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
-  };
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_auto_from_type (reserve_pub),
-    GNUNET_PQ_query_param_end
-  };
-  struct GNUNET_TIME_Timestamp creation_time;
-  struct GNUNET_TIME_Timestamp expiration_time;
-  struct TALER_Amount merchant_initial_balance;
-  struct TALER_Amount exchange_initial_balance;
-  struct TALER_Amount pickup_amount;
-  struct TALER_Amount committed_amount;
-  struct TALER_MasterPublicKeyP master_pub;
-  bool active;
-  char *exchange_url = NULL;
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    GNUNET_PQ_result_spec_timestamp ("creation_time",
-                                     &creation_time),
-    GNUNET_PQ_result_spec_timestamp ("expiration",
-                                     &expiration_time),
-    TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance",
-                                               &merchant_initial_balance),
-    TALER_PQ_result_spec_amount_with_currency ("exchange_initial_balance",
-                                               &exchange_initial_balance),
-    TALER_PQ_result_spec_amount_with_currency ("rewards_picked_up",
-                                               &pickup_amount),
-    TALER_PQ_result_spec_amount_with_currency ("rewards_committed",
-                                               &committed_amount),
-    GNUNET_PQ_result_spec_auto_from_type ("master_pub",
-                                          &master_pub),
-    GNUNET_PQ_result_spec_bool ("active",
-                                &active),
-    GNUNET_PQ_result_spec_allow_null (
-      GNUNET_PQ_result_spec_string ("exchange_url",
-                                    &exchange_url),
-      NULL),
-    GNUNET_PQ_result_spec_end
-  };
-  enum GNUNET_DB_QueryStatus qs;
-
-  check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                 "lookup_reserve",
-                                                 params,
-                                                 rs);
-  if (qs < 0)
-    return qs;
-  if (! fetch_rewards)
-  {
-    cb (cb_cls,
-        creation_time,
-        expiration_time,
-        &merchant_initial_balance,
-        &exchange_initial_balance,
-        &pickup_amount,
-        &committed_amount,
-        active,
-        &master_pub,
-        exchange_url,
-        0,
-        NULL);
-    GNUNET_PQ_cleanup_result (rs);
-    return qs;
-  }
-
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             "lookup_reserve_rewards",
-                                             params,
-                                             &lookup_reserve_rewards_cb,
-                                             &ltc);
-  if (qs < 0)
-    return qs;
-  if (ltc.qs >= 0)
-  {
-    cb (cb_cls,
-        creation_time,
-        expiration_time,
-        &merchant_initial_balance,
-        &exchange_initial_balance,
-        &pickup_amount,
-        &committed_amount,
-        active,
-        &master_pub,
-        exchange_url,
-        ltc.rewards_length,
-        ltc.rewards);
-  }
-  for (unsigned int i = 0; i<ltc.rewards_length; i++)
-    GNUNET_free (ltc.rewards[i].reason);
-  GNUNET_array_grow (ltc.rewards,
-                     ltc.rewards_length,
-                     0);
-  GNUNET_PQ_cleanup_result (rs);
-  return ltc.qs;
-}
-
-
-/**
- * Delete a reserve's private key.
- *
- * @param cls closure, typically a connection to the db
- * @param instance_id which instance is the reserve tied to
- * @param reserve_pub which reserve is to be deleted
- * @return transaction status, usually
- *      #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success
- */
-static enum GNUNET_DB_QueryStatus
-postgres_delete_reserve (void *cls,
-                         const char *instance_id,
-                         const struct TALER_ReservePublicKeyP *reserve_pub)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_auto_from_type (reserve_pub),
-    GNUNET_PQ_query_param_end
-  };
-
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "delete_reserve",
-                                             params);
-}
-
-
-/**
- * Purge all of the information about a reserve, including rewards.
- *
- * @param cls closure, typically a connection to the db
- * @param instance_id which instance is the reserve tied to
- * @param reserve_pub which reserve is to be purged
- * @return transaction status, usually
- *      #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success
- */
-static enum GNUNET_DB_QueryStatus
-postgres_purge_reserve (void *cls,
-                        const char *instance_id,
-                        const struct TALER_ReservePublicKeyP *reserve_pub)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_auto_from_type (reserve_pub),
-    GNUNET_PQ_query_param_end
-  };
-
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "purge_reserve",
-                                             params);
-}
-
-
-/**
- * Closure for #lookup_signatures_cb().
- */
-struct LookupSignaturesContext
-{
-  /**
-   * Length of the @e sigs array
-   */
-  unsigned int sigs_length;
-
-  /**
-   * Where to store the signatures.
-   */
-  struct TALER_BlindedDenominationSignature *sigs;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about accounts.
- *
- * @param[in,out] cls of type `struct LookupSignaturesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_signatures_cb (void *cls,
-                      PGresult *result,
-                      unsigned int num_results)
-{
-  struct LookupSignaturesContext *lsc = cls;
-
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    uint32_t offset;
-    struct TALER_BlindedDenominationSignature bsig;
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_uint32 ("coin_offset",
-                                    &offset),
-      TALER_PQ_result_spec_blinded_denom_sig ("blind_sig",
-                                              &bsig),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      return;
-    }
-    if (offset >= lsc->sigs_length)
-    {
-      GNUNET_break_op (0);
-      GNUNET_PQ_cleanup_result (rs);
-      continue;
-    }
-    /* Must be NULL due to UNIQUE constraint on offset and
-       requirement that client launched us with 'sigs'
-       pre-initialized to NULL. */
-    lsc->sigs[offset] = bsig;
-  }
-}
-
-
-/**
- * Lookup pickup details for pickup @a pickup_id.
- *
- * @param cls closure, typically a connection to the db
- * @param instance_id which instance should we lookup reward details for
- * @param reward_id which reward should we lookup details on
- * @param pickup_id which pickup should we lookup details on
- * @param[out] exchange_url which exchange is the reward withdrawn from
- * @param[out] reserve_priv private key the reward is withdrawn from (set if 
still available!)
- * @param sigs_length length of the @a sigs array
- * @param[out] sigs set to the (blind) signatures we have for this @a 
pickup_id,
- *              those that are unavailable are left at NULL
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_pickup (void *cls,
-                        const char *instance_id,
-                        const struct TALER_RewardIdentifierP *reward_id,
-                        const struct TALER_PickupIdentifierP *pickup_id,
-                        char **exchange_url,
-                        struct TALER_ReservePrivateKeyP *reserve_priv,
-                        unsigned int sigs_length,
-                        struct TALER_BlindedDenominationSignature sigs[])
-{
-  struct PostgresClosure *pg = cls;
-  uint64_t pickup_serial;
-
-  {
-    struct GNUNET_PQ_QueryParam params[] = {
-      GNUNET_PQ_query_param_string (instance_id),
-      GNUNET_PQ_query_param_auto_from_type (reward_id),
-      GNUNET_PQ_query_param_auto_from_type (pickup_id),
-      GNUNET_PQ_query_param_end
-    };
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_string ("exchange_url",
-                                    exchange_url),
-      GNUNET_PQ_result_spec_auto_from_type ("reserve_priv",
-                                            reserve_priv),
-      GNUNET_PQ_result_spec_uint64 ("pickup_serial",
-                                    &pickup_serial),
-      GNUNET_PQ_result_spec_end
-    };
-    enum GNUNET_DB_QueryStatus qs;
-
-    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "lookup_pickup",
-                                                   params,
-                                                   rs);
-    if (qs <= 0)
-      return qs;
-  }
-  {
-    struct GNUNET_PQ_QueryParam params[] = {
-      GNUNET_PQ_query_param_uint64 (&pickup_serial),
-      GNUNET_PQ_query_param_end
-    };
-    struct LookupSignaturesContext lsc = {
-      .sigs_length = sigs_length,
-      .sigs = sigs
-    };
-
-    return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                                 "lookup_pickup_signatures",
-                                                 params,
-                                                 &lookup_signatures_cb,
-                                                 &lsc);
-  }
-}
-
-
-/**
- * Lookup reward details for reward @a reward_id.
- *
- * @param cls closure, typically a connection to the db
- * @param instance_id which instance should we lookup reward details for
- * @param reward_id which reward should we lookup details on
- * @param[out] total_authorized amount how high is the reward (with fees)
- * @param[out] total_picked_up how much of the reward was so far picked up 
(with fees)
- * @param[out] expiration set to when the reward expires
- * @param[out] exchange_url set to the exchange URL where the reserve is
- * @param[out] next_url set to the URL where the wallet should navigate after 
getting the reward
- * @param[out] reserve_priv set to private key of reserve to be debited
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_reward (void *cls,
-                        const char *instance_id,
-                        const struct TALER_RewardIdentifierP *reward_id,
-                        struct TALER_Amount *total_authorized,
-                        struct TALER_Amount *total_picked_up,
-                        struct GNUNET_TIME_Timestamp *expiration,
-                        char **exchange_url,
-                        char **next_url,
-                        struct TALER_ReservePrivateKeyP *reserve_priv)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_auto_from_type (reward_id),
-    GNUNET_PQ_query_param_end
-  };
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    TALER_PQ_result_spec_amount_with_currency ("amount",
-                                               total_authorized),
-    TALER_PQ_result_spec_amount_with_currency ("picked_up",
-                                               total_picked_up),
-    GNUNET_PQ_result_spec_timestamp ("expiration",
-                                     expiration),
-    GNUNET_PQ_result_spec_string ("exchange_url",
-                                  exchange_url),
-    GNUNET_PQ_result_spec_string ("next_url",
-                                  next_url),
-    GNUNET_PQ_result_spec_auto_from_type ("reserve_priv",
-                                          reserve_priv),
-    GNUNET_PQ_result_spec_end
-  };
-
-  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "lookup_reward",
-                                                   params,
-                                                   rs);
-}
-
-
-/**
- * Context used for postgres_lookup_rewards().
- */
-struct LookupMerchantRewardsContext
-{
-  /**
-   * Postgres context.
-   */
-  struct PostgresClosure *pg;
-
-  /**
-   * Function to call with the results.
-   */
-  TALER_MERCHANTDB_RewardsCallback cb;
-
-  /**
-   * Closure for @a cb.
-   */
-  void *cb_cls;
-
-  /**
-   * Internal result.
-   */
-  enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about rewards.
- *
- * @param[in,out] cls of type `struct LookupRewardsContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_rewards_cb (void *cls,
-                   PGresult *result,
-                   unsigned int num_results)
-{
-  struct LookupMerchantRewardsContext *plc = cls;
-
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    uint64_t row_id;
-    struct TALER_RewardIdentifierP reward_id;
-    struct TALER_Amount reward_amount;
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_uint64 ("reward_serial",
-                                    &row_id),
-      GNUNET_PQ_result_spec_auto_from_type ("reward_id",
-                                            &reward_id),
-      TALER_PQ_result_spec_amount_with_currency ("amount",
-                                                 &reward_amount),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      plc->qs = GNUNET_DB_STATUS_HARD_ERROR;
-      return;
-    }
-    plc->cb (plc->cb_cls,
-             row_id,
-             reward_id,
-             reward_amount);
-    GNUNET_PQ_cleanup_result (rs);
-  }
-}
-
-
-/**
- * Lookup rewards
- *
- * @param cls closure, typically a connection to the db
- * @param instance_id which instance should we lookup rewards for
- * @param expired should we include expired rewards?
- * @param limit maximum number of results to return, positive for
- *   ascending row id, negative for descending
- * @param offset row id to start returning results from
- * @param cb function to call with reward data
- * @param cb_cls closure for @a cb
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_rewards (void *cls,
-                         const char *instance_id,
-                         enum TALER_EXCHANGE_YesNoAll expired,
-                         int64_t limit,
-                         uint64_t offset,
-                         TALER_MERCHANTDB_RewardsCallback cb,
-                         void *cb_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct LookupMerchantRewardsContext plc = {
-    .pg = pg,
-    .cb = cb,
-    .cb_cls = cb_cls
-  };
-  uint64_t ulimit = (limit > 0) ? limit : -limit;
-  uint8_t bexpired;
-  struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_uint64 (&ulimit),
-    GNUNET_PQ_query_param_uint64 (&offset),
-    GNUNET_PQ_query_param_absolute_time (&now),
-    GNUNET_PQ_query_param_auto_from_type (&bexpired),
-    GNUNET_PQ_query_param_end
-  };
-  enum GNUNET_DB_QueryStatus qs;
-  char stmt[128];
-
-  bexpired = (TALER_EXCHANGE_YNA_YES == expired);
-  GNUNET_snprintf (stmt,
-                   sizeof (stmt),
-                   "lookup_rewards_%s%s",
-                   (limit > 0) ? "inc" : "dec",
-                   (TALER_EXCHANGE_YNA_ALL == expired) ? "" : "_expired");
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             stmt,
-                                             params,
-                                             &lookup_rewards_cb,
-                                             &plc);
-  if (0 != plc.qs)
-    return plc.qs;
-  return qs;
-}
-
-
-/**
- * Closure for #lookup_pickup_details_cb().
- */
-struct LookupRewardDetailsContext
-{
-  /**
-   * Length of the @e sigs array
-   */
-  unsigned int *pickups_length;
-
-  /**
-   * Where to store the signatures.
-   */
-  struct TALER_MERCHANTDB_PickupDetails **pickups;
-
-  /**
-   * Database handle.
-   */
-  struct PostgresClosure *pg;
-
-  /**
-   * Transaction status.
-   */
-  enum GNUNET_DB_QueryStatus qs;
-
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about pickups.
- *
- * @param[in,out] cls of type `struct LookupRewardDetailsContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_pickup_details_cb (void *cls,
-                          PGresult *result,
-                          unsigned int num_results)
-{
-  struct LookupRewardDetailsContext *ltdc = cls;
-
-  *ltdc->pickups_length = num_results;
-  *ltdc->pickups = GNUNET_new_array (num_results,
-                                     struct TALER_MERCHANTDB_PickupDetails);
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    struct TALER_MERCHANTDB_PickupDetails *pd = &((*ltdc->pickups)[i]);
-    uint64_t num_planchets = 0;
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_auto_from_type ("pickup_id",
-                                            &pd->pickup_id),
-      TALER_PQ_result_spec_amount_with_currency ("amount",
-                                                 &pd->requested_amount),
-      GNUNET_PQ_result_spec_uint64 ("num_planchets",
-                                    &num_planchets),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      ltdc->qs = GNUNET_DB_STATUS_HARD_ERROR;
-      GNUNET_array_grow (*ltdc->pickups,
-                         *ltdc->pickups_length,
-                         0);
-      return;
-    }
-
-    pd->num_planchets = num_planchets;
-  }
-}
-
-
-/**
- * Lookup reward details for reward @a reward_id.
- *
- * @param cls closure, typically a connection to the db
- * @param instance_id which instance should we lookup reward details for
- * @param reward_id which reward should we lookup details on
- * @param fpu should we fetch details about individual pickups
- * @param[out] total_authorized amount how high is the reward (with fees)
- * @param[out] total_picked_up how much of the reward was so far picked up 
(with fees)
- * @param[out] justification why was the reward approved
- * @param[out] expiration set to when the reward expires
- * @param[out] reserve_pub set to which reserve is debited
- * @param[out] pickups_length set to the length of @e pickups
- * @param[out] pickups if @a fpu is true, set to details about the pickup 
operations
- * @return transaction status,
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_reward_details (void *cls,
-                                const char *instance_id,
-                                const struct TALER_RewardIdentifierP 
*reward_id,
-                                bool fpu,
-                                struct TALER_Amount *total_authorized,
-                                struct TALER_Amount *total_picked_up,
-                                char **justification,
-                                struct GNUNET_TIME_Timestamp *expiration,
-                                struct TALER_ReservePublicKeyP *reserve_pub,
-                                unsigned int *pickups_length,
-                                struct TALER_MERCHANTDB_PickupDetails 
**pickups)
-{
-  struct PostgresClosure *pg = cls;
-  uint64_t reward_serial;
-  enum GNUNET_DB_QueryStatus qs;
-  {
-    struct GNUNET_PQ_QueryParam params[] = {
-      GNUNET_PQ_query_param_string (instance_id),
-      GNUNET_PQ_query_param_auto_from_type (reward_id),
-      GNUNET_PQ_query_param_end
-    };
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_uint64 ("reward_serial",
-                                    &reward_serial),
-      TALER_PQ_result_spec_amount_with_currency ("amount",
-                                                 total_authorized),
-      TALER_PQ_result_spec_amount_with_currency ("picked_up",
-                                                 total_picked_up),
-      GNUNET_PQ_result_spec_string ("justification",
-                                    justification),
-      GNUNET_PQ_result_spec_timestamp ("expiration",
-                                       expiration),
-      GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
-                                            reserve_pub),
-      GNUNET_PQ_result_spec_end
-    };
-
-    check_connection (pg);
-    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "lookup_reward_details",
-                                                   params,
-                                                   rs);
-    if (qs <= 0)
-      return qs;
-    if (! fpu)
-    {
-      *pickups_length = 0;
-      *pickups = NULL;
-      return qs;
-    }
-  }
-  {
-    struct GNUNET_PQ_QueryParam params[] = {
-      GNUNET_PQ_query_param_uint64 (&reward_serial),
-      GNUNET_PQ_query_param_end
-    };
-
-    struct LookupRewardDetailsContext ltdc = {
-      .pickups_length = pickups_length,
-      .pickups = pickups,
-      .pg = pg,
-      .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
-    };
-
-    qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                               "lookup_pickup_details",
-                                               params,
-                                               &lookup_pickup_details_cb,
-                                               &ltdc);
-    if (qs < 0)
-      return qs;
-    return ltdc.qs;
-  }
-}
-
-
-/**
- * Insert blind signature obtained from the exchange during a
- * reward pickup operation.
- *
- * @param cls closure, typically a connection to the db
- * @param pickup_id unique ID for the operation
- * @param offset offset of the blind signature for the pickup
- * @param blind_sig the blind signature
- * @return transaction status, usually
- *      #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success
- *      #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a credit_uuid already known
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_pickup_blind_signature (
-  void *cls,
-  const struct TALER_PickupIdentifierP *pickup_id,
-  uint32_t offset,
-  const struct TALER_BlindedDenominationSignature *blind_sig)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_auto_from_type (pickup_id),
-    GNUNET_PQ_query_param_uint32 (&offset),
-    TALER_PQ_query_param_blinded_denom_sig (blind_sig),
-    GNUNET_PQ_query_param_end
-  };
-
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "insert_pickup_blind_signature",
-                                             params);
-}
-
-
-/**
- * Delete information about a webhook.
- *
- * @param cls closure
- * @param instance_id instance to delete webhook of
- * @param webhook_id webhook to delete
- * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
- *           if webhook unknown.
- */
-static enum GNUNET_DB_QueryStatus
-postgres_delete_webhook (void *cls,
-                         const char *instance_id,
-                         const char *webhook_id)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_string (webhook_id),
-    GNUNET_PQ_query_param_end
-  };
-
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "delete_webhook",
-                                             params);
-}
-
-
-/**
- * Insert details about a particular webhook.
- *
- * @param cls closure
- * @param instance_id instance to insert webhook for
- * @param webhook_id webhook identifier of webhook to insert
- * @param wb the webhook details to insert
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_webhook (void *cls,
-                         const char *instance_id,
-                         const char *webhook_id,
-                         const struct TALER_MERCHANTDB_WebhookDetails *wb)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_string (webhook_id),
-    GNUNET_PQ_query_param_string (wb->event_type),
-    GNUNET_PQ_query_param_string (wb->url),
-    GNUNET_PQ_query_param_string (wb->http_method),
-    (NULL == wb->header_template)
-    ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_string (wb->header_template),
-    (NULL == wb->body_template)
-    ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_string (wb->body_template),
-    GNUNET_PQ_query_param_end
-  };
-
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "insert_webhook",
-                                             params);
-}
-
-
-/**
- * Update details about a particular webhook.
- *
- * @param cls closure
- * @param instance_id instance to update template for
- * @param webhook_id webhook to update
- * @param wb update to the webhook details on success, can be NULL
- *             (in that case we only want to check if the webhook exists)
- * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the 
webhook
- *         does not yet exist.
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_webhook (void *cls,
-                         const char *instance_id,
-                         const char *webhook_id,
-                         const struct TALER_MERCHANTDB_WebhookDetails *wb)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_string (webhook_id),
-    GNUNET_PQ_query_param_string (wb->event_type),
-    GNUNET_PQ_query_param_string (wb->url),
-    GNUNET_PQ_query_param_string (wb->http_method),
-    (NULL == wb->header_template)
-    ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_string (wb->header_template),
-    (NULL == wb->body_template)
-    ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_string (wb->body_template),
-    GNUNET_PQ_query_param_end
-  };
-
-
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "update_webhook",
-                                             params);
-}
-
-
-/**
- * Context used for postgres_lookup_webhook().
- */
-struct LookupWebhookContext
-{
-  /**
-   * Function to call with the results.
-   */
-  TALER_MERCHANTDB_WebhooksCallback cb;
-
-  /**
-   * Closure for @a cb.
-   */
-  void *cb_cls;
-
-  /**
-   * Did database result extraction fail?
-   */
-  bool extract_failed;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about webhook.
- *
- * @param[in,out] cls of type `struct LookupWebhookContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_webhooks_cb (void *cls,
-                    PGresult *result,
-                    unsigned int num_results)
-{
-  struct LookupWebhookContext *wlc = cls;
-
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    char *webhook_id;
-    char *event_type;
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_string ("webhook_id",
-                                    &webhook_id),
-      GNUNET_PQ_result_spec_string ("event_type",
-                                    &event_type),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      wlc->extract_failed = true;
-      return;
-    }
-    wlc->cb (wlc->cb_cls,
-             webhook_id,
-             event_type);
-    GNUNET_PQ_cleanup_result (rs);
-  }
-}
-
-
-/**
- * Lookup all of the webhooks the given instance has configured.
- *
- * @param cls closure
- * @param instance_id instance to lookup webhook for
- * @param cb function to call on all webhook found
- * @param cb_cls closure for @a cb
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_webhooks (void *cls,
-                          const char *instance_id,
-                          TALER_MERCHANTDB_WebhooksCallback cb,
-                          void *cb_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct LookupWebhookContext wlc = {
-    .cb = cb,
-    .cb_cls = cb_cls,
-    /* Can be overwritten by the lookup_webhook_cb */
-    .extract_failed = false,
-  };
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_end
-  };
-  enum GNUNET_DB_QueryStatus qs;
-
-  check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             "lookup_webhooks",
-                                             params,
-                                             &lookup_webhooks_cb,
-                                             &wlc);
-  /* If there was an error inside lookup_webhook_cb, return a hard error. */
-  if (wlc.extract_failed)
-    return GNUNET_DB_STATUS_HARD_ERROR;
-  return qs;
-}
-
-
-/**
- * Lookup details about a particular webhook.
- *
- * @param cls closure
- * @param instance_id instance to lookup webhook for
- * @param webhook_id webhook to lookup
- * @param[out] wb set to the webhook details on success, can be NULL
- *             (in that case we only want to check if the webhook exists)
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_webhook (void *cls,
-                         const char *instance_id,
-                         const char *webhook_id,
-                         struct TALER_MERCHANTDB_WebhookDetails *wb)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_string (webhook_id),
-    GNUNET_PQ_query_param_end
-  };
-
-  if (NULL == wb)
-  {
-    struct GNUNET_PQ_ResultSpec rs_null[] = {
-      GNUNET_PQ_result_spec_end
-    };
-
-    check_connection (pg);
-    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                     "lookup_webhook",
-                                                     params,
-                                                     rs_null);
-  }
-  else
-  {
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_string ("event_type",
-                                    &wb->event_type),
-      GNUNET_PQ_result_spec_string ("url",
-                                    &wb->url),
-      GNUNET_PQ_result_spec_string ("http_method",
-                                    &wb->http_method),
-      GNUNET_PQ_result_spec_allow_null (
-        GNUNET_PQ_result_spec_string ("header_template",
-                                      &wb->header_template),
-        NULL),
-      GNUNET_PQ_result_spec_allow_null (
-        GNUNET_PQ_result_spec_string ("body_template",
-                                      &wb->body_template),
-        NULL),
-      GNUNET_PQ_result_spec_end
-    };
-
-    check_connection (pg);
-    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                     "lookup_webhook",
-                                                     params,
-                                                     rs);
-  }
-}
-
-
-/**
- * Context used for postgres_lookup_webhook().
- */
-struct LookupWebhookDetailContext
-{
-  /**
-   * Function to call with the results.
-   */
-  TALER_MERCHANTDB_WebhookDetailCallback cb;
-
-  /**
-   * Closure for @a cb.
-   */
-  void *cb_cls;
-
-  /**
-   * Did database result extraction fail?
-   */
-  bool extract_failed;
-};
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about webhook.
- *
- * @param[in,out] cls of type `struct LookupPendingWebhookContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_webhook_by_event_cb (void *cls,
-                            PGresult *result,
-                            unsigned int num_results)
-{
-  struct LookupWebhookDetailContext *wlc = cls;
-
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    uint64_t webhook_serial;
-    char *event_type;
-    char *url;
-    char *http_method;
-    char *header_template;
-    char *body_template;
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_uint64 ("webhook_serial",
-                                    &webhook_serial),
-      GNUNET_PQ_result_spec_string ("event_type",
-                                    &event_type),
-      GNUNET_PQ_result_spec_string ("url",
-                                    &url),
-      GNUNET_PQ_result_spec_string ("http_method",
-                                    &http_method),
-      GNUNET_PQ_result_spec_allow_null (
-        GNUNET_PQ_result_spec_string ("header_template",
-                                      &header_template),
-        NULL),
-      GNUNET_PQ_result_spec_allow_null (
-        GNUNET_PQ_result_spec_string ("body_template",
-                                      &body_template),
-        NULL),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      wlc->extract_failed = true;
-      return;
-    }
-    wlc->cb (wlc->cb_cls,
-             webhook_serial,
-             event_type,
-             url,
-             http_method,
-             header_template,
-             body_template);
-    GNUNET_PQ_cleanup_result (rs);
-  }
-}
-
-
-/**
-   * Lookup webhook by event
-   *
-   * @param cls closure
-   * @param instance_id instance to lookup webhook for
-   * @param event_type event that we need to put in the pending webhook
-   * @param[out] cb set to the webhook details on success
-   * @param cb_cls callback closure
-   * @return database result code
-   */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_webhook_by_event (void *cls,
-                                  const char *instance_id,
-                                  const char *event_type,
-                                  TALER_MERCHANTDB_WebhookDetailCallback cb,
-                                  void *cb_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct LookupWebhookDetailContext wlc = {
-    .cb = cb,
-    .cb_cls = cb_cls,
-    .extract_failed = false,
-  };
-
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_string (event_type),
-    GNUNET_PQ_query_param_end
-  };
-  enum GNUNET_DB_QueryStatus qs;
-
-  check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             "lookup_webhook_by_event",
-                                             params,
-                                             &lookup_webhook_by_event_cb,
-                                             &wlc);
-
-  if (wlc.extract_failed)
-    return GNUNET_DB_STATUS_HARD_ERROR;
-  return qs;
-}
-
-
-/**
- * Insert webhook in the pending webhook.
- *
- * @param cls closure
- * @param instance_id instance to insert webhook for
- * @param webhook_serial webhook to insert in the pending webhook
- * @param url to make the request to
- * @param http_method for the webhook
- * @param header of the webhook
- * @param body of the webhook
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_pending_webhook (void *cls,
-                                 const char *instance_id,
-                                 uint64_t webhook_serial,
-                                 const char *url,
-                                 const char *http_method,
-                                 const char *header,
-                                 const char *body)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_uint64 (&webhook_serial),
-    GNUNET_PQ_query_param_string (url),
-    GNUNET_PQ_query_param_string (http_method),
-    NULL == header
-    ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_string (header),
-    NULL == body
-    ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_string (body),
-    GNUNET_PQ_query_param_end
-  };
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "insert_pending_webhook",
-                                             params);
-}
-
-
-/**
- * Context used for postgres_lookup_future_webhook().
- */
-struct LookupPendingWebhookContext
-{
-  /**
-   * Function to call with the results.
-   */
-  TALER_MERCHANTDB_PendingWebhooksCallback cb;
-
-  /**
-   * Closure for @a cb.
-   */
-  void *cb_cls;
-
-  /**
-   * Did database result extraction fail?
-   */
-  bool extract_failed;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about webhook.
- *
- * @param[in,out] cls of type `struct LookupPendingWebhookContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_pending_webhooks_cb (void *cls,
-                            PGresult *result,
-                            unsigned int num_results)
-{
-  struct LookupPendingWebhookContext *pwlc = cls;
-
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    uint64_t webhook_pending_serial;
-    struct GNUNET_TIME_Absolute next_attempt;
-    uint32_t retries;
-    char *url;
-    char *http_method;
-    char *header = NULL;
-    char *body = NULL;
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_uint64 ("webhook_pending_serial",
-                                    &webhook_pending_serial),
-      GNUNET_PQ_result_spec_absolute_time ("next_attempt",
-                                           &next_attempt),
-      GNUNET_PQ_result_spec_uint32 ("retries",
-                                    &retries),
-      GNUNET_PQ_result_spec_string ("url",
-                                    &url),
-      GNUNET_PQ_result_spec_string ("http_method",
-                                    &http_method),
-      GNUNET_PQ_result_spec_allow_null (
-        GNUNET_PQ_result_spec_string ("header",
-                                      &header),
-        NULL),
-      GNUNET_PQ_result_spec_allow_null (
-        GNUNET_PQ_result_spec_string ("body",
-                                      &body),
-        NULL),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      pwlc->extract_failed = true;
-      return;
-    }
-    pwlc->cb (pwlc->cb_cls,
-              webhook_pending_serial,
-              next_attempt,
-              retries,
-              url,
-              http_method,
-              header,
-              body);
-    GNUNET_PQ_cleanup_result (rs);
-  }
-}
-
-
-/**
- * Lookup the webhook that need to be send in priority.
- * send.
- *
- * @param cls closure
- * @param cb pending webhook callback
- * @param cb_cls callback closure
- */
-// WHERE next_attempt <= now ORDER BY next_attempt ASC
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_pending_webhooks (void *cls,
-                                  TALER_MERCHANTDB_PendingWebhooksCallback cb,
-                                  void *cb_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct LookupPendingWebhookContext pwlc = {
-    .cb = cb,
-    .cb_cls = cb_cls,
-    .extract_failed = false,
-  };
-  struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-  struct GNUNET_PQ_QueryParam params_null[] = {
-    GNUNET_PQ_query_param_absolute_time (&now),
-    GNUNET_PQ_query_param_end
-  };
-
-  enum GNUNET_DB_QueryStatus qs;
-
-  check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             "lookup_pending_webhooks",
-                                             params_null,
-                                             &lookup_pending_webhooks_cb,
-                                             &pwlc);
-
-  if (pwlc.extract_failed)
-    return GNUNET_DB_STATUS_HARD_ERROR;
-  return qs;
-}
-
-
-/**
- * Lookup future webhook in the pending webhook that need to be send.
- * With that we can know how long the system can 'sleep'.
- *
- * @param cls closure
- * @param cb pending webhook callback
- * @param cb_cls callback closure
- */
-// ORDER BY next_attempt ASC LIMIT 1
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_future_webhook (void *cls,
-                                TALER_MERCHANTDB_PendingWebhooksCallback cb,
-                                void *cb_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct LookupPendingWebhookContext pwlc = {
-    .cb = cb,
-    .cb_cls = cb_cls,
-    .extract_failed = false,
-  };
-  struct GNUNET_PQ_QueryParam params_null[] = {
-    GNUNET_PQ_query_param_end
-  };
-
-  enum GNUNET_DB_QueryStatus qs;
-
-  check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             "lookup_future_webhook",
-                                             params_null,
-                                             &lookup_pending_webhooks_cb,
-                                             &pwlc);
-
-  if (pwlc.extract_failed)
-    return GNUNET_DB_STATUS_HARD_ERROR;
-  return qs;
-}
-
-
-/**
-   * Lookup all the webhooks in the pending webhook.
-   * Use by the administrator
-   *
-   * @param cls closure
-   * @param instance_id to lookup webhooks for this instance particularly
-   * @param min_row to see the list of the pending webhook that it is started 
with this minimum row.
-   * @param max_results to see the list of the pending webhook that it is end 
with this max results.
-   * @param cb pending webhook callback
-   * @param cb_cls callback closure
-   */
-// WHERE webhook_pending_serial > min_row ORDER BY webhook_pending_serial ASC 
LIMIT max_results
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_all_webhooks (void *cls,
-                              const char *instance_id,
-                              uint64_t min_row,
-                              uint32_t max_results,
-                              TALER_MERCHANTDB_PendingWebhooksCallback cb,
-                              void *cb_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct LookupPendingWebhookContext pwlc = {
-    .cb = cb,
-    .cb_cls = cb_cls,
-    .extract_failed = false,
-  };
-  uint64_t max_results64 = max_results;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_uint64 (&min_row),
-    GNUNET_PQ_query_param_uint64 (&max_results64),
-    GNUNET_PQ_query_param_end
-  };
-
-  enum GNUNET_DB_QueryStatus qs;
-
-  check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             "lookup_all_webhooks",
-                                             params,
-                                             &lookup_pending_webhooks_cb,
-                                             &pwlc);
-
-  if (pwlc.extract_failed)
-    return GNUNET_DB_STATUS_HARD_ERROR;
-  return qs;
-}
-
-
-/**
- * Update the pending webhook. It is use if the webhook can't be send.
- *
- * @param cls closure
- * @param webhook_pending_serial pending_webhook that need to be update
- * @param next_attempt when to try the webhook next
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_pending_webhook (void *cls,
-                                 uint64_t webhook_pending_serial,
-                                 struct GNUNET_TIME_Absolute next_attempt)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_uint64 (&webhook_pending_serial),
-    GNUNET_PQ_query_param_absolute_time (&next_attempt),
-    GNUNET_PQ_query_param_end
-  };
-
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "update_pending_webhook",
-                                             params);
-}
-
-
-/**
- * Delete a webhook in the pending webhook after the
- * webhook was completed successfully.
- *
- * @param cls closure
- * @param webhook_pending_serial identifies the row that needs to be deleted 
in the pending webhook table
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_delete_pending_webhook (void *cls,
-                                 uint64_t webhook_pending_serial)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_uint64 (&webhook_pending_serial),
-    GNUNET_PQ_query_param_end
-  };
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
-                                             "delete_pending_webhook",
-                                             params);
-}
-
-
 /**
  * Establish connection to the database.
  *
@@ -1900,377 +308,6 @@ postgres_connect (void *cls)
   struct GNUNET_PQ_PreparedStatement ps[] = {
     GNUNET_PQ_make_prepare ("end_transaction",
                             "COMMIT"),
-    /* For postgres_insert_reserve() */
-    GNUNET_PQ_make_prepare ("insert_reserve_key",
-                            "INSERT INTO merchant_reward_reserve_keys"
-                            "(reserve_serial"
-                            ",reserve_priv"
-                            ",exchange_url"
-                            ",master_pub"
-                            ")"
-                            "SELECT reserve_serial, $3, $4, $5"
-                            " FROM merchant_reward_reserves"
-                            " WHERE reserve_pub=$2"
-                            "   AND merchant_serial="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"),
-    /* For postgres_lookup_pending_reserves() */
-    GNUNET_PQ_make_prepare ("lookup_pending_reserves",
-                            "SELECT"
-                            " reserve_pub"
-                            ",merchant_id"
-                            ",exchange_url"
-                            ",merchant_initial_balance"
-                            " FROM merchant_reward_reserves mrr"
-                            " JOIN merchant_instances USING (merchant_serial)"
-                            " JOIN merchant_reward_reserve_keys USING 
(reserve_serial)"
-                            " WHERE (mrr.exchange_initial_balance).val=0"
-                            "   AND (mrr.exchange_initial_balance).frac=0"),
-    /* For postgres_lookup_reserve() */
-    GNUNET_PQ_make_prepare ("lookup_reserve",
-                            "SELECT"
-                            " creation_time"
-                            ",expiration"
-                            ",merchant_initial_balance"
-                            ",exchange_initial_balance"
-                            ",rewards_committed"
-                            ",rewards_picked_up"
-                            ",reserve_priv IS NOT NULL AS active"
-                            ",exchange_url"
-                            ",master_pub"
-                            " FROM merchant_reward_reserves"
-                            " FULL OUTER JOIN merchant_reward_reserve_keys 
USING (reserve_serial)"
-                            " WHERE reserve_pub = $2"
-                            "   AND merchant_serial ="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"),
-    /* For postgres_lookup_reserve() */
-    GNUNET_PQ_make_prepare ("lookup_reserve_rewards",
-                            "SELECT"
-                            " justification"
-                            ",reward_id"
-                            ",amount"
-                            " FROM merchant_rewards"
-                            " WHERE reserve_serial ="
-                            "  (SELECT reserve_serial"
-                            "     FROM merchant_reward_reserves"
-                            "      WHERE reserve_pub=$2"
-                            "        AND merchant_serial ="
-                            "       (SELECT merchant_serial"
-                            "          FROM merchant_instances"
-                            "         WHERE merchant_id=$1))"),
-    /* for postgres_delete_reserve() */
-    GNUNET_PQ_make_prepare ("delete_reserve",
-                            "DELETE"
-                            " FROM merchant_reward_reserve_keys"
-                            " WHERE reserve_serial="
-                            "   (SELECT reserve_serial"
-                            "      FROM merchant_reward_reserves"
-                            "       WHERE reserve_pub=$2"
-                            "         AND merchant_serial="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1))"),
-    /* for postgres_purge_reserve() */
-    GNUNET_PQ_make_prepare ("purge_reserve",
-                            "DELETE"
-                            "   FROM merchant_reward_reserves"
-                            "  WHERE reserve_pub=$2"
-                            "    AND merchant_serial="
-                            "    (SELECT merchant_serial"
-                            "       FROM merchant_instances"
-                            "      WHERE merchant_id=$1)"),
-    /* For postgres_lookup_pickup() */
-    GNUNET_PQ_make_prepare ("lookup_pickup",
-                            "SELECT"
-                            " exchange_url"
-                            ",reserve_priv"
-                            ",pickup_serial"
-                            " FROM merchant_reward_pickups"
-                            " JOIN merchant_rewards USING (reward_serial)"
-                            " JOIN merchant_reward_reserves USING 
(reserve_serial)"
-                            " JOIN merchant_reward_reserve_keys USING 
(reserve_serial)"
-                            " WHERE pickup_id = $3"
-                            "   AND reward_id = $2"
-                            "   AND merchant_serial ="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"),
-    /* For postgres_lookup_pickup() */
-    GNUNET_PQ_make_prepare ("lookup_pickup_signatures",
-                            "SELECT"
-                            " coin_offset"
-                            ",blind_sig"
-                            " FROM merchant_reward_pickup_signatures"
-                            " WHERE pickup_serial = $1"),
-
-    /* For postgres_lookup_reward() */
-    GNUNET_PQ_make_prepare ("lookup_reward",
-                            "SELECT"
-                            " amount"
-                            ",picked_up"
-                            ",merchant_rewards.expiration"
-                            ",exchange_url"
-                            ",next_url"
-                            ",reserve_priv"
-                            " FROM merchant_rewards"
-                            " JOIN merchant_reward_reserves USING 
(reserve_serial)"
-                            " JOIN merchant_reward_reserve_keys USING 
(reserve_serial)"
-                            " WHERE reward_id = $2"
-                            "   AND merchant_serial ="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"),
-    /* For postgres_lookup_reward() */
-    GNUNET_PQ_make_prepare ("lookup_rewards_inc",
-                            "SELECT"
-                            " reward_serial"
-                            ",reward_id"
-                            ",amount"
-                            ",CAST($4 as BIGINT)" /* otherwise $4 is unused 
and Postgres unhappy */
-                            ",CAST($5 as BOOL)" /* otherwise $5 is unused and 
Postgres unhappy */
-                            " FROM merchant_rewards"
-                            " JOIN merchant_reward_reserves USING 
(reserve_serial)"
-                            " WHERE merchant_serial ="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"
-                            "   AND"
-                            "    reward_serial > $3"
-                            " ORDER BY reward_serial ASC"
-                            " LIMIT $2"),
-    GNUNET_PQ_make_prepare ("lookup_rewards_dec",
-                            "SELECT"
-                            " reward_serial"
-                            ",reward_id"
-                            ",amount"
-                            ",CAST($4 as BIGINT)" /* otherwise $4 is unused 
and Postgres unhappy */
-                            ",CAST($5 as BOOL)" /* otherwise $5 is unused and 
Postgres unhappy */
-                            " FROM merchant_rewards"
-                            " JOIN merchant_reward_reserves USING 
(reserve_serial)"
-                            " WHERE merchant_serial ="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"
-                            "   AND"
-                            "    reward_serial < $3"
-                            " ORDER BY reward_serial DESC"
-                            " LIMIT $2"),
-    GNUNET_PQ_make_prepare ("lookup_rewards_inc_expired",
-                            "SELECT"
-                            " reward_serial"
-                            ",reward_id"
-                            ",amount"
-                            " FROM merchant_rewards"
-                            " JOIN merchant_reward_reserves USING 
(reserve_serial)"
-                            " WHERE merchant_serial ="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"
-                            "   AND"
-                            "    reward_serial > $3"
-                            "   AND"
-                            "    CAST($5 as BOOL) = 
(merchant_rewards.expiration < $4)"
-                            " ORDER BY reward_serial ASC"
-                            " LIMIT $2"),
-    GNUNET_PQ_make_prepare ("lookup_rewards_dec_expired",
-                            "SELECT"
-                            " reward_serial"
-                            ",reward_id"
-                            ",amount"
-                            " FROM merchant_rewards"
-                            " JOIN merchant_reward_reserves USING 
(reserve_serial)"
-                            " WHERE merchant_serial ="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"
-                            "   AND"
-                            "    reward_serial < $3"
-                            "   AND"
-                            "    CAST($5 as BOOL) = 
(merchant_rewards.expiration < $4)"
-                            " ORDER BY reward_serial DESC"
-                            " LIMIT $2"),
-    /* for postgres_lookup_reward_details() */
-    GNUNET_PQ_make_prepare ("lookup_reward_details",
-                            "SELECT"
-                            " reward_serial"
-                            ",amount"
-                            ",picked_up"
-                            ",justification"
-                            ",merchant_rewards.expiration"
-                            ",reserve_pub"
-                            " FROM merchant_rewards"
-                            " JOIN merchant_reward_reserves USING 
(reserve_serial)"
-                            " WHERE reward_id = $2"
-                            "   AND merchant_serial ="
-                            "     (SELECT merchant_serial"
-                            "        FROM merchant_instances"
-                            "       WHERE merchant_id=$1)"),
-    /* for postgres_lookup_reward_details() */
-    GNUNET_PQ_make_prepare ("lookup_pickup_details",
-                            "SELECT"
-                            " pickup_id"
-                            ",amount"
-                            ",COUNT(blind_sig) AS num_planchets"
-                            " FROM merchant_reward_pickups"
-                            " JOIN merchant_reward_pickup_signatures USING 
(pickup_serial)"
-                            " WHERE reward_serial = $1"
-                            " GROUP BY pickup_serial"),
-    /* for postgres_insert_pickup_blind_signature() */
-    GNUNET_PQ_make_prepare ("insert_pickup_blind_signature",
-                            "INSERT INTO merchant_reward_pickup_signatures"
-                            "(pickup_serial"
-                            ",coin_offset"
-                            ",blind_sig"
-                            ") "
-                            "SELECT"
-                            " pickup_serial, $2, $3"
-                            " FROM merchant_reward_pickups"
-                            " WHERE pickup_id=$1"),
-    /* for postgres_lookup_webhooks() */
-    GNUNET_PQ_make_prepare ("lookup_webhooks",
-                            "SELECT"
-                            " webhook_id"
-                            ",event_type"
-                            " FROM merchant_webhook"
-                            " JOIN merchant_instances"
-                            "   USING (merchant_serial)"
-                            " WHERE merchant_instances.merchant_id=$1"),
-    /* for postgres_lookup_webhook() */
-    GNUNET_PQ_make_prepare ("lookup_webhook",
-                            "SELECT"
-                            " event_type"
-                            ",url"
-                            ",http_method"
-                            ",header_template"
-                            ",body_template"
-                            " FROM merchant_webhook"
-                            " JOIN merchant_instances"
-                            "   USING (merchant_serial)"
-                            " WHERE merchant_instances.merchant_id=$1"
-                            "   AND merchant_webhook.webhook_id=$2"),
-    /* for postgres_delete_webhook() */
-    GNUNET_PQ_make_prepare ("delete_webhook",
-                            "DELETE"
-                            " FROM merchant_webhook"
-                            " WHERE merchant_webhook.merchant_serial="
-                            "     (SELECT merchant_serial "
-                            "        FROM merchant_instances"
-                            "        WHERE merchant_id=$1)"
-                            "   AND merchant_webhook.webhook_id=$2"),
-    /* for postgres_insert_webhook() */
-    GNUNET_PQ_make_prepare ("insert_webhook",
-                            "INSERT INTO merchant_webhook"
-                            "(merchant_serial"
-                            ",webhook_id"
-                            ",event_type"
-                            ",url"
-                            ",http_method"
-                            ",header_template"
-                            ",body_template"
-                            ")"
-                            " SELECT merchant_serial,"
-                            " $2, $3, $4, $5, $6, $7"
-                            " FROM merchant_instances"
-                            " WHERE merchant_id=$1"),
-    /* for postgres_update_webhook() */
-    GNUNET_PQ_make_prepare ("update_webhook",
-                            "UPDATE merchant_webhook SET"
-                            " event_type=$3"
-                            ",url=$4"
-                            ",http_method=$5"
-                            ",header_template=$6"
-                            ",body_template=$7"
-                            " WHERE merchant_serial="
-                            "   (SELECT merchant_serial"
-                            "      FROM merchant_instances"
-                            "      WHERE merchant_id=$1)"
-                            "   AND webhook_id=$2"),
-    /* for postgres_lookup_webhook_by_event() */
-    GNUNET_PQ_make_prepare ("lookup_webhook_by_event",
-                            "SELECT"
-                            " webhook_serial"
-                            ",event_type"
-                            ",url"
-                            ",http_method"
-                            ",header_template"
-                            ",body_template"
-                            " FROM merchant_webhook"
-                            " JOIN merchant_instances"
-                            "   USING (merchant_serial)"
-                            " WHERE merchant_instances.merchant_id=$1"
-                            "  AND event_type=$2"),
-    /* for postgres_delete_pending_webhook() */
-    GNUNET_PQ_make_prepare ("delete_pending_webhook",
-                            "DELETE"
-                            " FROM merchant_pending_webhooks"
-                            " WHERE webhook_pending_serial=$1"),
-    /* for postgres_insert_pending_webhook() */
-    GNUNET_PQ_make_prepare ("insert_pending_webhook",
-                            "INSERT INTO merchant_pending_webhooks"
-                            "(merchant_serial"
-                            ",webhook_serial"
-                            ",url"
-                            ",http_method"
-                            ",header"
-                            ",body"
-                            ")"
-                            " SELECT mi.merchant_serial,"
-                            " $2, $3, $4, $5, $6"
-                            " FROM merchant_instances mi"
-                            " WHERE mi.merchant_id=$1"),
-    /* for postgres_update_pending_webhook() */
-    GNUNET_PQ_make_prepare ("update_pending_webhook",
-                            "UPDATE merchant_pending_webhooks SET"
-                            " retries=retries+1"
-                            ",next_attempt=$2"
-                            " WHERE webhook_pending_serial=$1"),
-    /* for postgres_lookup_pending_webhooks() */
-    GNUNET_PQ_make_prepare ("lookup_pending_webhooks",
-                            "SELECT"
-                            " webhook_pending_serial"
-                            ",next_attempt"
-                            ",retries"
-                            ",url"
-                            ",http_method"
-                            ",header"
-                            ",body"
-                            " FROM merchant_pending_webhooks"
-                            " WHERE next_attempt <= $1"
-                            "   ORDER BY next_attempt ASC"
-                            ),
-    /* for postgres_lookup_future_webhook() */
-    GNUNET_PQ_make_prepare ("lookup_future_webhook",
-                            "SELECT"
-                            " webhook_pending_serial"
-                            ",next_attempt"
-                            ",retries"
-                            ",url"
-                            ",http_method"
-                            ",header"
-                            ",body"
-                            " FROM merchant_pending_webhooks"
-                            " ORDER BY next_attempt ASC LIMIT 1"
-                            ),
-    /* for postgres_lookup_all_webhooks() */
-    GNUNET_PQ_make_prepare ("lookup_all_webhooks",
-                            " SELECT"
-                            " webhook_pending_serial"
-                            ",next_attempt"
-                            ",retries"
-                            ",url"
-                            ",http_method"
-                            ",header"
-                            ",body"
-                            " FROM merchant_pending_webhooks"
-                            " JOIN merchant_instances"
-                            "   USING (merchant_serial)"
-                            " WHERE merchant_instances.merchant_id=$1"
-                            " AND webhook_pending_serial > $2"
-                            "  ORDER BY webhook_pending_serial"
-                            "   ASC LIMIT $3"),
     GNUNET_PQ_PREPARED_STATEMENT_END
   };
   struct GNUNET_PQ_ExecuteStatement es[] = {
@@ -2494,16 +531,24 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
     = &TMH_PG_select_accounts;
   plugin->lookup_reserves
     = &TMH_PG_lookup_reserves;
-  plugin->lookup_pending_reserves = &postgres_lookup_pending_reserves;
-  plugin->lookup_reserve = &postgres_lookup_reserve;
-  plugin->delete_reserve = &postgres_delete_reserve;
-  plugin->purge_reserve = &postgres_purge_reserve;
-  plugin->lookup_pickup = &postgres_lookup_pickup;
-  plugin->lookup_reward = &postgres_lookup_reward;
-  plugin->lookup_rewards = &postgres_lookup_rewards;
-  plugin->lookup_reward_details = &postgres_lookup_reward_details;
-  plugin->insert_pickup_blind_signature =
-    &postgres_insert_pickup_blind_signature;
+  plugin->lookup_pending_reserves
+    = &TMH_PG_lookup_pending_reserves;
+  plugin->lookup_reserve
+    = &TMH_PG_lookup_reserve;
+  plugin->delete_reserve
+    = &TMH_PG_delete_reserve;
+  plugin->purge_reserve
+    = &TMH_PG_purge_reserve;
+  plugin->lookup_pickup
+    = &TMH_PG_lookup_pickup;
+  plugin->lookup_reward
+    = &TMH_PG_lookup_reward;
+  plugin->lookup_rewards
+    = &TMH_PG_lookup_rewards;
+  plugin->lookup_reward_details
+    = &TMH_PG_lookup_reward_details;
+  plugin->insert_pickup_blind_signature
+    = &TMH_PG_insert_pickup_blind_signature;
   plugin->select_open_transfers
     = &TMH_PG_select_open_transfers;
   plugin->insert_exchange_keys
@@ -2526,18 +571,30 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
     = &TMH_PG_authorize_reward;
   plugin->insert_pickup
     = &TMH_PG_insert_pickup;
-  plugin->lookup_webhooks = &postgres_lookup_webhooks;
-  plugin->lookup_webhook = &postgres_lookup_webhook;
-  plugin->delete_webhook = &postgres_delete_webhook;
-  plugin->insert_webhook = &postgres_insert_webhook;
-  plugin->update_webhook = &postgres_update_webhook;
-  plugin->lookup_webhook_by_event = &postgres_lookup_webhook_by_event;
-  plugin->lookup_all_webhooks = &postgres_lookup_all_webhooks;
-  plugin->lookup_future_webhook = &postgres_lookup_future_webhook;
-  plugin->lookup_pending_webhooks = &postgres_lookup_pending_webhooks;
-  plugin->delete_pending_webhook = &postgres_delete_pending_webhook;
-  plugin->insert_pending_webhook = &postgres_insert_pending_webhook;
-  plugin->update_pending_webhook = &postgres_update_pending_webhook;
+  plugin->lookup_webhooks
+    = &TMH_PG_lookup_webhooks;
+  plugin->lookup_webhook
+    = &TMH_PG_lookup_webhook;
+  plugin->delete_webhook
+    = &TMH_PG_delete_webhook;
+  plugin->insert_webhook
+    = &TMH_PG_insert_webhook;
+  plugin->update_webhook
+    = &TMH_PG_update_webhook;
+  plugin->lookup_webhook_by_event
+    = &TMH_PG_lookup_webhook_by_event;
+  plugin->lookup_all_webhooks
+    = &TMH_PG_lookup_all_webhooks;
+  plugin->lookup_future_webhook
+    = &TMH_PG_lookup_future_webhook;
+  plugin->lookup_pending_webhooks
+    = &TMH_PG_lookup_pending_webhooks;
+  plugin->delete_pending_webhook
+    = &TMH_PG_delete_pending_webhook;
+  plugin->insert_pending_webhook
+    = &TMH_PG_insert_pending_webhook;
+  plugin->update_pending_webhook
+    = &TMH_PG_update_pending_webhook;
   plugin->delete_exchange_accounts
     = &TMH_PG_delete_exchange_accounts;
   plugin->select_accounts_by_exchange

-- 
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]