From 43e04f2ad105ff4712697b3480bbb75330f69ad3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 20 Jan 2016 18:50:19 +0100 Subject: work on #3888 --- src/mint/taler-mint-httpd_db.c | 40 ++++++++++++++++++++++-- src/mint/taler-mint-httpd_responses.c | 59 ++++++++++++++++++++++++++++++----- src/mint/taler-mint-httpd_responses.h | 14 +++++++-- 3 files changed, 100 insertions(+), 13 deletions(-) (limited to 'src/mint') diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c index 14e03dfd2..d31dcd2ba 100644 --- a/src/mint/taler-mint-httpd_db.c +++ b/src/mint/taler-mint-httpd_db.c @@ -1702,7 +1702,6 @@ TMH_DB_execute_wire_deposits (struct MHD_Connection *connection, ctx.deposits = json_array (); ret = TMH_plugin->lookup_wire_transactions (TMH_plugin->cls, &wtid->raw, - sizeof (wtid->raw), &handle_transaction_data, &ctx); if (GNUNET_SYSERR == ret) @@ -1742,6 +1741,26 @@ struct DepositWtidContext */ struct MHD_Connection *connection; + /** + * Hash of the contract we are looking up. + */ + struct GNUNET_HashCode h_contract; + + /** + * Hash of the wire transfer details we are looking up. + */ + struct GNUNET_HashCode h_wire; + + /** + * Public key we are looking up. + */ + struct TALER_CoinSpendPublicKeyP coin_pub; + + /** + * Transaction ID we are looking up. + */ + uint64_t transaction_id; + /** * MHD result code to return. */ @@ -1754,8 +1773,11 @@ struct DepositWtidContext * wire transfer identifier information. * * @param cls our context for transmission - * @param wtid base32-encoded wire transfer identifier, NULL + * @param wtid raw wire transfer identifier, NULL * if the transaction was not yet done + * @param coin_contribution how much did the coin we asked about + * contribute to the total transfer value? (deposit value minus fee) + * @param total_amount how much was the total wire transfer? * @param execution_time when was the transaction done, or * when we expect it to be done (if @a wtid was NULL); * #GNUNET_TIME_UNIT_FOREVER_ABS if the /deposit is unknown @@ -1763,7 +1785,9 @@ struct DepositWtidContext */ static void handle_wtid_data (void *cls, - const char *wtid, + const struct TALER_WireTransferIdentifierRawP *wtid, + const struct TALER_Amount *coin_contribution, + const struct TALER_Amount *total_amount, struct GNUNET_TIME_Absolute execution_time) { struct DepositWtidContext *ctx = cls; @@ -1780,6 +1804,12 @@ handle_wtid_data (void *cls, else { ctx->res = TMH_RESPONSE_reply_deposit_wtid (ctx->connection, + &ctx->h_contract, + &ctx->h_wire, + &ctx->coin_pub, + coin_contribution, + total_amount, + ctx->transaction_id, wtid, execution_time); } @@ -1810,6 +1840,10 @@ TMH_DB_execute_deposit_wtid (struct MHD_Connection *connection, struct DepositWtidContext ctx; ctx.connection = connection; + ctx.h_contract = *h_contract; + ctx.h_wire = *h_wire; + ctx.coin_pub = *coin_pub; + ctx.transaction_id = transaction_id; ctx.res = MHD_NO; /* this value should never be read... */ ret = TMH_plugin->wire_lookup_deposit_wtid (TMH_plugin->cls, h_contract, diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index 9a55d5aab..d89b74c8f 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c @@ -1092,34 +1092,69 @@ TMH_RESPONSE_reply_deposit_pending (struct MHD_Connection *connection, * them. Generates the 200 reply. * * @param connection connection to the client - * @param wtid wire transfer identifier (as 0-terminated string) + * @param h_contract hash of the contract + * @param h_wire hash of wire account details + * @param coin_pub public key of the coin + * @param coin_contribution how much did the coin we asked about + * contribute to the total transfer value? (deposit value minus fee) + * @param total_amount how much was the total wire transfer? + * @param transaction_id merchant transaction identifier + * @param wtid raw wire transfer identifier * @param exec_time execution time of the wire transfer * @return MHD result code */ int TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection, - const char *wtid, + const struct GNUNET_HashCode *h_contract, + const struct GNUNET_HashCode *h_wire, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *coin_contribution, + const struct TALER_Amount *total_amount, + uint64_t transaction_id, + const struct TALER_WireTransferIdentifierRawP *wtid, struct GNUNET_TIME_Absolute exec_time) { struct TALER_ConfirmWirePS cw; struct TALER_MintPublicKeyP pub; struct TALER_MintSignatureP sig; + struct TALER_WireTransferIdentifierP wtid_crc; + char *wtid_s; + int ret; + /* Create signature for the reply */ cw.purpose.purpose = htonl (TALER_SIGNATURE_MINT_CONFIRM_WIRE); cw.purpose.size = htonl (sizeof (struct TALER_ConfirmWirePS)); - // FIXME: fill in rest of 'cw'! + cw.h_wire = *h_wire; + cw.h_contract = *h_contract; + cw.wtid = *wtid; + cw.coin_pub = *coin_pub; + cw.transaction_id = GNUNET_htonll (transaction_id); + cw.execution_time = GNUNET_TIME_absolute_hton (exec_time); + TALER_amount_hton (&cw.coin_contribution, + coin_contribution); + TALER_amount_hton (&cw.total_amount, + total_amount); TMH_KS_sign (&cw.purpose, &pub, &sig); - return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_FOUND, + /* Compute checksum and crockford encoding if wire transfer subject */ + wtid_crc.raw = *wtid; + wtid_crc.crc8 = GNUNET_CRYPTO_crc8_n (wtid, + sizeof (struct TALER_WireTransferIdentifierRawP)); + + wtid_s = GNUNET_STRINGS_data_to_string_alloc (&wtid_crc, + sizeof (wtid_crc)); + ret = TMH_RESPONSE_reply_json_pack (connection, + MHD_HTTP_OK, "{s:s, s:o, s:o, s:o}", - "wtid", wtid, + "wtid", wtid_s, "execution_time", TALER_json_from_abs (exec_time), "mint_sig", TALER_json_from_data (&sig, sizeof (sig)), "mint_pub", TALER_json_from_data (&pub, sizeof (pub))); + GNUNET_free (wtid_s); + return ret; } @@ -1141,8 +1176,16 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection, const struct GNUNET_HashCode *h_wire, json_t *deposits) { - GNUNET_break (0); // FIXME: not implemented - return MHD_NO; + /* FIXME: #4135: signing not implemented here */ + return TMH_RESPONSE_reply_json_pack (connection, + MHD_HTTP_OK, + "{s:o, s:o, s:o, s:o}", + "total", TALER_json_from_amount (total), + "merchant_pub", TALER_json_from_data (merchant_pub, + sizeof (struct TALER_MerchantPublicKeyP)), + "h_wire", TALER_json_from_data (h_wire, + sizeof (struct GNUNET_HashCode)), + "deposits", deposits); } diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h index 6debbc935..caad29047 100644 --- a/src/mint/taler-mint-httpd_responses.h +++ b/src/mint/taler-mint-httpd_responses.h @@ -277,13 +277,23 @@ TMH_RESPONSE_reply_deposit_pending (struct MHD_Connection *connection, * them. Generates the 200 reply. * * @param connection connection to the client - * @param wtid wire transfer identifier (as 0-terminated string) + * @param h_contract hash of the contract + * @param h_wire hash of wire account details + * @param coin_pub public key of the coin + * @param transaction_id merchant transaction identifier + * @param wtid raw wire transfer identifier * @param exec_time execution time of the wire transfer * @return MHD result code */ int TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection, - const char *wtid, + const struct GNUNET_HashCode *h_contract, + const struct GNUNET_HashCode *h_wire, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *coin_contribution, + const struct TALER_Amount *total_amount, + uint64_t transaction_id, + const struct TALER_WireTransferIdentifierRawP *wtid, struct GNUNET_TIME_Absolute exec_time); -- cgit v1.2.3