summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-10-20 19:40:09 +0200
committerChristian Grothoff <christian@grothoff.org>2018-10-20 19:40:09 +0200
commit4f37950a40c9deca4206d9835d7282c535a5dfd8 (patch)
tree6c50c39f72fc041aa89e522778b5be5b2dabd9f4 /src
parent9d18caa00638a2fb709c767769a2726c8fcec5d1 (diff)
downloadexchange-4f37950a40c9deca4206d9835d7282c535a5dfd8.tar.gz
exchange-4f37950a40c9deca4206d9835d7282c535a5dfd8.tar.bz2
exchange-4f37950a40c9deca4206d9835d7282c535a5dfd8.zip
extend auditordb API with function to store deposit confirmations
Diffstat (limited to 'src')
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c74
-rw-r--r--src/include/taler_auditordb_plugin.h89
2 files changed, 162 insertions, 1 deletions
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 13fbbc2f2..bf88e5e9d 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2017 GNUnet e.V.
+ Copyright (C) 2014-2018 GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -361,6 +361,24 @@ postgres_create_tables (void *cls)
")"),
GNUNET_PQ_make_try_execute ("CREATE INDEX auditor_historic_reserve_summary_by_master_pub_start_date "
"ON auditor_historic_reserve_summary(master_pub,start_date)"),
+
+ /* Table with deposit confirmation sent to us by merchants;
+ we must check that the exchange reported these properly. */
+ GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS deposit_confirmations "
+ "(master_pub BYTEA NOT NULL CHECK (LENGTH(master_pub)=32)"
+ ",h_contract_terms BYTEA PRIMARY KEY CHECK (LENGTH(h_contract_terms_hash)=64)"
+ ",h_wire BYTEA PRIMARY KEY CHECK (LENGTH(h_wire)=64)"
+ ",timestamp INT8 NOT NULL"
+ ",refund_deadline INT8 NOT NULL"
+ ",amount_with_fee_val INT8 NOT NULL"
+ ",amount_with_fee_frac INT4 NOT NULL"
+ ",amount_with_fee_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
+ ",coin_pub BYTEA PRIMARY KEY CHECK (LENGTH(coin_pub)=32)"
+ ",merchant BYTEA PRIMARY KEY CHECK (LENGTH(coin_pub)=32)"
+ ",exchange_sig BYTEA PRIMARY KEY CHECK (LENGTH(coin_pub)=32)"
+ ",exchange_pub BYTEA PRIMARY KEY CHECK (LENGTH(coin_pub)=32)"
+ ",master_sig BYTEA PRIMARY KEY CHECK (LENGTH(coin_pub)=32)"
+ ")"),
/* Table with historic business ledger; basically, when the exchange
operator decides to use operating costs for anything but wire
transfers to merchants, it goes in here. This happens when the
@@ -475,6 +493,22 @@ postgres_prepare (PGconn *db_conn)
" WHERE master_pub=$1;",
1),
/* Used in #postgres_insert_auditor_progress() */
+ GNUNET_PQ_make_prepare ("auditor_deposit_confirmation_insert",
+ "INSERT INTO deposit_confirmations "
+ "(master_pub"
+ ",h_contract_terms"
+ ",h_wire"
+ ",timestamp"
+ ",refund_deadline"
+ ",amount_without_fee"
+ ",coin_pub"
+ ",merchant"
+ ",exchange_sig"
+ ",exchange_pub"
+ ",master_sig" /* master_sig could be normalized... */
+ ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);",
+ 11),
+ /* Used in #postgres_insert_auditor_progress() */
GNUNET_PQ_make_prepare ("auditor_progress_insert",
"INSERT INTO auditor_progress "
"(master_pub"
@@ -1048,6 +1082,42 @@ postgres_gc (void *cls)
/**
+ * Insert information about a deposit confirmation into the database.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param session connection to the database
+ * @param dc deposit confirmation information to store
+ * @return query result status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_insert_deposit_confirmation (void *cls,
+ struct TALER_AUDITORDB_Session *session,
+ const struct TALER_AUDITORDB_DepositConfirmation *dc)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&dc->master_public_key),
+ GNUNET_PQ_query_param_auto_from_type (&dc->h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (&dc->h_wire),
+ TALER_PQ_query_param_absolute_time (&dc->timestamp),
+ TALER_PQ_query_param_absolute_time (&dc->refund_deadline),
+ TALER_PQ_query_param_amount (&dc->amount_without_fee),
+ GNUNET_PQ_query_param_auto_from_type (&dc->coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&dc->merchant),
+ GNUNET_PQ_query_param_auto_from_type (&dc->exchange_sig),
+ GNUNET_PQ_query_param_auto_from_type (&dc->exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (&dc->master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ return GNUNET_PQ_eval_prepared_non_select (session->conn,
+ "auditor_deposit_confirmation_insert",
+ params);
+
+
+}
+
+
+/**
* Insert information about a denomination key and in particular
* the properties (value, fees, expiration times) the coins signed
* with this key have.
@@ -2625,6 +2695,8 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
plugin->rollback = &postgres_rollback;
plugin->gc = &postgres_gc;
+ plugin->insert_deposit_confirmation = &postgres_insert_deposit_confirmation;
+
plugin->select_denomination_info = &postgres_select_denomination_info;
plugin->insert_denomination_info = &postgres_insert_denomination_info;
diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h
index e84fa048c..622ae1afa 100644
--- a/src/include/taler_auditordb_plugin.h
+++ b/src/include/taler_auditordb_plugin.h
@@ -187,6 +187,81 @@ struct TALER_AUDITORDB_ProgressPoint
/**
+ * Information about a deposit confirmation we received from
+ * a merchant.
+ */
+struct TALER_AUDITORDB_DepositConfirmation
+{
+
+ /**
+ * Hash over the contract for which this deposit is made.
+ */
+ struct GNUNET_HashCode h_contract_terms;
+
+ /**
+ * Hash over the wiring information of the merchant.
+ */
+ struct GNUNET_HashCode h_wire;
+
+ /**
+ * Time when this confirmation was generated.
+ */
+ struct GNUNET_TIME_Absolute timestamp;
+
+ /**
+ * How much time does the @e merchant have to issue a refund
+ * request? Zero if refunds are not allowed. After this time, the
+ * coin cannot be refunded. Note that the wire transfer will not be
+ * performed by the exchange until the refund deadline. This value
+ * is taken from the original deposit request.
+ */
+ struct GNUNET_TIME_Absolute refund_deadline;
+
+ /**
+ * Amount to be deposited, excluding fee. Calculated from the
+ * amount with fee and the fee from the deposit request.
+ */
+ struct TALER_Amount amount_without_fee;
+
+ /**
+ * The coin's public key. This is the value that must have been
+ * signed (blindly) by the Exchange. The deposit request is to be
+ * signed by the corresponding private key (using EdDSA).
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ /**
+ * The Merchant's public key. Allows the merchant to later refund
+ * the transaction or to inquire about the wire transfer identifier.
+ */
+ struct TALER_MerchantPublicKeyP merchant;
+
+ /**
+ * Signature from the exchange of type
+ * #TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT.
+ */
+ struct TALER_ExchangeSignatureP exchange_sig;
+
+ /**
+ * Public signing key from the exchange matching @e exchange_sig.
+ */
+ struct TALER_ExchangeSignatureP exchange_pub;
+
+ /**
+ * Exchange master signature over @e exchange_sig.
+ */
+ struct TALER_MasterSignatureP master_sig;
+
+ /**
+ * Master public key of the exchange corresponding to @e master_sig.
+ * Identifies the exchange this is about.
+ */
+ struct TALER_MasterPublicKeyP master_public_key;
+
+};
+
+
+/**
* Handle for one session with the database.
*/
struct TALER_AUDITORDB_Session;
@@ -292,6 +367,20 @@ struct TALER_AUDITORDB_Plugin
/**
+ * Insert information about a deposit confirmation into the database.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param session connection to the database
+ * @param dc deposit confirmation information to store
+ * @return query result status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_deposit_confirmation) (void *cls,
+ struct TALER_AUDITORDB_Session *session,
+ const struct TALER_AUDITORDB_DepositConfirmation *dc);
+
+
+ /**
* Insert information about a denomination key and in particular
* the properties (value, fees, expiration times) the coins signed
* with this key have.