summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-05-07 20:14:02 +0200
committerChristian Grothoff <christian@grothoff.org>2020-05-07 20:14:02 +0200
commit1c14e3319d3f82363a3bfd935410748eb8afb597 (patch)
tree2fa196ffdf27aaf64c4d0e16493f9fcd6328b9e0
parent4344f16b33bad868e8aea32f4921640950068332 (diff)
downloadmerchant-1c14e3319d3f82363a3bfd935410748eb8afb597.tar.gz
merchant-1c14e3319d3f82363a3bfd935410748eb8afb597.tar.bz2
merchant-1c14e3319d3f82363a3bfd935410748eb8afb597.zip
more work on post /transfers and the like
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-pay.c3
-rw-r--r--src/backend/taler-merchant-httpd_private-post-transfers.c12
-rw-r--r--src/backenddb/merchant-0001.sql2
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c177
-rw-r--r--src/include/taler_merchantdb_plugin.h7
5 files changed, 187 insertions, 14 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
index d76965d6..ca519a9f 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -537,12 +537,14 @@ begin_transaction (struct PayContext *pc);
* that no other confirmations are on the way, and can pack a response
* for the wallet
* @param hr HTTP response code details
+ * @param deposit_timestamp time when the exchange generated the deposit confirmation
* @param exchange_sig signature from the exchange over the deposit confirmation
* @param exchange_pub_key which key did the exchange use to create the @a exchange_sig
*/
static void
deposit_cb (void *cls,
const struct TALER_EXCHANGE_HttpResponse *hr,
+ struct GNUNET_TIME_Absolute deposit_timestamp,
const struct TALER_ExchangeSignatureP *exchange_sig,
const struct TALER_ExchangePublicKeyP *exchange_pub)
{
@@ -643,6 +645,7 @@ deposit_cb (void *cls,
TMH_db->preflight (TMH_db->cls);
qs = TMH_db->insert_deposit (TMH_db->cls,
pc->hc->instance->settings.id,
+ deposit_timestamp,
&pc->h_contract_terms,
&dc->coin_pub,
dc->exchange_url,
diff --git a/src/backend/taler-merchant-httpd_private-post-transfers.c b/src/backend/taler-merchant-httpd_private-post-transfers.c
index d78746cb..29e59972 100644
--- a/src/backend/taler-merchant-httpd_private-post-transfers.c
+++ b/src/backend/taler-merchant-httpd_private-post-transfers.c
@@ -261,7 +261,6 @@ transfer_cleanup (void *cls)
*
* @param cls closure with our `struct PostTransfersContext *`
* @param transaction_id of the contract
- * @param coin_pub public key of the coin
* @param exchange_url URL of the exchange that issued @a coin_pub
* @param amount_with_fee amount the exchange will transfer for this coin
* @param deposit_fee fee the exchange will charge for this coin
@@ -270,14 +269,17 @@ transfer_cleanup (void *cls)
*/
static void
check_transfer (void *cls,
- const struct GNUNET_HashCode *h_contract_terms,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
const char *exchange_url,
const struct TALER_Amount *amount_with_fee,
const struct TALER_Amount *deposit_fee,
const struct TALER_Amount *refund_fee,
const struct TALER_Amount *wire_fee,
- const json_t *exchange_proof)
+ const struct GNUNET_HashCode *h_wire,
+ struct GNUNET_TIME_Absolute deposit_timestamp,
+ struct GNUNET_TIME_Absolute refund_deadline,
+ const struct TALER_ExchangeSignatureP *exchange_sig,
+ const struct TALER_ExchangePublicKeyP *exchange_pub);
+
{
struct PostTransfersContext *ptc = cls;
const struct TALER_TrackTransferDetails *ttd = ptc->current_detail;
@@ -301,7 +303,7 @@ check_transfer (void *cls,
"hint", "disagreement about deposit valuation",
"exchange_deposit_proof", exchange_proof,
"conflict_offset", (json_int_t) ptc->current_offset,
- "coin_pub", GNUNET_JSON_from_data_auto (coin_pub),
+ "coin_pub", GNUNET_JSON_from_data_auto (&ttd->coin_pub),
"h_contract_terms", GNUNET_JSON_from_data_auto (
&ttd->h_contract_terms),
"amount_with_fee", TALER_JSON_from_amount (amount_with_fee),
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index 55cef426..754b47f3 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -302,7 +302,7 @@ COMMENT ON TABLE merchant_deposits
COMMENT ON COLUMN merchant_deposits.signkey_serial
IS 'Online signing key of the exchange on the deposit confirmation';
COMMENT ON COLUMN merchant_deposits.deposit_timestamp
- IS 'Time when we received the deposit confirmation from the exchange (not rounded)';
+ IS 'Time when the exchange generated the deposit confirmation';
COMMENT ON COLUMN merchant_deposits.exchange_sig
IS 'Signature of the exchange over the deposit confirmation';
COMMENT ON COLUMN merchant_deposits.wire_fee_val
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index acb32e9b..60cbc7a5 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1683,6 +1683,7 @@ postgres_insert_exchange_signkey (
*
* @param cls closure
* @param instance_id instance to lookup deposits for
+ * @param deposit_timestamp time when the exchange generated the deposit confirmation
* @param h_contract_terms proposal data's hashcode
* @param coin_pub public key of the coin
* @param exchange_url URL of the exchange that issued @a coin_pub
@@ -1698,6 +1699,7 @@ postgres_insert_exchange_signkey (
static enum GNUNET_DB_QueryStatus
postgres_insert_deposit (void *cls,
const char *instance_id,
+ struct GNUNET_TIME_Absolute deposit_timestamp,
const struct GNUNET_HashCode *h_contract_terms,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const char *exchange_url,
@@ -1710,11 +1712,10 @@ postgres_insert_deposit (void *cls,
const struct TALER_ExchangePublicKeyP *exchange_pub)
{
struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (instance_id),
GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
- GNUNET_PQ_query_param_absolute_time (&now), /* $3 */
+ GNUNET_PQ_query_param_absolute_time (&deposit_timestamp), /* $3 */
GNUNET_PQ_query_param_auto_from_type (coin_pub),
GNUNET_PQ_query_param_string (exchange_url),
TALER_PQ_query_param_amount (amount_with_fee), /* $6/$7 */
@@ -2557,7 +2558,7 @@ postgres_lookup_refunds_detailed (
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (instance_id),
+ GNUNET_PQ_query_param_string (instance_id),
GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
GNUNET_PQ_query_param_end
};
@@ -2960,6 +2961,173 @@ postgres_lookup_wire_fee (void *cls,
}
+/**
+ * Closure for #lookup_deposits_by_contract_and_coin_cb().
+ */
+struct LookupDepositsByCnCContext
+{
+ /**
+ * Function to call for each deposit.
+ */
+ TALER_MERCHANTDB_CoinDepositCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Transaction result.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls of type `struct LookupDepositsByCnCContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+lookup_deposits_by_contract_and_coin_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupDepositsByCnCContext *ldcc = cls;
+ struct PostgresClosure *pg = ldcc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ // WIP!
+ uint64_t refund_serial;
+ struct GNUNET_TIME_Absolute timestamp;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ uint64_t rtransaction_id;
+ struct TALER_Amount refund_amount;
+ char *reason;
+ char *exchange_url;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("refund_serial",
+ &refund_serial),
+ GNUNET_PQ_result_spec_absolute_time ("refund_timestamp",
+ &timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_string ("exchange_url",
+ &exchange_url),
+ GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
+ &rtransaction_id),
+ GNUNET_PQ_result_spec_string ("reason",
+ &reason),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("refund_amount",
+ &refund_amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ lrdc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ ldcc->qs = i + 1;
+ ldcc->rc (ldcc->rc_cls,
+ ...);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Lookup information about coin payments by @a h_contract_terms and
+ * @a coin_pub.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup payments for
+ * @param h_contract_terms proposal data's hashcode
+ * @param coin_pub public key to use for the search
+ * @param cb function to call with payment data
+ * @param cb_cls closure for @a cb
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_lookup_deposits_by_contract_and_coin (
+ void *cls,
+ const char *instance_id,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ TALER_MERCHANTDB_CoinDepositCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string_type (instance_id),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct LookupDepositsByCnCContext ldcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ check_connection (pg);
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_deposits_by_contract_and_coin",
+ params,
+ &
+ lookup_deposits_by_contract_and_coin_cb,
+ &ldcc);
+ if (0 >= qs)
+ return qs;
+ return ldcc.qs;
+}
+
+
+/**
+ * Lookup transfer details.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup payments for
+ * @param exchange_url
+ * @param payto_uri
+ * @param wtid
+ * @param total_amount
+ * @param wire_fee
+ * @param execution_time
+ * @param cb function to call with detailed transfer data
+ * @param cb_cls closure for @a cb
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_lookup_transfer_details (
+ void *cls,
+ const char *instance_id,
+ const char *exchange_url,
+ const char *payto_uri,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_Amount *wire_fee,
+ struct GNUNET_TIME_Absolute execution_time,
+ TALER_MERCHANTDB_TransferDetailsCallback cb,
+ void *cb_cls)
+{
+}
+
+
/* ********************* OLD API ************************** */
/**
@@ -6181,6 +6349,9 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->lookup_account = &postgres_lookup_account;
plugin->insert_transfer_details = &postgres_insert_transfer_details;
plugin->lookup_wire_fee = &postgres_lookup_wire_fee;
+ plugin->lookup_deposits_by_contract_and_coin =
+ &postgres_lookup_deposits_by_contract_and_coin;
+ plugin->lookup_transfer_details = &postgres_lookup_transfer_details;
/* OLD API: */
plugin->store_coin_to_transfer = &postgres_store_coin_to_transfer;
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index 51d48dc4..1101e77c 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -453,8 +453,6 @@ typedef void
* Function called with information about a coin that was deposited.
*
* @param cls closure
- * @param h_contract_terms proposal data's hashcode
- * @param coin_pub public key of the coin
* @param exchange_url URL of the exchange that issued the coin
* @param amount_with_fee amount the exchange will deposit for this coin
* @param deposit_fee fee the exchange will charge for this coin
@@ -466,8 +464,6 @@ typedef void
typedef void
(*TALER_MERCHANTDB_CoinDepositCallback)(
void *cls,
- const struct GNUNET_HashCode *h_contract_terms,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
const char *exchange_url,
const struct TALER_Amount *amount_with_fee,
const struct TALER_Amount *deposit_fee,
@@ -1012,6 +1008,7 @@ struct TALER_MERCHANTDB_Plugin
*
* @param cls closure
* @param instance_id instance to lookup deposits for
+ * @param deposit_timestamp time when the exchange generated the deposit confirmation
* @param h_contract_terms proposal data's hashcode
* @param coin_pub public key of the coin
* @param exchange_url URL of the exchange that issued @a coin_pub
@@ -1026,6 +1023,7 @@ struct TALER_MERCHANTDB_Plugin
enum GNUNET_DB_QueryStatus
(*insert_deposit)(void *cls,
const char *instance_id,
+ struct GNUNET_TIME_Absolute deposit_timestamp,
const struct GNUNET_HashCode *h_contract_terms,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const char *exchange_url,
@@ -1300,7 +1298,6 @@ struct TALER_MERCHANTDB_Plugin
struct TALER_MasterSignatureP *master_sig);
- /* WIP: */
/**
* Lookup information about coin payments by @a h_contract_terms and
* @a coin_pub.