summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-10 21:01:08 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-10 21:01:08 +0200
commit4f237e8aae9b67a0bdb9363934dcbbb3a7742daa (patch)
tree992a271f48bdb940f3251c0bd39158ffd0453194
parent0b945df357bf820540b67b412d47aa9073797267 (diff)
downloadmerchant-4f237e8aae9b67a0bdb9363934dcbbb3a7742daa.tar.gz
merchant-4f237e8aae9b67a0bdb9363934dcbbb3a7742daa.tar.bz2
merchant-4f237e8aae9b67a0bdb9363934dcbbb3a7742daa.zip
add API to store refund proofs
-rw-r--r--src/backenddb/merchant-0001.sql22
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c115
-rw-r--r--src/include/taler_merchantdb_plugin.h49
3 files changed, 183 insertions, 3 deletions
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index bfcc828a..63eb4bf7 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -59,7 +59,8 @@ CREATE TABLE IF NOT EXISTS merchant_deposits
,signkey_pub BYTEA NOT NULL CHECK (LENGTH(signkey_pub)=32)
,exchange_proof BYTEA NOT NULL
,PRIMARY KEY (h_contract_terms, coin_pub)
- ,FOREIGN KEY (h_contract_terms, merchant_pub) REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)
+ ,FOREIGN KEY (h_contract_terms, merchant_pub)
+ REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)
);
CREATE TABLE IF NOT EXISTS merchant_proofs
@@ -109,10 +110,25 @@ CREATE TABLE IF NOT EXISTS merchant_refunds
,reason VARCHAR NOT NULL
,refund_amount_val INT8 NOT NULL
,refund_amount_frac INT4 NOT NULL
- ,FOREIGN KEY (h_contract_terms, coin_pub) REFERENCES merchant_deposits (h_contract_terms, coin_pub)
- ,FOREIGN KEY (h_contract_terms, merchant_pub) REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)
+ ,FOREIGN KEY (h_contract_terms, coin_pub)
+ REFERENCES merchant_deposits (h_contract_terms, coin_pub)
+ ,FOREIGN KEY (h_contract_terms, merchant_pub)
+ REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)
+ ,PRIMARY KEY (h_contract_terms, merchant_pub, coin_pub, rtransaction_id)
);
+CREATE TABLE IF NOT EXISTS merchant_refund_proofs
+ (rtransaction_id BIGSERIAL UNIQUE
+ ,merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)
+ ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)
+ ,coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)
+ ,exchange_sig BYTEA NOT NULL CHECK (LENGTH(exchange_sig)=64)
+ ,exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)
+ ,FOREIGN KEY (h_contract_terms, merchant_pub, coin_pub, rtransaction_id)
+ REFERENCES merchant_refunds (h_contract_terms, merchant_pub, coin_pub, rtransaction_id)
+ ,PRIMARY KEY (h_contract_terms, merchant_pub, coin_pub, rtransaction_id)
+);
+
-- balances of the reserves available for tips
CREATE TABLE IF NOT EXISTS merchant_tip_reserves
(reserve_priv BYTEA NOT NULL CHECK (LENGTH(reserve_priv)=32)
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 18b4f76b..77c96072 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1829,6 +1829,97 @@ postgres_get_refunds_from_contract_terms_hash (
/**
+ * Obtain refund proofs associated with a refund operation on a
+ * coin.
+ *
+ * @param cls closure, typically a connection to the db
+ * @param merchant_pub public key of the merchant instance
+ * @param h_contract_terms hash code of the contract
+ * @param coin_pub public key of the coin
+ * @param rtransaction_id identificator of the refund
+ * @param[out] exchange_pub public key of the exchange affirming the refund
+ * @param[out] exchange_sig signature of the exchange affirming the refund
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_get_refund_proof (
+ void *cls,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t rtransaction_id,
+ struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct TALER_ExchangeSignatureP *exchange_sig)
+{
+ 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_uint64 (&rtransaction_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_sig",
+ exchange_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
+ exchange_pub),
+ GNUNET_PQ_result_spec_end
+ };
+
+ check_connection (pg);
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_refund_proof",
+ params,
+ rs);
+}
+
+
+/**
+ * Store refund proofs associated with a refund operation on a
+ * coin.
+ *
+ * @param cls closure, typically a connection to the db
+ * @param merchant_pub public key of the merchant instance
+ * @param h_contract_terms hash code of the contract
+ * @param coin_pub public key of the coin
+ * @param rtransaction_id identificator of the refund
+ * @param exchange_pub public key of the exchange affirming the refund
+ * @param exchange_sig signature of the exchange affirming the refund
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_put_refund_proof (
+ void *cls,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t rtransaction_id,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_ExchangeSignatureP *exchange_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&rtransaction_id),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (exchange_sig),
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ TALER_LOG_DEBUG ("Inserting refund proof %s + %s\n",
+ GNUNET_h2s (h_contract_terms),
+ TALER_B2S (coin_pub));
+ check_connection (pg);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_refund_proof",
+ params);
+}
+
+
+/**
* Insert a refund row into merchant_refunds. Not meant to be exported
* in the db API.
*
@@ -3231,6 +3322,28 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" WHERE merchant_refunds.merchant_pub=$1"
" AND merchant_refunds.h_contract_terms=$2",
2),
+ GNUNET_PQ_make_prepare ("get_refund_proof",
+ "SELECT"
+ " exchange_pub"
+ ",exchange_sig"
+ " FROM merchant_refund_proofs"
+ " WHERE"
+ " h_contract_terms=$1"
+ " AND merchant_pub=$2"
+ " AND coin_pub=$3"
+ " AND rtransaction_id=$4",
+ 4),
+ GNUNET_PQ_make_prepare ("insert_refund_proof",
+ "INSERT INTO merchant_refund_proofs"
+ "(rtransaction_id"
+ ",merchant_pub"
+ ",h_contract_terms"
+ ",coin_pub"
+ ",exchange_sig"
+ ",exchange_pub)"
+ " VALUES "
+ "($1, $2, $3, $4, $5, $6)",
+ 6),
GNUNET_PQ_make_prepare ("find_contract_terms_by_date_and_range_asc",
"SELECT"
" contract_terms"
@@ -3532,6 +3645,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
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;
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index 3ac43397..57ec69f7 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -685,6 +685,55 @@ struct TALER_MERCHANTDB_Plugin
TALER_MERCHANTDB_RefundCallback rc,
void *rc_cls);
+
+ /**
+ * Obtain refund proofs associated with a refund operation on a
+ * coin.
+ *
+ * @param cls closure, typically a connection to the db
+ * @param merchant_pub public key of the merchant instance
+ * @param h_contract_terms hash code of the contract
+ * @param coin_pub public key of the coin
+ * @param rtransaction_id identificator of the refund
+ * @param[out] exchange_pub public key of the exchange affirming the refund
+ * @param[out] exchange_sig signature of the exchange affirming the refund
+ * @return transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_refund_proof)(
+ void *cls,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t rtransaction_id,
+ struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct TALER_ExchangeSignatureP *exchange_sig);
+
+
+ /**
+ * Store refund proofs associated with a refund operation on a
+ * coin.
+ *
+ * @param cls closure, typically a connection to the db
+ * @param merchant_pub public key of the merchant instance
+ * @param h_contract_terms hash code of the contract
+ * @param coin_pub public key of the coin
+ * @param rtransaction_id identificator of the refund
+ * @param exchange_pub public key of the exchange affirming the refund
+ * @param exchange_sig signature of the exchange affirming the refund
+ * @return transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*put_refund_proof)(
+ void *cls,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t rtransaction_id,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_ExchangeSignatureP *exchange_sig);
+
+
/**
* Add @a credit to a reserve to be used for tipping. Note that
* this function does not actually perform any wire transfers to