aboutsummaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2017-06-08 09:56:46 +0200
committerMarcello Stanisci <marcello.stanisci@inria.fr>2017-06-08 09:57:13 +0200
commit55e0f3759fe57f2063b66613e46f5107b2212700 (patch)
treeb51a3cda6e0fc56837186428a889f096b2099337 /src/backenddb
parent2aab5f342e452b41cedc9817eed5f8796fe510d2 (diff)
fix "insufficient data left in message" from Postgresql
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c167
1 files changed, 82 insertions, 85 deletions
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;i<PQntuples (result);i++)
{
- json_t *proof;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ uint64_t rtransaction_id;
+ struct TALER_Amount refund_amount;
+ struct TALER_Amount refund_fee;
+ char *reason;
+
struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_json ("proof",
- &proof),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
+ &rtransaction_id),
+ TALER_PQ_result_spec_amount ("refund_amount",
+ &refund_amount),
+ TALER_PQ_result_spec_amount ("refund_fee",
+ &refund_fee),
+ GNUNET_PQ_result_spec_string ("reason",
+ &reason),
GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
GNUNET_PQ_extract_result (result,
rs,
- 0))
+ i))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
- cb (cb_cls,
- proof);
+ rc (rc_cls,
+ &coin_pub,
+ rtransaction_id,
+ reason,
+ &refund_amount,
+ &refund_fee);
+
GNUNET_PQ_cleanup_result (rs);
}
-
PQclear (result);
return GNUNET_OK;
}
+
/**
- * Obtain refunds associated with a contract.
+ * Lookup proof information about a wire transfer.
*
- * @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
+ * @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
*/
-int
-get_refunds_from_contract_terms_hash (void *cls,
- const struct GNUNET_HashCode *h_contract_terms,
- TALER_MERCHANTDB_RefundCallback rc,
- void *rc_cls)
+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)
{
-
struct PostgresClosure *pg = cls;
PGresult *result;
- unsigned int i;
-
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_string (exchange_uri),
GNUNET_PQ_query_param_end
};
result = GNUNET_PQ_exec_prepared (pg->conn,
- "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<PQntuples (result);i++)
+ if (1 != PQntuples (result))
{
- struct TALER_CoinSpendPublicKeyP coin_pub;
- uint64_t rtransaction_id;
- struct TALER_Amount refund_amount;
- struct TALER_Amount refund_fee;
- char *reason;
+ GNUNET_break (0);
+ PQclear (result);
+ return GNUNET_SYSERR;
+ }
+ {
+ json_t *proof;
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin_pub),
- GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
- &rtransaction_id),
- TALER_PQ_result_spec_amount ("refund_amount",
- &refund_amount),
- TALER_PQ_result_spec_amount ("refund_fee",
- &refund_fee),
- GNUNET_PQ_result_spec_string ("reason",
- &reason),
+ TALER_PQ_result_spec_json ("proof",
+ &proof),
GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
GNUNET_PQ_extract_result (result,
rs,
- i))
+ 0))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
- rc (rc_cls,
- &coin_pub,
- rtransaction_id,
- reason,
- &refund_amount,
- &refund_fee);
-
+ cb (cb_cls,
+ proof);
GNUNET_PQ_cleanup_result (rs);
}
+
PQclear (result);
return GNUNET_OK;
}
-
/**
* Initialize Postgres database subsystem.
*