From 55e0f3759fe57f2063b66613e46f5107b2212700 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Thu, 8 Jun 2017 09:56:46 +0200 Subject: fix "insufficient data left in message" from Postgresql --- src/backenddb/plugin_merchantdb_postgres.c | 167 ++++++++++++++--------------- 1 file changed, 82 insertions(+), 85 deletions(-) (limited to 'src/backenddb') diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index e0711a73..4dc4f1bc 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -122,6 +122,15 @@ postgres_initialize (void *cls) ",row_id BIGSERIAL" ",PRIMARY KEY (order_id, merchant_pub)" ");"), + GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_refunds (" + " rtransaction_id SERIAL" + ",h_contract_terms BYTEA NOT NULL" + ",coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)" + ",reason VARCHAR NOT NULL" + ",refund_amount_val INT8 NOT NULL" + ",refund_amount_frac INT8 NOT NULL" + ",refund_amount_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") NOT NULL" + ");"), GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_transactions (" " h_contract_terms BYTEA NOT NULL" ",exchange_uri VARCHAR NOT NULL" @@ -146,23 +155,12 @@ postgres_initialize (void *cls) ",deposit_fee_frac INT4 NOT NULL" ",deposit_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") NOT NULL" ",refund_fee_val INT8 NOT NULL" - ",refund_fee_frac INT8 NOT NULL" + ",refund_fee_frac INT4 NOT NULL" ",refund_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") NOT NULL" ",signkey_pub BYTEA NOT NULL CHECK (LENGTH(signkey_pub)=32)" ",exchange_proof BYTEA NOT NULL" ",PRIMARY KEY (h_contract_terms, coin_pub)" ");"), - - GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_refunds (" - " rtransaction_id SERIAL" - ",h_contract_terms BYTEA NOT NULL" - ",coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)" - ",reason VARCHAR NOT NULL" - ",refund_amount_val INT8 NOT NULL" - ",refund_amount_frac INT8 NOT NULL" - ",refund_amount_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") NOT NULL" - ");"), - GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_proofs (" " exchange_uri VARCHAR NOT NULL" ",wtid BYTEA CHECK (LENGTH(wtid)=32)" @@ -1484,35 +1482,33 @@ postgres_find_deposits_by_wtid (void *cls, return GNUNET_OK; } - /** - * Lookup proof information about a wire transfer. + * Obtain refunds associated with a contract. * - * @param cls closure - * @param exchange_uri from which exchange are we looking for proof - * @param wtid wire transfer identifier for the search - * @param cb function to call with proof data - * @param cb_cls closure for @a cb - * @return #GNUNET_OK on success, #GNUNET_NO if transaction Id is unknown, - * #GNUNET_SYSERR on hard errors + * @param rc function to call for each coin on which there is a refund + * @param rc_cls closure for @a rc + * @return #GNUNET_OK if we called @a rc on all coins + * #GNUNET_NO if there are no refunds for @a h_contract_terms + * #GNUNET_SYSERR if there were errors talking to the DB */ -static int -postgres_find_proof_by_wtid (void *cls, - const char *exchange_uri, - const struct TALER_WireTransferIdentifierRawP *wtid, - TALER_MERCHANTDB_ProofCallback cb, - void *cb_cls) +int +get_refunds_from_contract_terms_hash (void *cls, + const struct GNUNET_HashCode *h_contract_terms, + TALER_MERCHANTDB_RefundCallback rc, + void *rc_cls) { + struct PostgresClosure *pg = cls; PGresult *result; + unsigned int i; + struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_string (exchange_uri), + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), GNUNET_PQ_query_param_end }; result = GNUNET_PQ_exec_prepared (pg->conn, - "find_proof_by_wtid", + "FIXME", params); if (PGRES_TUPLES_OK != PQresultStatus (result)) { @@ -1525,66 +1521,80 @@ postgres_find_proof_by_wtid (void *cls, PQclear (result); return GNUNET_NO; } - if (1 != PQntuples (result)) - { - GNUNET_break (0); - PQclear (result); - return GNUNET_SYSERR; - } + for (i=0;iconn, - "FIXME", + "find_proof_by_wtid", params); if (PGRES_TUPLES_OK != PQresultStatus (result)) { @@ -1597,53 +1607,40 @@ get_refunds_from_contract_terms_hash (void *cls, PQclear (result); return GNUNET_NO; } - - for (i=0;i