diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_reserves.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_reserves.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/backend/taler-merchant-httpd_reserves.c b/src/backend/taler-merchant-httpd_reserves.c new file mode 100644 index 00000000..5876243b --- /dev/null +++ b/src/backend/taler-merchant-httpd_reserves.c @@ -0,0 +1,142 @@ +/* + This file is part of TALER + (C) 2020 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU 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 backend/taler-merchant-httpd_reserves.c + * @brief logic for initially tracking a reserve's status + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_json_lib.h> +#include "taler-merchant-httpd.h" +#include "taler-merchant-httpd_reserves.h" + + +/** + * Our representation of a reserve that we are (still) checking the status of. + */ +struct Reserve +{ + /** + * Reserve's public key. + */ + struct TALER_ReservePublicKeyP reserve_pub; + + /** + * Amount the merchant expects to see in the reserve initially. + * We log a warning if there is a missmatch. + */ + struct TALER_Amount expected_amount; + + /** + * URL of the exchange hosting this reserve. + */ + char *exchange_url; + + /** + * Instance this reserve belongs with. + */ + char *instance_id; +}; + + +/** + * Function called with information about a reserve that we need + * to check the status from at the exchange to see if/when it has + * been filled (and with what amount). + * + * @param cls closure + * @param instance_id for which instance is this reserve + * @param exchange_url base URL of the exchange at which the reserve lives + * @param reserve_pub public key of the reserve + * @param expected_amount how much do we expect to see in the reserve + */ +static void +add_reserve (void *cls, + const char *instance_id, + const char *exchange_url, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_Amount *expected_amount) +{ + struct Reserve *r; + + r = GNUNET_new (struct Reserve); + r->exchange_url = GNUNET_strdup (exchange_url); + r->instance_id = GNUNET_strdup (instance_id); + r->reserve_pub = *reserve_pub; + r->expected_amount = *expected_amount; + // .... +} + + +/** + * Load information about reserves and start querying reserve status. + * Must be called after the database is available. + */ +void +TMH_RESERVES_init (void) +{ + TMH_db->lookup_pending_reserves (TMH_db->cls, + &add_reserve, + NULL); +} + + +/** + * Add a reserve to the list of reserves to check. + * + * @param instance_id which instance is the reserve for + * @param exchange_url URL of the exchange with the reserve + * @param reserve_pub public key of the reserve to check + * @param expected_amount amount the merchant expects to see initially in the reserve + */ +void +TMH_RESERVES_check (const char *instance_id, + const char *exchange_url, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_Amount *expected_amount) +{ + enum GNUNET_DB_QueryStatus qs; + + add_reserve (NULL, + instance_id, + exchange_url, + reserve_pub, + expected_amount); + + // Do this temporarily for testing + qs = TMH_db->activate_reserve (TMH_db->cls, + instance_id, + reserve_pub, + expected_amount); // FIXME: change to REAL amount later! + if (qs <= 0) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to commit reserve activation to database (%d)\n", + (int) qs); + } +} + + +/** + * Stop checking reserve status. + */ +void +TMH_RESERVES_done (void) +{ +} + + +/* end of taler-merchant-httpd_reserves.c */ |