merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 500b6456966cdcce2ed10a92870f5a1c82e34168
parent 9e2795084737fa588a0b0552ca04cbd165aba10b
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Thu, 13 Oct 2016 01:37:32 +0200

making (transaction_id, merchant_pub) the primary key
for table merchant_transactions, and making merchant_deposit
reference (transaction_id, merchant_pub) in merchant_transactions.
Adjusting testcase accordingly, as we now can have clashes
on transaction_id. Test NOT passed.

Diffstat:
Msrc/backend/taler-merchant-httpd_pay.c | 1+
Msrc/backenddb/plugin_merchantdb_postgres.c | 14++++++++++----
Msrc/backenddb/test_merchantdb.c | 1+
Msrc/include/taler_merchantdb_plugin.h | 2++
Msrc/lib/test_merchant_api.c | 28++++++++++++++++++++++++----
5 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c @@ -389,6 +389,7 @@ deposit_cb (void *cls, if (GNUNET_OK != db->store_deposit (db->cls, pc->transaction_id, + &pc->mi->pubkey, &dc->coin_pub, &dc->amount_with_fee, &dc->deposit_fee, diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -155,7 +155,7 @@ postgres_initialize (void *cls) /* Setup tables */ PG_EXEC (pg, "CREATE TABLE IF NOT EXISTS merchant_transactions (" - " transaction_id INT8 UNIQUE" + " transaction_id INT8" ",exchange_uri VARCHAR NOT NULL" ",merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)" ",h_contract BYTEA NOT NULL CHECK (LENGTH(h_contract)=64)" @@ -169,7 +169,9 @@ postgres_initialize (void *cls) ");"); PG_EXEC (pg, "CREATE TABLE IF NOT EXISTS merchant_deposits (" - " transaction_id INT8 REFERENCES merchant_transactions (transaction_id)" + " transaction_id INT8" + ",merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)" + ",FOREIGN KEY (transaction_id, merchant_pub) REFERENCES merchant_transactions (transaction_id, merchant_pub)" ",coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)" ",amount_with_fee_val INT8 NOT NULL" ",amount_with_fee_frac INT4 NOT NULL" @@ -228,6 +230,7 @@ postgres_initialize (void *cls) "insert_deposit", "INSERT INTO merchant_deposits" "(transaction_id" + ",merchant_pub" ",coin_pub" ",amount_with_fee_val" ",amount_with_fee_frac" @@ -237,8 +240,8 @@ postgres_initialize (void *cls) ",deposit_fee_curr" ",signkey_pub" ",exchange_proof) VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", - 10); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)", + 11); PG_PREPARE (pg, "insert_transfer", "INSERT INTO merchant_transfers" @@ -410,6 +413,7 @@ postgres_store_transaction (void *cls, * * @param cls closure * @param transaction_id of the contract + * @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 @@ -420,6 +424,7 @@ postgres_store_transaction (void *cls, static int postgres_store_deposit (void *cls, uint64_t transaction_id, + const struct TALER_MerchantPublicKeyP *merchant_pub, const struct TALER_CoinSpendPublicKeyP *coin_pub, const struct TALER_Amount *amount_with_fee, const struct TALER_Amount *deposit_fee, @@ -432,6 +437,7 @@ postgres_store_deposit (void *cls, struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&transaction_id), + GNUNET_PQ_query_param_auto_from_type (merchant_pub), GNUNET_PQ_query_param_auto_from_type (coin_pub), TALER_PQ_query_param_amount (amount_with_fee), TALER_PQ_query_param_amount (deposit_fee), diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -348,6 +348,7 @@ run (void *cls) FAILIF (GNUNET_OK != plugin->store_deposit (plugin->cls, transaction_id, + &merchant_pub, &coin_pub, &amount_with_fee, &deposit_fee, diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h @@ -179,6 +179,7 @@ struct TALER_MERCHANTDB_Plugin * * @param cls closure * @param transaction_id of the contract + * @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 @@ -189,6 +190,7 @@ struct TALER_MERCHANTDB_Plugin int (*store_deposit) (void *cls, uint64_t transaction_id, + const struct TALER_MerchantPublicKeyP *merchant_pub, const struct TALER_CoinSpendPublicKeyP *coin_pub, const struct TALER_Amount *amount_with_fee, const struct TALER_Amount *deposit_fee, diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c @@ -1457,7 +1457,7 @@ interpreter_run (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Switching instance: '%s'\n", receiver); - get_new_contracts(is->commands); + /*get_new_contracts(is->commands);*/ is->task = GNUNET_SCHEDULER_add_now (interpreter_run, is); return; @@ -2169,7 +2169,17 @@ run (void *cls) /* Create contract */ { .oc = OC_CONTRACT, .label = "create-contract-1", - .expected_response_code = MHD_HTTP_OK }, + .expected_response_code = MHD_HTTP_OK, + .details.contract.proposal = "{\ + \"max_fee\":\ + {\"currency\":\"EUR\", \"value\":0, \"fraction\":500000},\ + \"transaction_id\":1,\ + \"timestamp\":\"\\/Date(42)\\/\",\ + \"refund_deadline\":\"\\/Date(0)\\/\",\ + \"expiry\":\"\\/Date(999999999)\\/\",\ + \"amount\":{\"currency\":\"EUR\", \"value\":5, \"fraction\":0},\ + \"products\":\ + [ {\"description\":\"ice cream\", \"value\":\"{EUR:5}\"} ] }"}, { .oc = OC_PAY, .label = "deposit-simple", .expected_response_code = MHD_HTTP_OK, @@ -2181,7 +2191,17 @@ run (void *cls) { .oc = OC_CONTRACT, .label = "create-contract-2", - .expected_response_code = MHD_HTTP_OK }, + .expected_response_code = MHD_HTTP_OK, + .details.contract.proposal = "{\ + \"max_fee\":\ + {\"currency\":\"EUR\", \"value\":0, \"fraction\":500000},\ + \"transaction_id\":2,\ + \"timestamp\":\"\\/Date(42)\\/\",\ + \"refund_deadline\":\"\\/Date(0)\\/\",\ + \"expiry\":\"\\/Date(999999999)\\/\",\ + \"amount\":{\"currency\":\"EUR\", \"value\":5, \"fraction\":0},\ + \"products\":\ + [ {\"description\":\"ice cream\", \"value\":\"{EUR:5}\"} ] }" }, /* Try to double-spend the 5 EUR coin at the same merchant (but different transaction ID) */ { .oc = OC_PAY, @@ -2348,7 +2368,7 @@ run (void *cls) /* end of testcase */ { .oc = OC_END } }; - get_new_contracts (commands); + /*get_new_contracts (commands);*/ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Interpreter initializing\n");