diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/taler-merchant-httpd_exchanges.c | 3 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-pay.c | 3 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-pay.h | 2 | ||||
-rw-r--r-- | src/backenddb/merchant-0001.sql | 6 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 585 | ||||
-rw-r--r-- | src/include/taler_merchant_service.h | 10 | ||||
-rw-r--r-- | src/include/taler_merchant_testing_lib.h | 8 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 31 | ||||
-rw-r--r-- | src/lib/Makefile.am | 1 | ||||
-rw-r--r-- | src/lib/merchant_api_post_order_pay.c (renamed from src/lib/merchant_api_pay.c) | 4 | ||||
-rw-r--r-- | src/testing/Makefile.am | 3 | ||||
-rw-r--r-- | src/testing/testing_api_trait_refund_entry.c | 14 |
12 files changed, 520 insertions, 150 deletions
diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c index 11f845f1..f874bb99 100644 --- a/src/backend/taler-merchant-httpd_exchanges.c +++ b/src/backend/taler-merchant-httpd_exchanges.c @@ -830,6 +830,9 @@ keys_mgmt_cb (void *cls, exchange->url); } } + // FIXME: go over keys->sign_keys and STORE + // all of those into our database! + expire = TALER_EXCHANGE_check_keys_current (exchange->conn, GNUNET_NO, GNUNET_NO); diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c index 004b5e40..8afa41cf 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c @@ -641,8 +641,6 @@ deposit_cb (void *cls, pc->hc->infix, GNUNET_h2s (&pc->h_contract_terms), pc->hc->instance->settings.id); - /* NOTE: not run in any transaction block, simply as a - transaction by itself! */ TMH_db->preflight (TMH_db->cls); qs = TMH_db->insert_deposit (TMH_db->cls, pc->hc->instance->settings.id, @@ -653,6 +651,7 @@ deposit_cb (void *cls, &dc->deposit_fee, &dc->refund_fee, &dc->wire_fee, + &pc->wm->h_wire, exchange_sig, exchange_pub); if (0 > qs) diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.h b/src/backend/taler-merchant-httpd_post-orders-ID-pay.h index 7cce41f8..02564947 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.h +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.h @@ -34,7 +34,7 @@ MH_force_pc_resume (void); /** - * Process payment for an order. + * Process payment for a claimed order. * * @param rh context of the handler * @param connection the MHD connection to handle diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql index 0682da96..77c79052 100644 --- a/src/backenddb/merchant-0001.sql +++ b/src/backenddb/merchant-0001.sql @@ -61,7 +61,7 @@ COMMENT ON COLUMN merchant_exchange_signing_keys.master_pub CREATE TABLE IF NOT EXISTS merchant_instances (merchant_serial BIGSERIAL PRIMARY KEY ,merchant_pub BYTEA NOT NULL UNIQUE CHECK (LENGTH(merchant_pub)=32) - ,merchant_id VARCHAR NOT NULL + ,merchant_id VARCHAR NOT NULL UNIQUE ,merchant_name VARCHAR NOT NULL ,address BYTEA NOT NULL ,jurisdiction BYTEA NOT NULL @@ -279,6 +279,7 @@ CREATE TABLE IF NOT EXISTS merchant_deposits (deposit_serial BIGSERIAL PRIMARY KEY ,order_serial BIGINT REFERENCES merchant_contract_terms (order_serial) ON DELETE CASCADE + ,deposit_timestamp INT8 NOT NULL ,coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32) ,exchange_url VARCHAR NOT NULL ,amount_with_fee_val INT8 NOT NULL @@ -292,7 +293,6 @@ CREATE TABLE IF NOT EXISTS merchant_deposits ,signkey_serial BIGINT NOT NULL REFERENCES merchant_exchange_signing_keys (signkey_serial) ON DELETE CASCADE ,exchange_sig BYTEA NOT NULL CHECK (LENGTH(exchange_sig)=64) - ,exchange_timestamp INT8 NOT NULL ,account_serial BIGINT NOT NULL REFERENCES merchant_accounts (account_serial) ON DELETE CASCADE ,UNIQUE (order_serial, coin_pub) @@ -301,6 +301,8 @@ COMMENT ON TABLE merchant_deposits IS 'Table with the deposit confirmations for each coin we deposited at the exchange'; COMMENT ON COLUMN merchant_deposits.signkey_serial IS 'Online signing key of the exchange on the deposit confirmation'; +COMMENT ON COLUMN merchant_deposits.deposit_timestamp + IS 'Time when we received the deposit confirmation from the exchange (not rounded)'; COMMENT ON COLUMN merchant_deposits.exchange_sig IS 'Signature of the exchange over the deposit confirmation'; COMMENT ON COLUMN merchant_deposits.wire_fee_val diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index f02d0900..06f1d7a9 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -1501,6 +1501,382 @@ postgres_delete_contract_terms (void *cls, } +/** + * Closure for #lookup_deposits_cb(). + */ +struct LookupDepositsContext +{ + /** + * Function to call with results. + */ + TALER_MERCHANTDB_DepositsCallback cb; + + /** + * Closure for @e cls. + */ + 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[in,out] cls of type `struct LookupDepositsContext *` + * @param result the postgres result + * @param num_result the number of results in @a result + */ +static void +lookup_deposits_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupDepositsContext *ldc = cls; + struct PostgresClosure *pg = ldc->pg; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_CoinSpendPublicKeyP coin_pub; + struct TALER_Amount amount_with_fee; + struct TALER_Amount deposit_fee; + struct TALER_Amount refund_fee; + struct TALER_Amount wire_fee; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &coin_pub), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", + &amount_with_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee", + &deposit_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("refund_fee", + &refund_fee), + TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee", + &wire_fee), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ldc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + ldc->qs = i + 1; + ldc->cb (ldc->cb_cls, + &coin_pub, + &amount_with_fee, + &deposit_fee, + &refund_fee, + &wire_fee); + GNUNET_PQ_cleanup_result (rs); /* technically useless here */ + } +} + + +/** + * Lookup information about coins that were successfully deposited for a + * given contract. + * + * @param cls closure + * @param instance_id instance to lookup deposits for + * @param h_contract_terms proposal data's hashcode + * @param cb function to call with payment data + * @param cb_cls closure for @a cb + * @return transaction status + */ +static enum GNUNET_DB_QueryStatus +postgres_lookup_deposits (void *cls, + const char *instance_id, + const struct GNUNET_HashCode *h_contract_terms, + TALER_MERCHANTDB_DepositsCallback cb, + void *cb_cls) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_end + }; + struct LookupDepositsContext ldc = { + .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 deposits for h_contract_terms '%s'\n", + GNUNET_h2s (h_contract_terms)); + check_connection (pg); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "lookup_deposits", + params, + &lookup_deposits_cb, + &ldc); + if (qs <= 0) + return qs; + return ldc.qs; +} + + +/** + * Insert an exchange signing key into our database. + * + * @param cls closure + * @param master_pub exchange master public key used for @a master_sig + * @param exchange_pub exchange signing key to insert + * @param start_date when does the signing key become valid + * @param expire_date when does the signing key stop being used + * @param end_date when does the signing key become void as proof + * @param master_sig signature of @a master_pub over the @a exchange_pub and the dates + */ +static enum GNUNET_DB_QueryStatus +postgres_insert_exchange_signkey ( + void *cls, + const struct TALER_MasterPublicKeyP *master_pub, + const struct TALER_ExchangePublicKeyP *exchange_pub, + struct GNUNET_TIME_Absolute start_date, + struct GNUNET_TIME_Absolute expire_date, + struct GNUNET_TIME_Absolute end_date, + const struct TALER_MasterSignatureP *master_sig) +{ + // FIXME! +} + + +/** + * Insert payment confirmation from the exchange into the database. + * + * @param cls closure + * @param instance_id instance to lookup deposits for + * @param h_contract_terms proposal data's hashcode + * @param coin_pub public key of the coin + * @param exchange_url URL of the exchange that issued @a coin_pub + * @param amount_with_fee amount the exchange will deposit for this coin + * @param deposit_fee fee the exchange will charge for this coin + * @param wire_fee wire fee the exchange charges + * @param h_wire hash of the wire details of the target account of the merchant + * @param exchange_timestamp timestamp from the exchange + * @param exchange_sig signature from exchange that coin was accepted + * @param exchange_pub signgin key that was used for @a exchange_sig + * @return transaction status + */ +static enum GNUNET_DB_QueryStatus +postgres_insert_deposit (void *cls, + const char *instance_id, + const struct GNUNET_HashCode *h_contract_terms, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const char *exchange_url, + const struct TALER_Amount *amount_with_fee, + const struct TALER_Amount *deposit_fee, + const struct TALER_Amount *refund_fee, + const struct TALER_Amount *wire_fee, + const struct GNUNET_HashCode *h_wire, + const struct TALER_ExchangeSignatureP *exchange_sig, + const struct TALER_ExchangePublicKeyP *exchange_pub) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_absolute_time (&now), /* $3 */ + GNUNET_PQ_query_param_auto_from_type (coin_pub), + GNUNET_PQ_query_param_string (exchange_url), + TALER_PQ_query_param_amount (amount_with_fee), /* $6/$7 */ + TALER_PQ_query_param_amount (deposit_fee), /* $8, $9 */ + TALER_PQ_query_param_amount (refund_fee), /* $10, $11 */ + TALER_PQ_query_param_amount (wire_fee), /* $12, $13 */ + GNUNET_PQ_query_param_auto_from_type (h_wire), /* $14 */ + GNUNET_PQ_query_param_auto_from_type (exchange_sig), /* $15 */ + GNUNET_PQ_query_param_auto_from_type (exchange_pub), /* $16 */ + GNUNET_PQ_query_param_end + }; + + /* no preflight check here, run in transaction by caller! */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Storing deposit for instance `%s' h_contract_terms `%s', coin_pub: `%s', amount_with_fee: %s\n", + instance_id, + GNUNET_h2s (h_contract_terms), + TALER_B2S (coin_pub), + TALER_amount2s (amount_with_fee)); + check_connection (pg); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_deposit", + params); + +} + + +/** + * Closure for #lookup_refunds_cb(). + */ +struct LookupRefundsContext +{ + /** + * Function to call for each refund. + */ + TALER_MERCHANTDB_RefundCallback rc; + + /** + * Closure for @e rc. + */ + void *rc_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** + * Transaction result. + */ + 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 LookupRefundsContext *` + * @param result the postgres result + * @param num_result the number of results in @a result + */ +static void +lookup_refunds_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRefundsContext *lrc = cls; + struct PostgresClosure *pg = lrc->pg; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_CoinSpendPublicKeyP coin_pub; + struct TALER_Amount refund_amount; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &coin_pub), + TALER_PQ_RESULT_SPEC_AMOUNT ("refund_amount", + &refund_amount), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + lrc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + lrc->qs = i + 1; + lrc->rc (lrc->rc_cls, + &coin_pub, + &refund_amount); + GNUNET_PQ_cleanup_result (rs); /* technically useless here */ + } +} + + +/** + * Obtain refunds associated with a contract. + * + * @param cls closure, typically a connection to the db + * @param instance_id instance to lookup refunds for + * @param h_contract_terms hash code of the contract + * @param rc function to call for each coin on which there is a refund + * @param rc_cls closure for @a rc + * @return transaction status + */ +static enum GNUNET_DB_QueryStatus +postgres_lookup_refunds (void *cls, + const char *instance_id, + const struct GNUNET_HashCode *h_contract_terms, + TALER_MERCHANTDB_RefundCallback rc, + void *rc_cls) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_end + }; + struct LookupRefundsContext lrc = { + .rc = rc, + .rc_cls = rc_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + /* no preflight check here, run in transaction by caller! */ + TALER_LOG_DEBUG ("Looking for refund of h_contract_terms %s at `%s'\n", + GNUNET_h2s (h_contract_terms), + instance_id); + check_connection (pg); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "lookup_refunds", + params, + &lookup_refunds_cb, + &lrc); + if (0 >= qs) + return qs; + return lrc.qs; +} + + +/** + * Mark contract as paid and store the current @a session_id + * for which the contract was paid. + * + * @param cls closure + * @param instance_id instance to mark contract as paid for + * @param h_contract_terms hash of the contract that is now paid + * @param session_id the session that paid the contract, can be NULL + * @return transaction status + */ +static enum GNUNET_DB_QueryStatus +postgres_mark_contract_paid (void *cls, + const char *instance_id, + const struct GNUNET_HashCode *h_contract_terms, + const char *session_id) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_string (session_id), + GNUNET_PQ_query_param_end + }; + + /* no preflight check here, run in transaction by caller! */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Marking h_contract_terms '%s' of %s as paid for session `%s'\n", + GNUNET_h2s (h_contract_terms), + instance_id, + session_id); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "mark_contract_paid", + params); +} + + /* ********************* OLD API ************************** */ /** @@ -1580,44 +1956,6 @@ postgres_find_paid_contract_terms_from_hash (void *cls, /** - * Mark contract terms as paid. Needed by /history as only paid - * contracts must be shown. - * - * NOTE: we can't get the list of (paid) contracts from the - * transactions table because it lacks contract_terms plain JSON. In - * facts, the protocol doesn't allow to store contract_terms in - * transactions table, as /pay handler doesn't receive this data (only - * /proposal does). - * - * @param cls closure - * @param h_contract_terms hash of the contract that is now paid - * @param merchant_pub merchant's public key - * @return transaction status - */ -static enum GNUNET_DB_QueryStatus -postgres_mark_proposal_paid (void *cls, - const struct GNUNET_HashCode *h_contract_terms, - const struct - TALER_MerchantPublicKeyP *merchant_pub) -{ - 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 - }; - - TALER_LOG_DEBUG ("Marking proposal paid, h_contract_terms: '%s'," - " merchant_pub: '%s'\n", - GNUNET_h2s (h_contract_terms), - TALER_B2S (merchant_pub)); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "mark_proposal_paid", - params); -} - - -/** * Store the order ID that was used to pay for a resource within a session. * * @param cls closure @@ -1696,64 +2034,6 @@ postgres_find_session_info (void *cls, /** - * Insert payment confirmation from the exchange into the database. - * - * @param cls closure - * @param order_id identificator of the proposal associated with this revenue - * @param merchant_pub merchant's public key - * @param coin_pub public key of the coin - * @param amount_with_fee amount the exchange will deposit 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 wire_fee wire fee changed by the exchange - * @param signkey_pub public key used by the exchange for @a exchange_proof - * @param exchange_proof proof from exchange that coin was accepted - * @return transaction status - */ -static enum GNUNET_DB_QueryStatus -postgres_store_deposit (void *cls, - const struct GNUNET_HashCode *h_contract_terms, - const struct TALER_MerchantPublicKeyP *merchant_pub, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const char *exchange_url, - const struct TALER_Amount *amount_with_fee, - const struct TALER_Amount *deposit_fee, - const struct TALER_Amount *refund_fee, - const struct TALER_Amount *wire_fee, - const struct TALER_ExchangePublicKeyP *signkey_pub, - const json_t *exchange_proof) -{ - 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_string (exchange_url), - TALER_PQ_query_param_amount (amount_with_fee), - TALER_PQ_query_param_amount (deposit_fee), - TALER_PQ_query_param_amount (refund_fee), - TALER_PQ_query_param_amount (wire_fee), - GNUNET_PQ_query_param_auto_from_type (signkey_pub), - TALER_PQ_query_param_json (exchange_proof), - GNUNET_PQ_query_param_end - }; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Storing payment for h_contract_terms `%s', coin_pub: `%s', amount_with_fee: %s\n", - GNUNET_h2s (h_contract_terms), - TALER_B2S (coin_pub), - TALER_amount2s (amount_with_fee)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Merchant pub is `%s'\n", - TALER_B2S (merchant_pub)); - check_connection (pg); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_deposit", - params); -} - - -/** * Insert mapping of @a coin_pub and @a h_contract_terms to * corresponding @a wtid. * @@ -2075,7 +2355,7 @@ find_payments_cb (void *cls, * @param cb_cls closure for @a cb * @return transaction status */ -static enum GNUNET_DB_QueryStatus +enum GNUNET_DB_QueryStatus postgres_find_payments (void *cls, const struct GNUNET_HashCode *h_contract_terms, const struct TALER_MerchantPublicKeyP *merchant_pub, @@ -2535,7 +2815,7 @@ struct GetRefundsContext /** * Function to call for each refund. */ - TALER_MERCHANTDB_RefundCallback rc; + TALER_MERCHANTDB_CoinRefundCallback rc; /** * Closure for @e rc. @@ -2626,12 +2906,12 @@ get_refunds_cb (void *cls, * @param rc_cls closure for @a rc * @return transaction status */ -static enum GNUNET_DB_QueryStatus +enum GNUNET_DB_QueryStatus postgres_get_refunds_from_contract_terms_hash ( void *cls, const struct TALER_MerchantPublicKeyP *merchant_pub, const struct GNUNET_HashCode *h_contract_terms, - TALER_MERCHANTDB_RefundCallback rc, + TALER_MERCHANTDB_CoinRefundCallback rc, void *rc_cls) { struct PostgresClosure *pg = cls; @@ -5002,14 +5282,45 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) " (NOT paid) ) OR" " (creation_time + $3 > $4) )", 4), - - /* OLD API: */ - -#if 0 + GNUNET_PQ_make_prepare ("lookup_deposits", + "SELECT" + " coin_pub" + ",amount_with_fee_val" + ",amount_with_fee_frac" + ",deposit_fee_val" + ",deposit_fee_frac" + ",refund_fee_val" + ",refund_fee_frac" + ",wire_fee_val" + ",wire_fee_frac" + " FROM merchant_deposits" + " WHERE order_serial=" + " (SELECT order_serial" + " FROM merchant_contract_terms" + " WHERE h_contract_terms=$2" + " AND merchant_serial=" + " (SELECT merchant_serial" + " FROM merchant_instances" + " WHERE merchant_id=$1))", + 2), GNUNET_PQ_make_prepare ("insert_deposit", + "WITH md AS" + " (SELECT account_serial, merchant_serial" + " FROM merchant_accounts" + " WHERE h_wire=$14" + " AND merchant_serial=" + " (SELECT merchant_serial" + " FROM merchant_instances" + " WHERE merchant_id=$1))" + ", ed AS" + " (SELECT signkey_serial" + " FROM merchant_exchange_signing_keys" + " WHERE exchange_pub=$16" + " ORDER BY start_date DESC" + " LIMIT 1)" "INSERT INTO merchant_deposits" - "(h_contract_terms" - ",merchant_pub" + "(order_serial" + ",deposit_timestamp" ",coin_pub" ",exchange_url" ",amount_with_fee_val" @@ -5020,10 +5331,47 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) ",refund_fee_frac" ",wire_fee_val" ",wire_fee_frac" - ",signkey_pub" - ",exchange_proof) VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", - 14), + ",exchange_sig" + ",signkey_serial" + ",account_serial)" + " SELECT " + " order_serial" + " ,$3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $15" + " ,ed.signkey_serial" + " ,md.account_serial" + " FROM merchant_contract_terms" + " JOIN md USING (merchant_serial)" + " FULL OUTER JOIN ed ON TRUE" + " WHERE h_contract_terms=$2", + 16), + GNUNET_PQ_make_prepare ("lookup_refunds", + "SELECT" + " coin_pub" + ",refund_amount_val" + ",refund_amount_frac" + " FROM merchant_refunds" + " WHERE order_serial=" + " (SELECT order_serial" + " FROM merchant_contract_terms" + " WHERE h_contract_terms=$2" + " AND merchant_serial=" + " (SELECT merchant_serial" + " FROM merchant_instances" + " WHERE merchant_id=$1))", + 2), + GNUNET_PQ_make_prepare ("mark_contract_paid", + "UPDATE merchant_contract_terms SET" + " paid=TRUE" + ",session_id=$3" + " WHERE h_contract_terms=$2" + " AND merchant_serial=" + " (SELECT merchant_serial" + " FROM merchant_instances" + " WHERE merchant_id=$1)", + 3), + /* OLD API: */ + +#if 0 GNUNET_PQ_make_prepare ("insert_transfer", "INSERT INTO merchant_transfers" "(h_contract_terms" @@ -5071,12 +5419,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) " VALUES " "($1, $2, $3, $4, $5)", 5), - GNUNET_PQ_make_prepare ("mark_proposal_paid", - "UPDATE merchant_contract_terms SET" - " paid=TRUE" - " WHERE h_contract_terms=$1" - " AND merchant_pub=$2", - 2), GNUNET_PQ_make_prepare ("insert_wire_fee", "INSERT INTO exchange_wire_fees" "(exchange_pub" @@ -5418,30 +5760,31 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->lookup_contract_terms = &postgres_lookup_contract_terms; plugin->insert_contract_terms = &postgres_insert_contract_terms; plugin->delete_contract_terms = &postgres_delete_contract_terms; + plugin->lookup_deposits = &postgres_lookup_deposits; + plugin->insert_exchange_signkey = &postgres_insert_exchange_signkey; + plugin->insert_deposit = &postgres_insert_deposit; + plugin->lookup_refunds = &postgres_lookup_refunds; + plugin->mark_contract_paid = &postgres_mark_contract_paid; + /* OLD API: */ plugin->find_contract_terms_from_hash = &postgres_find_contract_terms_from_hash; plugin->find_paid_contract_terms_from_hash = &postgres_find_paid_contract_terms_from_hash; - plugin->store_deposit = &postgres_store_deposit; 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_payments = &postgres_find_payments; 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->get_refunds_from_contract_terms_hash = - &postgres_get_refunds_from_contract_terms_hash; plugin->lookup_wire_fee = &postgres_lookup_wire_fee; plugin->increase_refund_for_contract_NT = &postgres_increase_refund_for_contract_NT; plugin->get_refund_proof = &postgres_get_refund_proof; plugin->put_refund_proof = &postgres_put_refund_proof; - plugin->mark_proposal_paid = &postgres_mark_proposal_paid; plugin->insert_session_info = &postgres_insert_session_info; plugin->find_session_info = &postgres_find_session_info; plugin->enable_tip_reserve_TR = &postgres_enable_tip_reserve_TR; diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index 3335aeab..39509de9 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -1524,7 +1524,7 @@ TALER_MERCHANT_order_pay_frontend ( const char *order_id, unsigned int num_coins, const struct TALER_MERCHANT_PaidCoin coins[], - TALER_MERCHANT_PayCallback pay_cb, + TALER_MERCHANT_OrderPayCallback pay_cb, void *pay_cb_cls); @@ -1617,7 +1617,7 @@ TALER_MERCHANT_order_pay ( const char *order_id, unsigned int num_coins, const struct TALER_MERCHANT_PayCoin coins[], - TALER_MERCHANT_PayCallback pay_cb, + TALER_MERCHANT_OrderPayCallback pay_cb, void *pay_cb_cls); @@ -1638,7 +1638,7 @@ TALER_MERCHANT_order_pay_cancel (struct TALER_MERCHANT_OrderPayHandle *oph); /** * Handle for an POST /orders/$ID/abort operation. */ -struct TALER_MERCHANT_AbortHandle; +struct TALER_MERCHANT_OrderAbortHandle; /** @@ -1710,7 +1710,7 @@ typedef void * @param payref_cb_cls closure for @a pay_cb * @return a handle for this request */ -struct TALER_MERCHANT_AbortHandle * +struct TALER_MERCHANT_OrderAbortHandle * TALER_MERCHANT_order_abort (struct GNUNET_CURL_Context *ctx, const char *merchant_url, const struct GNUNET_HashCode *h_contract, @@ -1737,7 +1737,7 @@ TALER_MERCHANT_order_abort (struct GNUNET_CURL_Context *ctx, * @param oah the abort request handle */ void -TALER_MERCHANT_order_abort_cancel (struct TALER_MERCHANT_OrderAbortandle *oah); +TALER_MERCHANT_order_abort_cancel (struct TALER_MERCHANT_OrderAbortHandle *oah); /* ********************* OLD ************************** */ diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index 4e0b3fd6..63becbc7 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -969,9 +969,9 @@ TALER_TESTING_get_trait_h_contract_terms ( * @return the trait */ struct TALER_TESTING_Trait -TALER_TESTING_make_trait_refund_entry ( +TALER_TESTING_make_trait_refund_entry ( // FIXME: rename: entry->detail unsigned int index, - const struct TALER_MERCHANT_RefundEntry *refund_entry); + const struct TALER_MERCHANT_RefundDetail *refund_entry); /** @@ -983,10 +983,10 @@ TALER_TESTING_make_trait_refund_entry ( * @return #GNUNET_OK on success */ int -TALER_TESTING_get_trait_refund_entry ( +TALER_TESTING_get_trait_refund_entry ( // FIXME: rename: entry->detail const struct TALER_TESTING_Command *cmd, unsigned int index, - const struct TALER_MERCHANT_RefundEntry **refund_entry); + const struct TALER_MERCHANT_RefundDetail **refund_entry); /** * Create a /tip-authorize CMD, specifying the Taler error code diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index 2ef75de4..68efc6c7 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -311,7 +311,7 @@ typedef void * @param wire_fee wire fee the exchange charges */ typedef void -(*TALER_MERCHANTDB_DepositCallback)( +(*TALER_MERCHANTDB_DepositsCallback)( void *cls, const struct TALER_CoinSpendPublicKeyP *coin_pub, const struct TALER_Amount *amount_with_fee, @@ -904,9 +904,32 @@ struct TALER_MERCHANTDB_Plugin (*lookup_deposits)(void *cls, const char *instance_id, const struct GNUNET_HashCode *h_contract_terms, - TALER_MERCHANTDB_DepositCallback cb, + TALER_MERCHANTDB_DepositsCallback cb, void *cb_cls); + + /** + * Insert an exchange signing key into our database. + * + * @param cls closure + * @param master_pub exchange master public key used for @a master_sig + * @param exchange_pub exchange signing key to insert + * @param start_date when does the signing key become valid + * @param expire_date when does the signing key stop being used + * @param end_date when does the signing key become void as proof + * @param master_sig signature of @a master_pub over the @a exchange_pub and the dates + */ + enum GNUNET_DB_QueryStatus + (*insert_exchange_signkey)( + void *cls, + const struct TALER_MasterPublicKeyP *master_pub, + const struct TALER_ExchangePublicKeyP *exchange_pub, + struct GNUNET_TIME_Absolute start_date, + struct GNUNET_TIME_Absolute expire_date, + struct GNUNET_TIME_Absolute end_date, + const struct TALER_MasterSignatureP *master_sig); + + /** * Insert payment confirmation from the exchange into the database. * @@ -918,8 +941,9 @@ struct TALER_MERCHANTDB_Plugin * @param amount_with_fee amount the exchange will deposit for this coin * @param deposit_fee fee the exchange will charge for this coin * @param wire_fee wire fee the exchange charges - * @param exchange_pub public key used by the exchange for @a exchange_sig + * @param h_wire hash of the wire details of the target account of the merchant * @param exchange_sig signature from exchange that coin was accepted + * @param exchange_pub signgin key that was used for @a exchange_sig * @return transaction status */ enum GNUNET_DB_QueryStatus @@ -932,6 +956,7 @@ struct TALER_MERCHANTDB_Plugin const struct TALER_Amount *deposit_fee, const struct TALER_Amount *refund_fee, const struct TALER_Amount *wire_fee, + const struct GNUNET_HashCode *h_wire, const struct TALER_ExchangeSignatureP *exchange_sig, const struct TALER_ExchangePublicKeyP *exchange_pub); diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 6e6fd54f..b4d9386d 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -33,7 +33,6 @@ libtalermerchant_la_SOURCES = \ \ merchant_api_check_payment.c \ merchant_api_history.c \ - merchant_api_pay.c \ merchant_api_poll_payment.c \ merchant_api_refund.c \ merchant_api_refund_increase.c \ diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_post_order_pay.c index 2bbc19c9..f860f3a8 100644 --- a/src/lib/merchant_api_pay.c +++ b/src/lib/merchant_api_post_order_pay.c @@ -55,7 +55,7 @@ struct TALER_MERCHANT_Pay /** * Function to call with the result in "pay" @e mode. */ - TALER_MERCHANT_PayCallback pay_cb; + TALER_MERCHANT_OrderPayCallback pay_cb; /** * Closure for @a pay_cb. @@ -586,7 +586,7 @@ request_pay_generic ( unsigned int num_coins, const struct TALER_MERCHANT_PaidCoin *coins, const char *mode, - TALER_MERCHANT_PayCallback pay_cb, + TALER_MERCHANT_OrderPayCallback pay_cb, void *pay_cb_cls, TALER_MERCHANT_PayRefundCallback abort_cb, void *abort_cb_cls) diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index c04c5b3f..24374ee3 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -31,9 +31,6 @@ libtalermerchanttesting_la_SOURCES = \ \ testing_api_cmd_check_payment.c \ testing_api_cmd_history.c \ - testing_api_cmd_pay.c \ - testing_api_cmd_pay_abort.c \ - testing_api_cmd_pay_abort_refund.c \ testing_api_cmd_poll_payment.c \ testing_api_cmd_refund_increase.c \ testing_api_cmd_refund_lookup.c \ diff --git a/src/testing/testing_api_trait_refund_entry.c b/src/testing/testing_api_trait_refund_entry.c index 6a27cfbd..4181d17b 100644 --- a/src/testing/testing_api_trait_refund_entry.c +++ b/src/testing/testing_api_trait_refund_entry.c @@ -29,6 +29,8 @@ #include <taler/taler_testing_lib.h> #include "taler_merchant_service.h" +// FIXME: rename: entry->detail! + #define TALER_TESTING_TRAIT_REFUND_ENTRY "refund-entry" /** @@ -41,10 +43,10 @@ * @return #GNUNET_OK on success */ int -TALER_TESTING_get_trait_refund_entry - (const struct TALER_TESTING_Command *cmd, +TALER_TESTING_get_trait_refund_entry ( + const struct TALER_TESTING_Command *cmd, unsigned int index, - const struct TALER_MERCHANT_RefundEntry **refund_entry) + const struct TALER_MERCHANT_RefundDetail **refund_entry) { return cmd->traits (cmd->cls, (const void **) refund_entry, @@ -62,9 +64,9 @@ TALER_TESTING_get_trait_refund_entry * @return the trait */ struct TALER_TESTING_Trait -TALER_TESTING_make_trait_refund_entry - (unsigned int index, - const struct TALER_MERCHANT_RefundEntry *refund_entry) +TALER_TESTING_make_trait_refund_entry ( + unsigned int index, + const struct TALER_MERCHANT_RefundDetail *refund_entry) { struct TALER_TESTING_Trait ret = { .index = index, |