From e3c0320132f88f3d13e1f6d96a6cea9c3334df83 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 1 Jun 2020 14:12:59 +0200 Subject: add logic for activation of reserves to merchant backend DB --- src/backenddb/plugin_merchantdb_postgres.c | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/backenddb/plugin_merchantdb_postgres.c') 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 @@ -3819,6 +3819,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. */ @@ -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; -- cgit v1.2.3