summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-30 00:25:17 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-30 00:25:17 +0200
commitf5c484e625cde6b6822ea75c20cecf8f4db7c54d (patch)
treeca954d04bfca85d91198024e1f7cf59e5d0d421f /src/backenddb
parentce97f3d2e12b4da31eb0f611d401f56ce8052de5 (diff)
downloadmerchant-f5c484e625cde6b6822ea75c20cecf8f4db7c54d.tar.gz
merchant-f5c484e625cde6b6822ea75c20cecf8f4db7c54d.tar.bz2
merchant-f5c484e625cde6b6822ea75c20cecf8f4db7c54d.zip
sql-ing
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/merchant-0001.sql6
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c585
2 files changed, 468 insertions, 123 deletions
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index 0682da96..77c79052 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -61,7 +61,7 @@ COMMENT ON COLUMN merchant_exchange_signing_keys.master_pub
CREATE TABLE IF NOT EXISTS merchant_instances
(merchant_serial BIGSERIAL PRIMARY KEY
,merchant_pub BYTEA NOT NULL UNIQUE CHECK (LENGTH(merchant_pub)=32)
- ,merchant_id VARCHAR NOT NULL
+ ,merchant_id VARCHAR NOT NULL UNIQUE
,merchant_name VARCHAR NOT NULL
,address BYTEA NOT NULL
,jurisdiction BYTEA NOT NULL
@@ -279,6 +279,7 @@ CREATE TABLE IF NOT EXISTS merchant_deposits
(deposit_serial BIGSERIAL PRIMARY KEY
,order_serial BIGINT
REFERENCES merchant_contract_terms (order_serial) ON DELETE CASCADE
+ ,deposit_timestamp INT8 NOT NULL
,coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)
,exchange_url VARCHAR NOT NULL
,amount_with_fee_val INT8 NOT NULL
@@ -292,7 +293,6 @@ CREATE TABLE IF NOT EXISTS merchant_deposits
,signkey_serial BIGINT NOT NULL
REFERENCES merchant_exchange_signing_keys (signkey_serial) ON DELETE CASCADE
,exchange_sig BYTEA NOT NULL CHECK (LENGTH(exchange_sig)=64)
- ,exchange_timestamp INT8 NOT NULL
,account_serial BIGINT NOT NULL
REFERENCES merchant_accounts (account_serial) ON DELETE CASCADE
,UNIQUE (order_serial, coin_pub)
@@ -301,6 +301,8 @@ COMMENT ON TABLE merchant_deposits
IS 'Table with the deposit confirmations for each coin we deposited at the exchange';
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)';
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 f02d0900..06f1d7a9 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1501,6 +1501,382 @@ postgres_delete_contract_terms (void *cls,
}
+/**
+ * Closure for #lookup_deposits_cb().
+ */
+struct LookupDepositsContext
+{
+ /**
+ * Function to call with results.
+ */
+ TALER_MERCHANTDB_DepositsCallback cb;
+
+ /**
+ * Closure for @e cls.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Transaction status (set).
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param[in,out] cls of type `struct LookupDepositsContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+lookup_deposits_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupDepositsContext *ldc = cls;
+ struct PostgresClosure *pg = ldc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount deposit_fee;
+ struct TALER_Amount refund_fee;
+ struct TALER_Amount wire_fee;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee",
+ &deposit_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("refund_fee",
+ &refund_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
+ &wire_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ldc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ ldc->qs = i + 1;
+ ldc->cb (ldc->cb_cls,
+ &coin_pub,
+ &amount_with_fee,
+ &deposit_fee,
+ &refund_fee,
+ &wire_fee);
+ GNUNET_PQ_cleanup_result (rs); /* technically useless here */
+ }
+}
+
+
+/**
+ * Lookup information about coins that were successfully deposited for a
+ * given contract.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup deposits for
+ * @param h_contract_terms proposal data's hashcode
+ * @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 (void *cls,
+ const char *instance_id,
+ const struct GNUNET_HashCode *h_contract_terms,
+ TALER_MERCHANTDB_DepositsCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ 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_end
+ };
+ struct LookupDepositsContext ldc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* no preflight check here, run in its own transaction by the caller! */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Finding deposits for h_contract_terms '%s'\n",
+ GNUNET_h2s (h_contract_terms));
+ check_connection (pg);
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_deposits",
+ params,
+ &lookup_deposits_cb,
+ &ldc);
+ if (qs <= 0)
+ return qs;
+ return ldc.qs;
+}
+
+
+/**
+ * Insert an exchange signing key into our database.
+ *
+ * @param cls closure
+ * @param master_pub exchange master public key used for @a master_sig
+ * @param exchange_pub exchange signing key to insert
+ * @param start_date when does the signing key become valid
+ * @param expire_date when does the signing key stop being used
+ * @param end_date when does the signing key become void as proof
+ * @param master_sig signature of @a master_pub over the @a exchange_pub and the dates
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_insert_exchange_signkey (
+ void *cls,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct GNUNET_TIME_Absolute start_date,
+ struct GNUNET_TIME_Absolute expire_date,
+ struct GNUNET_TIME_Absolute end_date,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ // FIXME!
+}
+
+
+/**
+ * Insert payment confirmation from the exchange into the database.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup deposits for
+ * @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
+ * @param amount_with_fee amount the exchange will deposit for this coin
+ * @param deposit_fee fee the exchange will charge for this coin
+ * @param wire_fee wire fee the exchange charges
+ * @param h_wire hash of the wire details of the target account of the merchant
+ * @param exchange_timestamp timestamp from the exchange
+ * @param exchange_sig signature from exchange that coin was accepted
+ * @param exchange_pub signgin key that was used for @a exchange_sig
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_insert_deposit (void *cls,
+ const char *instance_id,
+ 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 struct GNUNET_HashCode *h_wire,
+ const struct TALER_ExchangeSignatureP *exchange_sig,
+ 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_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_string (exchange_url),
+ TALER_PQ_query_param_amount (amount_with_fee), /* $6/$7 */
+ TALER_PQ_query_param_amount (deposit_fee), /* $8, $9 */
+ TALER_PQ_query_param_amount (refund_fee), /* $10, $11 */
+ TALER_PQ_query_param_amount (wire_fee), /* $12, $13 */
+ GNUNET_PQ_query_param_auto_from_type (h_wire), /* $14 */
+ GNUNET_PQ_query_param_auto_from_type (exchange_sig), /* $15 */
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub), /* $16 */
+ GNUNET_PQ_query_param_end
+ };
+
+ /* no preflight check here, run in transaction by caller! */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Storing deposit for instance `%s' h_contract_terms `%s', coin_pub: `%s', amount_with_fee: %s\n",
+ instance_id,
+ GNUNET_h2s (h_contract_terms),
+ TALER_B2S (coin_pub),
+ TALER_amount2s (amount_with_fee));
+ check_connection (pg);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_deposit",
+ params);
+
+}
+
+
+/**
+ * Closure for #lookup_refunds_cb().
+ */
+struct LookupRefundsContext
+{
+ /**
+ * Function to call for each refund.
+ */
+ TALER_MERCHANTDB_RefundCallback rc;
+
+ /**
+ * Closure for @e rc.
+ */
+ void *rc_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 LookupRefundsContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+lookup_refunds_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRefundsContext *lrc = cls;
+ struct PostgresClosure *pg = lrc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_Amount refund_amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ 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);
+ lrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ lrc->qs = i + 1;
+ lrc->rc (lrc->rc_cls,
+ &coin_pub,
+ &refund_amount);
+ GNUNET_PQ_cleanup_result (rs); /* technically useless here */
+ }
+}
+
+
+/**
+ * Obtain refunds associated with a contract.
+ *
+ * @param cls closure, typically a connection to the db
+ * @param instance_id instance to lookup refunds for
+ * @param h_contract_terms hash code of the contract
+ * @param rc function to call for each coin on which there is a refund
+ * @param rc_cls closure for @a rc
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_lookup_refunds (void *cls,
+ const char *instance_id,
+ const struct GNUNET_HashCode *h_contract_terms,
+ TALER_MERCHANTDB_RefundCallback rc,
+ void *rc_cls)
+{
+ struct PostgresClosure *pg = cls;
+ 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_end
+ };
+ struct LookupRefundsContext lrc = {
+ .rc = rc,
+ .rc_cls = rc_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* no preflight check here, run in transaction by caller! */
+ TALER_LOG_DEBUG ("Looking for refund of h_contract_terms %s at `%s'\n",
+ GNUNET_h2s (h_contract_terms),
+ instance_id);
+ check_connection (pg);
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_refunds",
+ params,
+ &lookup_refunds_cb,
+ &lrc);
+ if (0 >= qs)
+ return qs;
+ return lrc.qs;
+}
+
+
+/**
+ * Mark contract as paid and store the current @a session_id
+ * for which the contract was paid.
+ *
+ * @param cls closure
+ * @param instance_id instance to mark contract as paid for
+ * @param h_contract_terms hash of the contract that is now paid
+ * @param session_id the session that paid the contract, can be NULL
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_mark_contract_paid (void *cls,
+ const char *instance_id,
+ const struct GNUNET_HashCode *h_contract_terms,
+ const char *session_id)
+{
+ struct PostgresClosure *pg = cls;
+ 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_string (session_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ /* no preflight check here, run in transaction by caller! */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Marking h_contract_terms '%s' of %s as paid for session `%s'\n",
+ GNUNET_h2s (h_contract_terms),
+ instance_id,
+ session_id);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "mark_contract_paid",
+ params);
+}
+
+
/* ********************* OLD API ************************** */
/**
@@ -1580,44 +1956,6 @@ postgres_find_paid_contract_terms_from_hash (void *cls,
/**
- * Mark contract terms as paid. Needed by /history as only paid
- * contracts must be shown.
- *
- * NOTE: we can't get the list of (paid) contracts from the
- * transactions table because it lacks contract_terms plain JSON. In
- * facts, the protocol doesn't allow to store contract_terms in
- * transactions table, as /pay handler doesn't receive this data (only
- * /proposal does).
- *
- * @param cls closure
- * @param h_contract_terms hash of the contract that is now paid
- * @param merchant_pub merchant's public key
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_mark_proposal_paid (void *cls,
- const struct GNUNET_HashCode *h_contract_terms,
- const struct
- TALER_MerchantPublicKeyP *merchant_pub)
-{
- 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_end
- };
-
- TALER_LOG_DEBUG ("Marking proposal paid, h_contract_terms: '%s',"
- " merchant_pub: '%s'\n",
- GNUNET_h2s (h_contract_terms),
- TALER_B2S (merchant_pub));
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "mark_proposal_paid",
- params);
-}
-
-
-/**
* Store the order ID that was used to pay for a resource within a session.
*
* @param cls closure
@@ -1696,64 +2034,6 @@ postgres_find_session_info (void *cls,
/**
- * Insert payment confirmation from the exchange into the database.
- *
- * @param cls closure
- * @param order_id identificator of the proposal associated with this revenue
- * @param merchant_pub merchant's public key
- * @param coin_pub public key of 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
- * @param refund_fee fee the exchange will charge for refunding this coin
- * @param wire_fee wire fee changed by the exchange
- * @param signkey_pub public key used by the exchange for @a exchange_proof
- * @param exchange_proof proof from exchange that coin was accepted
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_store_deposit (void *cls,
- const struct GNUNET_HashCode *h_contract_terms,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- 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 struct TALER_ExchangePublicKeyP *signkey_pub,
- const json_t *exchange_proof)
-{
- 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_string (exchange_url),
- TALER_PQ_query_param_amount (amount_with_fee),
- TALER_PQ_query_param_amount (deposit_fee),
- TALER_PQ_query_param_amount (refund_fee),
- TALER_PQ_query_param_amount (wire_fee),
- GNUNET_PQ_query_param_auto_from_type (signkey_pub),
- TALER_PQ_query_param_json (exchange_proof),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Storing payment for h_contract_terms `%s', coin_pub: `%s', amount_with_fee: %s\n",
- GNUNET_h2s (h_contract_terms),
- TALER_B2S (coin_pub),
- TALER_amount2s (amount_with_fee));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Merchant pub is `%s'\n",
- TALER_B2S (merchant_pub));
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_deposit",
- params);
-}
-
-
-/**
* Insert mapping of @a coin_pub and @a h_contract_terms to
* corresponding @a wtid.
*
@@ -2075,7 +2355,7 @@ find_payments_cb (void *cls,
* @param cb_cls closure for @a cb
* @return transaction status
*/
-static enum GNUNET_DB_QueryStatus
+enum GNUNET_DB_QueryStatus
postgres_find_payments (void *cls,
const struct GNUNET_HashCode *h_contract_terms,
const struct TALER_MerchantPublicKeyP *merchant_pub,
@@ -2535,7 +2815,7 @@ struct GetRefundsContext
/**
* Function to call for each refund.
*/
- TALER_MERCHANTDB_RefundCallback rc;
+ TALER_MERCHANTDB_CoinRefundCallback rc;
/**
* Closure for @e rc.
@@ -2626,12 +2906,12 @@ get_refunds_cb (void *cls,
* @param rc_cls closure for @a rc
* @return transaction status
*/
-static enum GNUNET_DB_QueryStatus
+enum GNUNET_DB_QueryStatus
postgres_get_refunds_from_contract_terms_hash (
void *cls,
const struct TALER_MerchantPublicKeyP *merchant_pub,
const struct GNUNET_HashCode *h_contract_terms,
- TALER_MERCHANTDB_RefundCallback rc,
+ TALER_MERCHANTDB_CoinRefundCallback rc,
void *rc_cls)
{
struct PostgresClosure *pg = cls;
@@ -5002,14 +5282,45 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" (NOT paid) ) OR"
" (creation_time + $3 > $4) )",
4),
-
- /* OLD API: */
-
-#if 0
+ GNUNET_PQ_make_prepare ("lookup_deposits",
+ "SELECT"
+ " coin_pub"
+ ",amount_with_fee_val"
+ ",amount_with_fee_frac"
+ ",deposit_fee_val"
+ ",deposit_fee_frac"
+ ",refund_fee_val"
+ ",refund_fee_frac"
+ ",wire_fee_val"
+ ",wire_fee_frac"
+ " FROM merchant_deposits"
+ " WHERE order_serial="
+ " (SELECT order_serial"
+ " FROM merchant_contract_terms"
+ " WHERE h_contract_terms=$2"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1))",
+ 2),
GNUNET_PQ_make_prepare ("insert_deposit",
+ "WITH md AS"
+ " (SELECT account_serial, merchant_serial"
+ " FROM merchant_accounts"
+ " WHERE h_wire=$14"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1))"
+ ", ed AS"
+ " (SELECT signkey_serial"
+ " FROM merchant_exchange_signing_keys"
+ " WHERE exchange_pub=$16"
+ " ORDER BY start_date DESC"
+ " LIMIT 1)"
"INSERT INTO merchant_deposits"
- "(h_contract_terms"
- ",merchant_pub"
+ "(order_serial"
+ ",deposit_timestamp"
",coin_pub"
",exchange_url"
",amount_with_fee_val"
@@ -5020,10 +5331,47 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
",refund_fee_frac"
",wire_fee_val"
",wire_fee_frac"
- ",signkey_pub"
- ",exchange_proof) VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)",
- 14),
+ ",exchange_sig"
+ ",signkey_serial"
+ ",account_serial)"
+ " SELECT "
+ " order_serial"
+ " ,$3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $15"
+ " ,ed.signkey_serial"
+ " ,md.account_serial"
+ " FROM merchant_contract_terms"
+ " JOIN md USING (merchant_serial)"
+ " FULL OUTER JOIN ed ON TRUE"
+ " WHERE h_contract_terms=$2",
+ 16),
+ GNUNET_PQ_make_prepare ("lookup_refunds",
+ "SELECT"
+ " coin_pub"
+ ",refund_amount_val"
+ ",refund_amount_frac"
+ " FROM merchant_refunds"
+ " WHERE order_serial="
+ " (SELECT order_serial"
+ " FROM merchant_contract_terms"
+ " WHERE h_contract_terms=$2"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1))",
+ 2),
+ GNUNET_PQ_make_prepare ("mark_contract_paid",
+ "UPDATE merchant_contract_terms SET"
+ " paid=TRUE"
+ ",session_id=$3"
+ " WHERE h_contract_terms=$2"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1)",
+ 3),
+ /* OLD API: */
+
+#if 0
GNUNET_PQ_make_prepare ("insert_transfer",
"INSERT INTO merchant_transfers"
"(h_contract_terms"
@@ -5071,12 +5419,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" VALUES "
"($1, $2, $3, $4, $5)",
5),
- GNUNET_PQ_make_prepare ("mark_proposal_paid",
- "UPDATE merchant_contract_terms SET"
- " paid=TRUE"
- " WHERE h_contract_terms=$1"
- " AND merchant_pub=$2",
- 2),
GNUNET_PQ_make_prepare ("insert_wire_fee",
"INSERT INTO exchange_wire_fees"
"(exchange_pub"
@@ -5418,30 +5760,31 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->lookup_contract_terms = &postgres_lookup_contract_terms;
plugin->insert_contract_terms = &postgres_insert_contract_terms;
plugin->delete_contract_terms = &postgres_delete_contract_terms;
+ plugin->lookup_deposits = &postgres_lookup_deposits;
+ plugin->insert_exchange_signkey = &postgres_insert_exchange_signkey;
+ plugin->insert_deposit = &postgres_insert_deposit;
+ plugin->lookup_refunds = &postgres_lookup_refunds;
+ plugin->mark_contract_paid = &postgres_mark_contract_paid;
+
/* OLD API: */
plugin->find_contract_terms_from_hash =
&postgres_find_contract_terms_from_hash;
plugin->find_paid_contract_terms_from_hash =
&postgres_find_paid_contract_terms_from_hash;
- 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_payments_by_hash_and_coin =
&postgres_find_payments_by_hash_and_coin;
- plugin->find_payments = &postgres_find_payments;
plugin->find_transfers_by_hash = &postgres_find_transfers_by_hash;
plugin->find_deposits_by_wtid = &postgres_find_deposits_by_wtid;
plugin->find_proof_by_wtid = &postgres_find_proof_by_wtid;
plugin->get_authorized_tip_amount = &postgres_get_authorized_tip_amount;
- plugin->get_refunds_from_contract_terms_hash =
- &postgres_get_refunds_from_contract_terms_hash;
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;
plugin->enable_tip_reserve_TR = &postgres_enable_tip_reserve_TR;