diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-05 16:51:31 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-05 16:51:31 +0200 |
commit | a32fb651ca7680a54d7b016101a7ad1028d1f031 (patch) | |
tree | 59db6134d80b7c5f7e48d175d0e585e30dc18dd1 | |
parent | bd8d4e99a97d7a6cc3931af52b36324920620223 (diff) | |
download | merchant-a32fb651ca7680a54d7b016101a7ad1028d1f031.tar.gz merchant-a32fb651ca7680a54d7b016101a7ad1028d1f031.tar.bz2 merchant-a32fb651ca7680a54d7b016101a7ad1028d1f031.zip |
implement check_deposit()
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 17 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_contract.c | 3 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_track-deposit.c | 68 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_track-transaction.c | 2 |
4 files changed, 48 insertions, 42 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index afff8285..5dab04e6 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -84,11 +84,6 @@ static char *keyfile; struct GNUNET_TIME_Relative wire_transfer_delay; /** - * Which currency is supported by this merchant? - */ -char *TMH_merchant_currency_string; - -/** * Should a "Connection: close" header be added to each HTTP response? */ int TMH_merchant_connection_close; @@ -511,18 +506,6 @@ run (void *cls, GNUNET_SCHEDULER_shutdown (); return; } - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (config, - "taler", - "currency", - &TMH_merchant_currency_string)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "taler", - "currency"); - GNUNET_SCHEDULER_shutdown (); - return; - } if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (config, diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c index 969c0c9e..072f8bad 100644 --- a/src/backend/taler-merchant-httpd_contract.c +++ b/src/backend/taler-merchant-httpd_contract.c @@ -29,9 +29,6 @@ #include "taler-merchant-httpd_responses.h" -extern char *TMH_merchant_currency_string; - - /** * Check that the given JSON array of products is well-formed. * diff --git a/src/backend/taler-merchant-httpd_track-deposit.c b/src/backend/taler-merchant-httpd_track-deposit.c index c7bcc638..5e2cf4f0 100644 --- a/src/backend/taler-merchant-httpd_track-deposit.c +++ b/src/backend/taler-merchant-httpd_track-deposit.c @@ -37,8 +37,6 @@ */ #define TRACK_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)) -extern char *TMH_merchant_currency_string; - /** * Context used for handing /track/deposit requests. @@ -89,15 +87,10 @@ struct DepositTrackContext char *uri; /** - * FIXME: why do we need this? - */ - struct TALER_WireDepositDetails *details; - - /** - * Length of the @e details array. - * FIXME: probably not needed! + * Pointer to the detail that we are currently + * checking in #check_deposit(). */ - unsigned int details_length; + const struct TALER_WireDepositDetails *current_detail; /** * Argument for the /wire/deposits request. @@ -108,6 +101,13 @@ struct DepositTrackContext * Response code to return. */ unsigned int response_code; + + /** + * #GNUNET_NO if we did not find a matching coin. + * #GNUNET_SYSERR if we found a matching coin, but the amounts do not match. + * #GNUNET_OK if we did find a matching coin. + */ + int check_deposit_result; }; @@ -184,8 +184,9 @@ track_deposit_cleanup (struct TM_HandlerContext *hc) /** * Function called with information about a coin that was deposited. * Verify that it matches the information claimed by the exchange. + * Update the `check_deposit_result` field accordingly. * - * @param cls closure FIXME! + * @param cls closure with our `struct DepositTrackContext *` * @param transaction_id of the contract * @param coin_pub public key of the coin * @param amount_with_fee amount the exchange will deposit for this coin @@ -200,7 +201,25 @@ check_deposit (void *cls, const struct TALER_Amount *deposit_fee, const json_t *exchange_proof) { - GNUNET_break (0); // not implemented! + struct DepositTrackContext *rctx = cls; + const struct TALER_WireDepositDetails *wdd = rctx->current_detail; + + if (0 != memcmp (&wdd->coin_pub, + coin_pub, + sizeof (struct TALER_CoinSpendPublicKeyP))) + return; /* not the coin we're looking for */ + if ( (0 != TALER_amount_cmp (amount_with_fee, + &wdd->coin_value)) || + (0 != TALER_amount_cmp (deposit_fee, + &wdd->coin_fee)) ) + { + /* Disagreement between the exchange and us how much this + coin is worth! */ + GNUNET_break_op (0); + rctx->check_deposit_result = GNUNET_SYSERR; + return; + } + rctx->check_deposit_result = GNUNET_OK; } @@ -254,14 +273,10 @@ wire_deposit_cb (void *cls, "Failed to persist wire transfer proof in DB\n"); } - rctx->details_length = details_length; - rctx->details = GNUNET_new_array (details_length, - struct TALER_WireDepositDetails); - memcpy (rctx->details, - details, - details_length * sizeof (struct TALER_WireDepositDetails)); for (i=0;i<details_length;i++) { + rctx->current_detail = &details[i]; + rctx->check_deposit_result = GNUNET_NO; ret = db->find_payments_by_id (rctx, details[i].transaction_id, &check_deposit, @@ -271,12 +286,25 @@ wire_deposit_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to verify existing payment data in DB\n"); } - if (GNUNET_NO == ret) + if ( (GNUNET_NO == ret) || + (GNUNET_NO == rctx->check_deposit_result) ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to find payment data in DB\n"); } - /* FIXME: check result of #check_deposit()! */ + if (GNUNET_SYSERR == rctx->check_deposit_result) + { + /* #check_deposit() failed, do something! */ + GNUNET_break (0); + /* FIXME: generate nicer custom response */ + resume_track_deposit_with_response + (rctx, + MHD_HTTP_FAILED_DEPENDENCY, + TMH_RESPONSE_make_json_pack ("{s:I, s:O}", + "index", (json_int_t) i, + "details", json)); + return; + } ret = db->store_coin_to_transfer (db->cls, details[i].transaction_id, &details[i].coin_pub, diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c index f87cb84b..e75d92aa 100644 --- a/src/backend/taler-merchant-httpd_track-transaction.c +++ b/src/backend/taler-merchant-httpd_track-transaction.c @@ -37,8 +37,6 @@ */ #define TRACK_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)) -extern char *TMH_merchant_currency_string; - /** * Context for a /track/transaction operation. |