merchant

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

commit e3c0320132f88f3d13e1f6d96a6cea9c3334df83
parent cd3a94a3c143455350be8e8c0cddbb8dc691da33
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon,  1 Jun 2020 14:12:59 +0200

add logic for activation of reserves to merchant backend DB

Diffstat:
Msrc/backenddb/plugin_merchantdb_postgres.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Msrc/include/taler_merchantdb_plugin.h | 20++++++++++++++++++++
2 files changed, 65 insertions(+), 0 deletions(-)

diff --git 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; diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h @@ -1614,6 +1614,26 @@ struct TALER_MERCHANTDB_Plugin /** + * 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 + */ + enum GNUNET_DB_QueryStatus + (*activate_reserve)(void *cls, + const char *instance_id, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_Amount *initial_exchange_balance); + + + /** * Lookup reserves. * * @param cls closure