summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-07-01 15:55:29 +0200
committerChristian Grothoff <christian@grothoff.org>2017-07-01 15:55:29 +0200
commitd85a8566f3339f271e65caead9c68bd8d648d2b4 (patch)
tree5a546175495767cc141b3b904245e5a202c67ab5
parentaa83a9187873339c97177da77f9cd84f30f678f0 (diff)
downloadmerchant-d85a8566f3339f271e65caead9c68bd8d648d2b4.tar.gz
merchant-d85a8566f3339f271e65caead9c68bd8d648d2b4.tar.bz2
merchant-d85a8566f3339f271e65caead9c68bd8d648d2b4.zip
implement first part of #4943: persist wire transfer fees of exchange in DB
-rw-r--r--src/backend/taler-merchant-httpd_exchanges.c23
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c74
-rw-r--r--src/include/taler_merchantdb_plugin.h27
3 files changed, 123 insertions, 1 deletions
diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c
index a0d32024..a011be43 100644
--- a/src/backend/taler-merchant-httpd_exchanges.c
+++ b/src/backend/taler-merchant-httpd_exchanges.c
@@ -341,15 +341,36 @@ process_wire_fees (void *cls,
}
while (NULL != fees)
{
+ struct GNUNET_HashCode h_wire_method;
+ enum GNUNET_DB_QueryStatus qs;
+
af = GNUNET_new (struct TALER_EXCHANGE_WireAggregateFees);
*af = *fees;
+ GNUNET_CRYPTO_hash (wire_method,
+ strlen (wire_method) + 1,
+ &h_wire_method);
+ qs = db->store_wire_fee_by_exchange (db->cls,
+ &exchange->master_pub,
+ &h_wire_method,
+ &af->wire_fee,
+ &af->closing_fee,
+ af->start_date,
+ af->end_date,
+ &af->master_sig);
+ if (0 > qs)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to persist exchange wire fees in merchant DB!\n");
+ GNUNET_free (af);
+ fees = fees->next;
+ continue;
+ }
af->next = NULL;
if (NULL == endp)
f->af = af;
else
endp->next = af;
endp = af;
- // FIXME #4943: also preserve `fees` in backend DB (under wire method + exchange master pub!)
fees = fees->next;
}
}
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index bb1f286f..a05f468c 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -223,6 +223,20 @@ postgres_initialize (void *cls)
" ON merchant_transfers (h_contract_terms, coin_pub)"),
GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS merchant_transfers_by_wtid"
" ON merchant_transfers (wtid)"),
+ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS exchange_wire_fees ("
+ " exchange_pub BYTEA NOT NULL CHECK (length(exchange_pub)=32)"
+ ",h_wire_method BYTEA NOT NULL CHECK (length(h_wire_method)=64)"
+ ",wire_fee_val INT8 NOT NULL"
+ ",wire_fee_frac INT4 NOT NULL"
+ ",wire_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") NOT NULL"
+ ",closing_fee_val INT8 NOT NULL"
+ ",closing_fee_frac INT4 NOT NULL"
+ ",closing_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") NOT NULL"
+ ",start_date INT8 NOT NULL"
+ ",end_date INT8 NOT NULL"
+ ",exchange_sig BYTEA NOT NULL CHECK (length(exchange_sig)=64)"
+ ",PRIMARY KEY (exchange_pub,h_wire_method,start_date,end_date)"
+ ");"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
struct GNUNET_PQ_PreparedStatement ps[] = {
@@ -299,6 +313,22 @@ postgres_initialize (void *cls)
" VALUES "
"($1, $2, $3, $4, $5)",
4),
+ GNUNET_PQ_make_prepare ("insert_wire_fee",
+ "INSERT INTO exchange_wire_fees"
+ "(exchange_pub"
+ ",h_wire_method"
+ ",wire_fee_val"
+ ",wire_fee_frac"
+ ",wire_fee_curr"
+ ",closing_fee_val"
+ ",closing_fee_frac"
+ ",closing_fee_curr"
+ ",start_date"
+ ",end_data"
+ ",exchange_sig)"
+ " VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
+ 11),
GNUNET_PQ_make_prepare ("find_contract_terms_from_hash",
"SELECT"
" contract_terms"
@@ -1733,6 +1763,49 @@ insert_refund (void *cls,
/**
+ * Store information about wire fees charged by an exchange,
+ * including signature (so we have proof).
+ *
+ * @param cls closure
+ * @paramm exchange_pub public key of the exchange
+ * @param h_wire_method hash of wire method
+ * @param wire_fee wire fee charged
+ * @param closing_fee closing fee charged (irrelevant for us,
+ * but needed to check signature)
+ * @param start_date start of fee being used
+ * @param end_date end of fee being used
+ * @param exchange_sig signature of exchange over fee structure
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_store_wire_fee_by_exchange (void *cls,
+ const struct TALER_MasterPublicKeyP *exchange_pub,
+ const struct GNUNET_HashCode *h_wire_method,
+ const struct TALER_Amount *wire_fee,
+ const struct TALER_Amount *closing_fee,
+ struct GNUNET_TIME_Absolute start_date,
+ struct GNUNET_TIME_Absolute end_date,
+ const struct TALER_MasterSignatureP *exchange_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_wire_method),
+ TALER_PQ_query_param_amount (wire_fee),
+ TALER_PQ_query_param_amount (closing_fee),
+ GNUNET_PQ_query_param_absolute_time (&start_date),
+ GNUNET_PQ_query_param_absolute_time (&end_date),
+ GNUNET_PQ_query_param_auto_from_type (exchange_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_wire_fee",
+ params);
+}
+
+
+/**
* Closure for #process_refund_cb.
*/
struct FindRefundContext
@@ -2227,6 +2300,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->store_deposit = &postgres_store_deposit;
plugin->store_coin_to_transfer = &postgres_store_coin_to_transfer;
plugin->store_transfer_to_proof = &postgres_store_transfer_to_proof;
+ plugin->store_wire_fee_by_exchange = &postgres_store_wire_fee_by_exchange;
plugin->find_transaction = &postgres_find_transaction;
plugin->find_payments_by_hash_and_coin = &postgres_find_payments_by_hash_and_coin;
plugin->find_payments = &postgres_find_payments;
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index f856fc74..efb03cb8 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -391,6 +391,32 @@ struct TALER_MERCHANTDB_Plugin
/**
+ * Store information about wire fees charged by an exchange,
+ * including signature (so we have proof).
+ *
+ * @param cls closure
+ * @paramm exchange_pub public key of the exchange
+ * @param h_wire_method hash of wire method
+ * @param wire_fee wire fee charged
+ * @param closing_fee closing fee charged (irrelevant for us,
+ * but needed to check signature)
+ * @param start_date start of fee being used
+ * @param end_date end of fee being used
+ * @param exchange_sig signature of exchange over fee structure
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*store_wire_fee_by_exchange) (void *cls,
+ const struct TALER_MasterPublicKeyP *exchange_pub,
+ const struct GNUNET_HashCode *h_wire_method,
+ const struct TALER_Amount *wire_fee,
+ const struct TALER_Amount *closing_fee,
+ struct GNUNET_TIME_Absolute start_date,
+ struct GNUNET_TIME_Absolute end_date,
+ const struct TALER_MasterSignatureP *exchange_sig);
+
+
+ /**
* Find information about a transaction.
*
* @param cls our plugin handle
@@ -404,6 +430,7 @@ struct TALER_MERCHANTDB_Plugin
struct GNUNET_TIME_Absolute date,
TALER_MERCHANTDB_TransactionCallback cb,
void *cb_cls);
+
/**
* Find information about a transaction.