gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: add API to store refund proofs


From: gnunet
Subject: [taler-merchant] branch master updated: add API to store refund proofs
Date: Fri, 10 Apr 2020 21:01:10 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 4f237e8  add API to store refund proofs
4f237e8 is described below

commit 4f237e8aae9b67a0bdb9363934dcbbb3a7742daa
Author: Christian Grothoff <address@hidden>
AuthorDate: Fri Apr 10 21:01:08 2020 +0200

    add API to store refund proofs
---
 src/backenddb/merchant-0001.sql            |  22 +++++-
 src/backenddb/plugin_merchantdb_postgres.c | 115 +++++++++++++++++++++++++++++
 src/include/taler_merchantdb_plugin.h      |  49 ++++++++++++
 3 files changed, 183 insertions(+), 3 deletions(-)

diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index bfcc828..63eb4bf 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 18b4f76..77c9607 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1828,6 +1828,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 3ac4339..57ec69f 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

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]