aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-05-08 11:37:37 +0200
committerChristian Grothoff <christian@grothoff.org>2022-05-08 11:37:37 +0200
commitd3a63881999aa1c6d763263346a0a5979ec6efac (patch)
tree92f220ad08ce79d1f18366346ffabfa93cf33d75 /src/exchangedb
parent6b8e732bf8d8bfae268e7f5a9a09af9167fd0d47 (diff)
downloadexchange-d3a63881999aa1c6d763263346a0a5979ec6efac.tar.xz
pass purse_fee to determine how purse creation is paid for
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/common-0001.sql1
-rw-r--r--src/exchangedb/exchange-0001-part.sql21
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c18
3 files changed, 31 insertions, 9 deletions
diff --git a/src/exchangedb/common-0001.sql b/src/exchangedb/common-0001.sql
index 861e85475..3690eb347 100644
--- a/src/exchangedb/common-0001.sql
+++ b/src/exchangedb/common-0001.sql
@@ -1165,6 +1165,7 @@ BEGIN
',purse_expiration INT8 NOT NULL'
',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
',age_limit INT4 NOT NULL'
+ ',flags INT4 NOT NULL'
',refunded BOOLEAN NOT NULL DEFAULT(FALSE)'
',finished BOOLEAN NOT NULL DEFAULT(FALSE)'
',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql
index 4b9493bb1..b0c5171d8 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -1016,8 +1016,8 @@ COMMENT ON COLUMN purse_requests.purse_expiration
IS 'When the purse is set to expire';
COMMENT ON COLUMN purse_requests.h_contract_terms
IS 'Hash of the contract the parties are to agree to';
-COMMENT ON COLUMN purse_requests.shard
- IS 'for load distribution among router processes';
+COMMENT ON COLUMN purse_requests.flags
+ IS 'see the enum TALER_WalletAccountMergeFlags';
COMMENT ON COLUMN purse_requests.finished
IS 'set to TRUE once the purse has been merged (into reserve or wad) or the coins were refunded (transfer aborted)';
COMMENT ON COLUMN purse_requests.refunded
@@ -1312,9 +1312,9 @@ COMMENT ON TABLE purse_actions
IS 'purses awaiting some action by the router';
COMMENT ON COLUMN purse_actions.purse_pub
IS 'public (contract) key of the purse';
-COMMENT ON COLUMN purse_action.action_date
+COMMENT ON COLUMN purse_actions.action_date
IS 'when is the purse ready for action';
-COMMENT ON COLUMN purse_action.partner_serial_id
+COMMENT ON COLUMN purse_actions.partner_serial_id
IS 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown';
CREATE INDEX IF NOT EXISTS purse_action_by_target
@@ -1344,6 +1344,7 @@ CREATE TRIGGER purse_requests_on_insert
ON purse_requests
FOR EACH ROW EXECUTE FUNCTION purse_requests_insert_trigger();
COMMENT ON TRIGGER purse_requests_on_insert
+ ON purse_requests
IS 'Here we install an entry for the purse expiration.';
@@ -1392,6 +1393,7 @@ CREATE TRIGGER purse_merges_on_insert
ON purse_merges
FOR EACH ROW EXECUTE FUNCTION purse_merge_insert_trigger();
COMMENT ON TRIGGER purse_merges_on_insert
+ ON purse_merges
IS 'Here we install an entry that triggers the merge (if the purse is already full).';
@@ -1440,6 +1442,10 @@ BEGIN
(NEW.balance_frac >= NEW.amount_with_fee_frac) );
IF (was_merged AND was_paid)
THEN
+ -- FIXME: If 0==psi, why not simply DO the merge here?
+ -- Adding up reserve balance + setting finished
+ -- is hardly doing much, and could be combined
+ -- with the reserve update above!
UPDATE purse_actions
SET action_date=0 --- "immediately"
,partner_serial_id=psi
@@ -1448,14 +1454,15 @@ BEGIN
RETURN NEW;
END $$;
-COMMENT ON FUNCTION purse_requests_on_update_trigger
- IS 'Trigger the router if the purse is ready. Also removes the entry from the router watchlist once the purse is fnished.';
+COMMENT ON FUNCTION purse_requests_on_update_trigger()
+ IS 'Trigger the router if the purse is ready. Also removes the entry from the router watchlist once the purse is finished.';
CREATE TRIGGER purse_requests_on_update
BEFORE UPDATE
ON purse_requests
- FOR EACH ROW EXECUTE FUNCTION purse_requests_update_trigger();
+ FOR EACH ROW EXECUTE FUNCTION purse_requests_on_update_trigger();
COMMENT ON TRIGGER purse_requests_on_update
+ ON purse_requests
IS 'This covers the case where a deposit is made into a purse, which inherently then changes the purse balance via an UPDATE. If the merge is already present and the balance matches the total, we trigger the router. Once the router sets the purse to finished, the trigger will remove the purse from the watchlist of the router.';
---------------------------------------------------------------------------
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index aa4066e6f..a4807d030 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -3541,13 +3541,17 @@ prepare_statements (struct PostgresClosure *pg)
" ,purse_expiration"
" ,h_contract_terms"
" ,age_limit"
+ " ,flags"
+ " ,in_reserve_quota"
" ,amount_with_fee_val"
" ,amount_with_fee_frac"
+ " ,purse_fee_val"
+ " ,purse_fee_frac"
" ,purse_sig"
" ) VALUES "
- " ($1, $2, $3, $4, $5, $6, $7, $8)"
+ " ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)"
" ON CONFLICT DO NOTHING;",
- 8),
+ 12),
/* Used in #postgres_select_purse */
GNUNET_PQ_make_prepare (
"select_purse",
@@ -13481,6 +13485,8 @@ postgres_select_purse_request (
* @param purse_expiration time when the purse will expire
* @param h_contract_terms hash of the contract for the purse
* @param age_limit age limit to enforce for payments into the purse
+ * @param flags flags for the operation
+ * @param purse_fee fee we are allowed to charge to the reserve (depending on @a flags)
* @param amount target amount (with fees) to be put into the purse
* @param purse_sig signature with @a purse_pub's private key affirming the above
* @param[out] in_conflict set to true if the meta data
@@ -13497,19 +13503,27 @@ postgres_insert_purse_request (
struct GNUNET_TIME_Timestamp purse_expiration,
const struct TALER_PrivateContractHashP *h_contract_terms,
uint32_t age_limit,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
const struct TALER_Amount *amount,
const struct TALER_PurseContractSignatureP *purse_sig,
bool *in_conflict)
{
struct PostgresClosure *pg = cls;
enum GNUNET_DB_QueryStatus qs;
+ uint32_t flags32 = (uint32_t) flags;
+ bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE
+ == (flags & TALER_WAMF_MERGE_MODE_MASK));
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (purse_pub),
GNUNET_PQ_query_param_auto_from_type (merge_pub),
GNUNET_PQ_query_param_timestamp (&purse_expiration),
GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
GNUNET_PQ_query_param_uint32 (&age_limit),
+ GNUNET_PQ_query_param_uint32 (&flags32),
+ GNUNET_PQ_query_param_bool (in_reserve_quota),
TALER_PQ_query_param_amount (amount),
+ TALER_PQ_query_param_amount (purse_fee),
GNUNET_PQ_query_param_auto_from_type (purse_sig),
GNUNET_PQ_query_param_end
};