diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-11-07 01:20:00 +0100 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-11-07 01:20:00 +0100 |
commit | 697f7170fe09c8d7b627014907eac03a4d1bc4d2 (patch) | |
tree | 7f16d3b3952d97c68f06515c4d8c8a0eab4b5699 | |
parent | 16a906b94b148371ccd4088e5e2e786d7260b575 (diff) | |
download | merchant-697f7170fe09c8d7b627014907eac03a4d1bc4d2.tar.gz merchant-697f7170fe09c8d7b627014907eac03a4d1bc4d2.tar.bz2 merchant-697f7170fe09c8d7b627014907eac03a4d1bc4d2.zip |
Adding check of payment completion against the global array of deposit
confirmation from within the deposit callbacks
-rw-r--r-- | src/backend-lib/merchant_db.h | 14 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 40 | ||||
-rw-r--r-- | src/include/merchant.h | 14 |
3 files changed, 58 insertions, 10 deletions
diff --git a/src/backend-lib/merchant_db.h b/src/backend-lib/merchant_db.h index c748002e..aa157712 100644 --- a/src/backend-lib/merchant_db.h +++ b/src/backend-lib/merchant_db.h @@ -117,6 +117,20 @@ long long MERCHANT_DB_get_contract_product (PGconn *conn, uint64_t contract_id); +/** + * Update the pending column of a deposit permission + * @param conn handle to DB + * @param transaction_id identification number of the deposit to + * update + * @param pending true if still pending, false otherwise (i.e. the + * mint did respond something) + * @return GNUNET_OK if successful, GNUNET_SYSERR upon errors + */ +uint32_t +MERCHANT_DB_update_deposit_permission (PGconn *conn, + uint64_t transaction_id, + unsigned int pending); + unsigned int MERCHANT_DB_checkout_create (PGconn *conn, struct GNUNET_CRYPTO_rsa_PublicKey *coin_pub, diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index 0a1de887..5a33eed5 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -119,10 +119,36 @@ deposit_fee_from_coin_aggregate (struct MHD_Connection *connection, void deposit_cb (void *cls, unsigned int http_status, json_t *proof) { - if (MHD_HTTP_OK == http_status) - ; /* set pending to false in DB and notify the frontend with "OK" */ - else - ; /* set a timeout to retry */ + /* NOTE: what if the mint doesn't respond? Does this callback get + called? */ + int i; + struct MERCHANT_DepositConfirmationCls *dccls; + dccls = (struct MERCHANT_DepositConfirmationCls *) cls; + + if (GNUNET_SYSERR == + MERCHANT_DB_update_deposit_permission (db_conn, + dccls->transaction_id, + 0)) + /* TODO */; + dccls->dc[dccls->index].ackd = 1; + dccls->dc[dccls->index].exit_status = http_status; + dccls->dc[dccls->index].proof = proof; + + /* loop through the confirmation array and return accordingly */ + for (i = 0; i < dccls->coins_cnt; i++) + { + /* just return if there is at least one coin to be still + confirmed */ + if (!dccls->dc[i].ackd) + return; + } + + /* at this point, any coin has been confirmed by the mint. So + check for errors .. */ + + /* Finally */ + GNUNET_free (dccls->dc); + GNUNET_free (dccls); } /** @@ -150,8 +176,8 @@ MH_handler_pay (struct TMH_RequestHandler *rh, json_t *coin_aggregate; json_t *wire_details; unsigned int mint_index; /*a cell in the global array*/ - unsigned int coins_index; /*a cell in the global array*/ - unsigned int coins_cnt; /*a cell in the global array*/ + unsigned int coins_index; + unsigned int coins_cnt; uint64_t transaction_id; int res; @@ -336,6 +362,8 @@ MH_handler_pay (struct TMH_RequestHandler *rh, dccls = GNUNET_malloc (sizeof (struct MERCHANT_DepositConfirmationCls)); dccls->index = coins_index; dccls->dc = dc; + dccls->coins_cnt = coins_cnt; + dccls->transaction_id = transaction_id; dh = TALER_MINT_deposit (mints[mint_index].conn, &amount, diff --git a/src/include/merchant.h b/src/include/merchant.h index fd7e0e20..7e9cc4aa 100644 --- a/src/include/merchant.h +++ b/src/include/merchant.h @@ -47,10 +47,6 @@ struct MERCHANT_DepositConfirmation { /** - * How many coins this request is made of - */ - unsigned int coins_cnt; - /** * True if this coin's outcome has been read from * its cb */ @@ -82,6 +78,16 @@ struct MERCHANT_DepositConfirmationCls */ struct MERCHANT_DepositConfirmation *dc; + /** + * How many coins this paymen is made of. + */ + unsigned int coins_cnt; + + /** + * Transaction id + */ + uint64_t transaction_id; + }; /** |