summaryrefslogtreecommitdiff
path: root/src/backenddb/plugin_merchantdb_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-06-01 14:12:59 +0200
committerChristian Grothoff <christian@grothoff.org>2020-06-01 14:12:59 +0200
commite3c0320132f88f3d13e1f6d96a6cea9c3334df83 (patch)
tree0302c171277e073c31fad043e5672813cd8dcb8a /src/backenddb/plugin_merchantdb_postgres.c
parentcd3a94a3c143455350be8e8c0cddbb8dc691da33 (diff)
downloadmerchant-e3c0320132f88f3d13e1f6d96a6cea9c3334df83.tar.gz
merchant-e3c0320132f88f3d13e1f6d96a6cea9c3334df83.tar.bz2
merchant-e3c0320132f88f3d13e1f6d96a6cea9c3334df83.zip
add logic for activation of reserves to merchant backend DB
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 59810047..ca005397 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -3820,6 +3820,39 @@ RETRY:
/**
+ * Confirms @a credit as the amount the exchange claims to have received and
+ * thus really 'activates' the reserve. This has to happen before tips can
+ * be authorized.
+ *
+ * @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
+ * @return transaction status, usually
+ * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_activate_reserve (void *cls,
+ const char *instance_id,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *initial_exchange_balance)
+{
+ 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),
+ TALER_PQ_query_param_amount (initial_exchange_balance),
+ GNUNET_PQ_query_param_end
+ };
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "activate_reserve",
+ params);
+}
+
+
+/**
* Closure for #lookup_accounts_cb.
*/
struct LookupReservesContext
@@ -6865,6 +6898,17 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" FROM merchant_instances"
" WHERE merchant_id=$1",
6),
+ /* For postgres_activate_reserve() */
+ GNUNET_PQ_make_prepare ("activate_reserve",
+ "UPDATE merchant_tip_reserves SET"
+ " exchange_initial_balance_val=$3"
+ " exchange_initial_balance_frac=$4"
+ " WHERE reserve_pub=$2"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1)",
+ 4),
/* For postgres_insert_reserve() */
GNUNET_PQ_make_prepare ("insert_reserve_key",
"INSERT INTO merchant_tip_reserve_keys"
@@ -7250,6 +7294,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->lookup_transfers = &postgres_lookup_transfers;
plugin->store_wire_fee_by_exchange = &postgres_store_wire_fee_by_exchange;
plugin->insert_reserve = &postgres_insert_reserve;
+ plugin->activate_reserve = &postgres_activate_reserve;
plugin->lookup_reserves = &postgres_lookup_reserves;
plugin->lookup_reserve = &postgres_lookup_reserve;
plugin->delete_reserve = &postgres_delete_reserve;