From d6fc0b6fc79e1a15ec37128521c5b7403a3b0927 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 8 May 2020 23:40:48 +0200 Subject: more work on POST /transfer --- .../taler-merchant-httpd_private-post-transfers.c | 50 +- src/backenddb/plugin_merchantdb_postgres.c | 503 ++------------------- src/include/taler_merchantdb_plugin.h | 29 +- src/lib/merchant_api_post_order_pay.c | 2 +- 4 files changed, 88 insertions(+), 496 deletions(-) (limited to 'src') diff --git a/src/backend/taler-merchant-httpd_private-post-transfers.c b/src/backend/taler-merchant-httpd_private-post-transfers.c index 29e59972..fd9752d8 100644 --- a/src/backend/taler-merchant-httpd_private-post-transfers.c +++ b/src/backend/taler-merchant-httpd_private-post-transfers.c @@ -265,7 +265,11 @@ transfer_cleanup (void *cls) * @param amount_with_fee amount the exchange will transfer for this coin * @param deposit_fee fee the exchange will charge for this coin * @param refund_fee fee the exchange will charge for refunding this coin - * @param exchange_proof proof from exchange that coin was accepted + * @param h_wire hash of merchant's wire details + * @param deposit_timestamp when did the exchange receive the deposit + * @param refund_deadline until when are refunds allowed + * @param exchange_sig signature by the exchange + * @param exchange_pub exchange signing key used for @a exchange_sig */ static void check_transfer (void *cls, @@ -278,8 +282,7 @@ check_transfer (void *cls, struct GNUNET_TIME_Absolute deposit_timestamp, struct GNUNET_TIME_Absolute refund_deadline, const struct TALER_ExchangeSignatureP *exchange_sig, - const struct TALER_ExchangePublicKeyP *exchange_pub); - + const struct TALER_ExchangePublicKeyP *exchange_pub) { struct PostTransfersContext *ptc = cls; const struct TALER_TrackTransferDetails *ttd = ptc->current_detail; @@ -298,16 +301,37 @@ check_transfer (void *cls, /* Build the `TrackTransferConflictDetails` */ ptc->response = TALER_MHD_make_json_pack ( - "{s:I, s:s, s:o, s:I, s:o, s:s, s:o, s:o}", - "code", (json_int_t) TALER_EC_POST_TRANSFERS_CONFLICTING_REPORTS, - "hint", "disagreement about deposit valuation", - "exchange_deposit_proof", exchange_proof, - "conflict_offset", (json_int_t) ptc->current_offset, - "coin_pub", GNUNET_JSON_from_data_auto (&ttd->coin_pub), - "h_contract_terms", GNUNET_JSON_from_data_auto ( - &ttd->h_contract_terms), - "amount_with_fee", TALER_JSON_from_amount (amount_with_fee), - "deposit_fee", TALER_JSON_from_amount (deposit_fee)); + "{s:I, s:s, s:s, s:o, s:o," + " s:I, s:o, s:o, s:o, s:o," + " s:o, s:o, s:o }", + "code", + (json_int_t) TALER_EC_POST_TRANSFERS_CONFLICTING_REPORTS, + "hint", + "disagreement about deposit valuation", + "exchange_url", + exchange_url, + "deposit_timestamp", + GNUNET_JSON_from_time_abs (deposit_timestamp), + "refund_deadline", + GNUNET_JSON_from_time_abs (refund_deadline), + /* first block of 5 */ + "conflict_offset", + (json_int_t) ptc->current_offset, + "coin_pub", + GNUNET_JSON_from_data_auto (&ttd->coin_pub), + "h_wire", + GNUNET_JSON_from_data_auto (h_wire), + "exchange_sig", + GNUNET_JSON_from_data_auto (exchange_sig), + "exchange_pub", + GNUNET_JSON_from_data_auto (exchange_pub), + /* first block of 5 */ + "h_contract_terms", + GNUNET_JSON_from_data_auto (&ttd->h_contract_terms), + "amount_with_fee", + TALER_JSON_from_amount (amount_with_fee), + "deposit_fee", + TALER_JSON_from_amount (deposit_fee)); return; } ptc->check_transfer_result = GNUNET_OK; diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 60cbc7a5..d1fc4c19 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -3006,29 +3006,37 @@ lookup_deposits_by_contract_and_coin_cb (void *cls, for (unsigned int i = 0; iqs = GNUNET_DB_STATUS_HARD_ERROR; + ldcc->qs = GNUNET_DB_STATUS_HARD_ERROR; return; } ldcc->qs = i + 1; - ldcc->rc (ldcc->rc_cls, - ...); + ldcc->cb (ldcc->cb_cls, + exchange_url, + &amount_with_fee, + &deposit_fee, + &refund_fee, + &wire_fee, + &h_wire, + deposit_timestamp, + refund_deadline, + &exchange_sig, + &exchange_pub); GNUNET_PQ_cleanup_result (rs); } } @@ -3072,7 +3089,7 @@ postgres_lookup_deposits_by_contract_and_coin ( { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string_type (instance_id), + GNUNET_PQ_query_param_string (instance_id), GNUNET_PQ_query_param_auto_from_type (h_contract_terms), GNUNET_PQ_query_param_auto_from_type (coin_pub), GNUNET_PQ_query_param_end @@ -3342,305 +3359,6 @@ postgres_get_authorized_tip_amount (void *cls, } -/** - * Closure for #find_payments_cb(). - */ -struct FindPaymentsContext -{ - /** - * Function to call with results. - */ - TALER_MERCHANTDB_CoinDepositCallback cb; - - /** - * Closure for @e cls. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Contract term hash used for the search. - */ - const struct GNUNET_HashCode *h_contract_terms; - - /** - * Transaction status (set). - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls of type `struct FindPaymentsContext *` - * @param result the postgres result - * @param num_result the number of results in @a result - */ -static void -find_payments_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct FindPaymentsContext *fpc = cls; - struct PostgresClosure *pg = fpc->pg; - - for (unsigned int i = 0; iqs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - fpc->qs = i + 1; - fpc->cb (fpc->cb_cls, - fpc->h_contract_terms, - &coin_pub, - exchange_url, - &amount_with_fee, - &deposit_fee, - &refund_fee, - &wire_fee, - exchange_proof); - GNUNET_PQ_cleanup_result (rs); - } -} - - -/** - * Lookup information about coin payments by proposal data hash - * (and @a merchant_pub) - * - * @param cls closure - * @param h_contract_terms key for the search - * @param merchant_pub merchant's public key - * @param cb function to call with payment data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -postgres_find_payments (void *cls, - const struct GNUNET_HashCode *h_contract_terms, - const struct TALER_MerchantPublicKeyP *merchant_pub, - TALER_MERCHANTDB_CoinDepositCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_auto_from_type (merchant_pub), - GNUNET_PQ_query_param_end - }; - struct FindPaymentsContext fpc = { - .h_contract_terms = h_contract_terms, - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - /* no preflight check here, run in its own transaction by the - caller! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finding payment for h_contract_terms '%s'\n", - GNUNET_h2s (h_contract_terms)); - check_connection (pg); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "find_deposits", - params, - &find_payments_cb, - &fpc); - if (qs <= 0) - return qs; - return fpc.qs; -} - - -/** - * Closure for #find_payments_by_coin_cb(). - */ -struct FindPaymentsByCoinContext -{ - /** - * Function to call with results. - */ - TALER_MERCHANTDB_CoinDepositCallback cb; - - /** - * Closure for @e cls. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Coin we are looking for. - */ - const struct TALER_CoinSpendPublicKeyP *coin_pub; - - /** - * Hash of the contract we are looking for. - */ - const struct GNUNET_HashCode *h_contract_terms; - - /** - * Transaction status (set). - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls of type `struct FindPaymentsByCoinContext *` - * @param result the postgres result - * @param num_result the number of results in @a result - */ -static void -find_payments_by_coin_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct FindPaymentsByCoinContext *fpc = cls; - struct PostgresClosure *pg = fpc->pg; - - for (unsigned int i = 0; iqs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - fpc->qs = i + 1; - fpc->cb (fpc->cb_cls, - fpc->h_contract_terms, - fpc->coin_pub, - exchange_url, - &amount_with_fee, - &deposit_fee, - &refund_fee, - &wire_fee, - exchange_proof); - GNUNET_PQ_cleanup_result (rs); - } -} - - -/** - * Retrieve information about a deposited coin. - * - * @param cls closure - * @param h_contract_terms hashcode of the proposal data paid by @a coin_pub - * @param merchant_pub merchant's public key. - * @param coin_pub coin's public key used for the search - * @param cb function to call with payment data - * @param cb_cls closure for @a cb - * @return transaction status - */ -static enum GNUNET_DB_QueryStatus -postgres_find_payments_by_hash_and_coin (void *cls, - const struct - GNUNET_HashCode *h_contract_terms, - const struct - TALER_MerchantPublicKeyP *merchant_pub, - const struct - TALER_CoinSpendPublicKeyP *coin_pub, - TALER_MERCHANTDB_CoinDepositCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_auto_from_type (merchant_pub), - GNUNET_PQ_query_param_auto_from_type (coin_pub), - GNUNET_PQ_query_param_end - }; - struct FindPaymentsByCoinContext fpc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg, - .h_contract_terms = h_contract_terms, - .coin_pub = coin_pub - }; - enum GNUNET_DB_QueryStatus qs; - - check_connection (pg); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "find_deposits_by_hash_and_coin", - params, - &find_payments_by_coin_cb, - &fpc); - if (0 >= qs) - return qs; - return fpc.qs; -} - - /** * Closure for #find_transfers_cb(). */ @@ -3766,144 +3484,6 @@ postgres_find_transfers_by_hash (void *cls, } -/** - * Closure for #find_deposits_cb(). - */ -struct FindDepositsContext -{ - - /** - * Function to call for each result. - */ - TALER_MERCHANTDB_CoinDepositCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Transaction status (set). - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls of type `struct FindDepositsContext *` - * @param result the postgres result - * @param num_result the number of results in @a result - */ -static void -find_deposits_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct FindDepositsContext *fdc = cls; - struct PostgresClosure *pg = fdc->pg; - - for (unsigned int i = 0; iqs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - fdc->qs = i + 1; - fdc->cb (fdc->cb_cls, - &h_contract_terms, - &coin_pub, - exchange_url, - &amount_with_fee, - &deposit_fee, - &refund_fee, - &wire_fee, - exchange_proof); - GNUNET_PQ_cleanup_result (rs); - } -} - - -/** - * Lookup information about a coin deposits by @a wtid. - * - * @param cls closure - * @param wtid wire transfer identifier to find matching transactions for - * @param cb function to call with payment data - * @param cb_cls closure for @a cb - * @return transaction status - */ -static enum GNUNET_DB_QueryStatus -postgres_find_deposits_by_wtid (void *cls, - const struct - TALER_WireTransferIdentifierRawP *wtid, - TALER_MERCHANTDB_CoinDepositCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_end - }; - struct FindDepositsContext fdc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - check_connection (pg); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "find_deposits_by_wtid", - params, - &find_deposits_cb, - &fdc); - if (0 >= qs) - return qs; - return fdc.qs; -} - - /** * Store information about wire fees charged by an exchange, * including signature (so we have proof). @@ -6357,10 +5937,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->store_coin_to_transfer = &postgres_store_coin_to_transfer; plugin->store_transfer_to_proof = &postgres_store_transfer_to_proof; plugin->store_wire_fee_by_exchange = &postgres_store_wire_fee_by_exchange; - plugin->find_payments_by_hash_and_coin = - &postgres_find_payments_by_hash_and_coin; plugin->find_transfers_by_hash = &postgres_find_transfers_by_hash; - plugin->find_deposits_by_wtid = &postgres_find_deposits_by_wtid; plugin->find_proof_by_wtid = &postgres_find_proof_by_wtid; plugin->get_authorized_tip_amount = &postgres_get_authorized_tip_amount; plugin->enable_tip_reserve_TR = &postgres_enable_tip_reserve_TR; diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index 1101e77c..ec584bff 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -458,8 +458,11 @@ typedef void * @param deposit_fee fee the exchange will charge for this coin * @param refund_fee fee the exchange will charge for refunding this coin * @param wire_fee wire fee the exchange charges - * @param exchange_proof proof from exchange that coin was accepted, - * matches the `interface DepositSuccess` of the documentation. + * @param h_wire hash of merchant's wire details + * @param deposit_timestamp when did the exchange receive the deposit + * @param refund_deadline until when are refunds allowed + * @param exchange_sig signature by the exchange + * @param exchange_pub exchange signing key used for @a exchange_sig */ typedef void (*TALER_MERCHANTDB_CoinDepositCallback)( @@ -469,7 +472,11 @@ typedef void const struct TALER_Amount *deposit_fee, const struct TALER_Amount *refund_fee, const struct TALER_Amount *wire_fee, - const json_t *exchange_proof); + const struct GNUNET_HashCode *h_wire, + struct GNUNET_TIME_Absolute deposit_timestamp, + struct GNUNET_TIME_Absolute refund_deadline, + const struct TALER_ExchangeSignatureP *exchange_sig, + const struct TALER_ExchangePublicKeyP *exchange_pub); /** @@ -1547,22 +1554,6 @@ struct TALER_MERCHANTDB_Plugin void *cb_cls); - /** - * Lookup information about a coin deposits by @a wtid. - * - * @param cls closure - * @param wtid wire transfer identifier to find matching transactions for - * @param cb function to call with payment data - * @param cb_cls closure for @a cb - * @return transaction status - */ - enum GNUNET_DB_QueryStatus - (*find_deposits_by_wtid)(void *cls, - const struct TALER_WireTransferIdentifierRawP *wtid, - TALER_MERCHANTDB_CoinDepositCallback cb, - void *cb_cls); - - /** * Lookup proof information about a wire transfer. * diff --git a/src/lib/merchant_api_post_order_pay.c b/src/lib/merchant_api_post_order_pay.c index 178f47a0..650211c9 100644 --- a/src/lib/merchant_api_post_order_pay.c +++ b/src/lib/merchant_api_post_order_pay.c @@ -584,7 +584,7 @@ TALER_MERCHANT_order_pay (struct GNUNET_CURL_Context *ctx, .purpose.size = htonl (sizeof (dr)), .h_contract_terms = *h_contract_terms, .h_wire = *h_wire, - .timestamp = GNUNET_TIME_absolute_hton (timestamp), + .wallet_timestamp = GNUNET_TIME_absolute_hton (timestamp), .refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline), .merchant = *merchant_pub }; -- cgit v1.2.3