diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_admin.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_admin.c | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/src/exchange/taler-exchange-httpd_admin.c b/src/exchange/taler-exchange-httpd_admin.c index 8bb4b4988..e40775f51 100644 --- a/src/exchange/taler-exchange-httpd_admin.c +++ b/src/exchange/taler-exchange-httpd_admin.c @@ -27,6 +27,69 @@ #include "taler-exchange-httpd_validation.h" +/** + * Add an incoming transaction to the database. Checks if the + * transaction is fresh (not a duplicate) and if so adds it to + * the database. + * + * @param connection the MHD connection to handle + * @param reserve_pub public key of the reserve + * @param amount amount to add to the reserve + * @param execution_time when did we receive the wire transfer + * @param sender_account_details which account send the funds + * @param transfer_details information that uniquely identifies the transfer + * @return MHD result code + */ +static int +execute_admin_add_incoming (struct MHD_Connection *connection, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_Amount *amount, + struct GNUNET_TIME_Absolute execution_time, + const json_t *sender_account_details, + const json_t *transfer_details) +{ + struct TALER_EXCHANGEDB_Session *session; + int ret; + void *json_str; + + if (NULL == (session = TEH_plugin->get_session (TEH_plugin->cls))) + { + GNUNET_break (0); + return TEH_RESPONSE_reply_internal_db_error (connection, + TALER_EC_DB_SETUP_FAILED); + } + json_str = json_dumps (transfer_details, + JSON_INDENT(2)); + if (NULL == json_str) + { + GNUNET_break (0); + return TEH_RESPONSE_reply_internal_db_error (connection, + TALER_EC_PARSER_OUT_OF_MEMORY); + } + ret = TEH_plugin->reserves_in_insert (TEH_plugin->cls, + session, + reserve_pub, + amount, + execution_time, + sender_account_details, + json_str, + strlen (json_str)); + free (json_str); + if (GNUNET_SYSERR == ret) + { + GNUNET_break (0); + return TEH_RESPONSE_reply_internal_db_error (connection, + TALER_EC_ADMIN_ADD_INCOMING_DB_STORE); + } + return TEH_RESPONSE_reply_json_pack (connection, + MHD_HTTP_OK, + "{s:s}", + "status", + (GNUNET_OK == ret) + ? "NEW" + : "DUP"); +} + /** * Handle a "/admin/add/incoming" request. Parses the @@ -108,12 +171,12 @@ TEH_ADMIN_handler_admin_add_incoming (struct TEH_RequestHandler *rh, TALER_EC_ADMIN_ADD_INCOMING_CURRENCY_UNSUPPORTED, "amount:currency"); } - res = TEH_DB_execute_admin_add_incoming (connection, - &reserve_pub, - &amount, - at, - sender_account_details, - transfer_details); + res = execute_admin_add_incoming (connection, + &reserve_pub, + &amount, + at, + sender_account_details, + transfer_details); GNUNET_JSON_parse_free (spec); return res; } |