merchant

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

commit 55a4b83e50c04cff21660dd5257318fe4eb410d9
parent 91238a8ce45f2f479a170ae8dc43cbd250ffa18a
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Mon,  3 Oct 2016 17:37:25 +0200

testcase for query 'by date'

Diffstat:
Msrc/backenddb/plugin_merchantdb_postgres.c | 22+++++++++++++---------
Msrc/backenddb/test_merchantdb.c | 46+++++++++++++++++++++++++++++++++++++++++++++-
Msrc/include/taler_merchant_service.h | 3++-
3 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -199,10 +199,10 @@ postgres_initialize (void *cls) ",PRIMARY KEY (transaction_id, coin_pub)" ");"); PG_EXEC_INDEX (pg, - "CREATE INDEX IF NOT EXISTS merchant_transfers_by_coin " + "CREATE INDEX IF NOT EXISTS merchant_transfers_by_coin" " ON merchant_transfers (transaction_id, coin_pub)"); PG_EXEC_INDEX (pg, - "CREATE INDEX IF NOT EXISTS merchant_transfers_by_wtid " + "CREATE INDEX IF NOT EXISTS merchant_transfers_by_wtid" " ON merchant_transfers (wtid)"); /* Setup prepared "INSERT" statements */ @@ -258,7 +258,8 @@ postgres_initialize (void *cls) PG_PREPARE (pg, "find_transactions_by_date", "SELECT" - " exchange_uri" + " transaction_id" + ",exchange_uri" ",h_contract" ",h_wire" ",timestamp" @@ -552,13 +553,16 @@ postgres_store_transfer_to_proof (void *cls, */ static int postgres_find_transactions_by_date (void *cls, - struct GNUNET_TIME_Absolute date, - TALER_MERCHANTDB_TransactionCallback cb, - void *cb_cls) + struct GNUNET_TIME_Absolute date, + TALER_MERCHANTDB_TransactionCallback cb, + void *cb_cls) { struct PostgresClosure *pg = cls; PGresult *result; + unsigned int n; + unsigned int i; + struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_absolute_time (&date), GNUNET_PQ_query_param_end @@ -572,12 +576,12 @@ postgres_find_transactions_by_date (void *cls, PQclear (result); return GNUNET_SYSERR; } - if (0 == PQntuples (result)) + if (0 == (n = PQntuples (result))) { PQclear (result); return 0; } - /*FIXME iterate over result(s)*/ + for (i = 0; i < n; i++) { char *exchange_uri; struct GNUNET_HashCode h_contract; @@ -607,7 +611,7 @@ postgres_find_transactions_by_date (void *cls, if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, - 0)) + i)) { GNUNET_break (0); PQclear (result); diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -80,6 +80,11 @@ static uint64_t transaction_id; static struct GNUNET_TIME_Absolute timestamp; /** + * Delta aimed to test the "by_date" query on transactions. + */ +static struct GNUNET_TIME_Relative delta; + +/** * Deadline until which refunds are allowed. */ static struct GNUNET_TIME_Absolute refund_deadline; @@ -160,6 +165,34 @@ transaction_cb (void *cls, /** + * Function called with information about a transaction. Checks whether the + * returned tuple + * + * @param cls closure + * @param transaction_id of the contract + * @param exchange_uri URI of the exchange + * @param h_contract hash of the contract + * @param h_wire hash of our wire details + * @param timestamp time of the confirmation + * @param refund refund deadline + * @param total_amount total amount we receive for the contract after fees + */ + +static void +history_cb (void *cls, + uint64_t transaction_id, + const char *exchange_uri, + const struct GNUNET_HashCode *h_contract, + const struct GNUNET_HashCode *h_wire, + struct GNUNET_TIME_Absolute timestamp, + struct GNUNET_TIME_Absolute refund, + const struct TALER_Amount *total_amount) +{ + /*Just a stub*/ + return; +} + +/** * Function called with information about a coin that was deposited. * * @param cls closure @@ -252,6 +285,7 @@ static void run (void *cls) { struct GNUNET_CONFIGURATION_Handle *cfg = cls; + struct GNUNET_TIME_Absolute fake_now; /* Data for 'store_payment()' */ FAILIF (NULL == (plugin = TALER_MERCHANTDB_plugin_load (cfg))); @@ -266,6 +300,8 @@ run (void *cls) RND_BLK (&wtid); timestamp = GNUNET_TIME_absolute_get(); GNUNET_TIME_round_abs (&timestamp); + delta = GNUNET_TIME_UNIT_MINUTES; + fake_now = GNUNET_TIME_absolute_add (timestamp, delta); refund_deadline = GNUNET_TIME_absolute_get(); GNUNET_TIME_round_abs (&refund_deadline); GNUNET_assert (GNUNET_OK == @@ -319,6 +355,14 @@ run (void *cls) transaction_id, &transaction_cb, NULL)); + + /* FIXME: put here find_transactions_by_date () */ + FAILIF (1 != + plugin->find_transactions_by_date (plugin->cls, + fake_now, + history_cb, + NULL)); + FAILIF (GNUNET_OK != plugin->find_payments_by_id (plugin->cls, transaction_id, @@ -369,7 +413,7 @@ main (int argc, GNUNET_break (0); return -1; } - GNUNET_log_setup (argv[0], "WARNING", NULL); + GNUNET_log_setup (argv[0], "INFO", NULL); plugin_name++; (void) GNUNET_asprintf (&testname, "test-merchantdb-%s", diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h @@ -427,7 +427,8 @@ struct TALER_MERCHANT_TransactionWireTransfer /** - * Callbacks of this type are used to work the result of submitting a /track/transaction request to a merchant + * Callbacks of this type are used to work the result of submitting a + * /track/transaction request to a merchant * * @param cls closure * @param http_status HTTP status code we got, 0 on exchange protocol violation