aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2022-10-14 20:10:06 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2022-10-14 20:10:06 +0200
commit63b19fad0cbcafa340d3344c9dc33c06402371a6 (patch)
tree2d96278051f09dcead1c6470e1258d3bdb7d6bde /src
parent29e5cd0ef5e53cfdb39f4dd5b43902c2b63571e5 (diff)
simplify datastructures
Diffstat (limited to 'src')
-rw-r--r--src/exchange/taler-exchange-httpd_batch-deposit.c31
-rw-r--r--src/exchange/taler-exchange-httpd_deposit.c54
-rw-r--r--src/exchange/taler-exchange-httpd_responses.c6
-rw-r--r--src/include/taler_exchangedb_plugin.h53
-rw-r--r--src/include/taler_extensions_policy.h2
5 files changed, 76 insertions, 70 deletions
diff --git a/src/exchange/taler-exchange-httpd_batch-deposit.c b/src/exchange/taler-exchange-httpd_batch-deposit.c
index 6393ff97..92bf5bdd 100644
--- a/src/exchange/taler-exchange-httpd_batch-deposit.c
+++ b/src/exchange/taler-exchange-httpd_batch-deposit.c
@@ -509,19 +509,19 @@ parse_coin (struct MHD_Connection *connection,
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
if (GNUNET_OK !=
- TALER_wallet_deposit_verify (&deposit->amount_with_fee,
- &deposit->deposit_fee,
- &dc->h_wire,
- &dc->h_contract_terms,
- &deposit->coin.h_age_commitment,
- dc->has_policy ? &dc->h_policy :
- NULL,
- &deposit->coin.denom_pub_hash,
- dc->timestamp,
- &dc->merchant_pub,
- dc->refund_deadline,
- &deposit->coin.coin_pub,
- &deposit->csig))
+ TALER_wallet_deposit_verify (
+ &deposit->amount_with_fee,
+ &deposit->deposit_fee,
+ &dc->h_wire,
+ &dc->h_contract_terms,
+ &deposit->coin.h_age_commitment,
+ dc->has_policy ? &dc->h_policy : NULL,
+ &deposit->coin.denom_pub_hash,
+ dc->timestamp,
+ &dc->merchant_pub,
+ dc->refund_deadline,
+ &deposit->coin.coin_pub,
+ &deposit->csig))
{
TALER_LOG_WARNING ("Invalid signature on /batch-deposit request\n");
GNUNET_JSON_parse_free (spec);
@@ -537,11 +537,6 @@ parse_coin (struct MHD_Connection *connection,
deposit->h_contract_terms = dc->h_contract_terms;
deposit->wire_salt = dc->wire_salt;
deposit->receiver_wire_account = (char *) dc->payto_uri;
- /* FIXME-OEC: #7270 should NOT insert the extension details N times,
- but rather insert them ONCE and then per-coin only use
- the resulting extension UUID/serial; so the data structure
- here should be changed once we look at extensions in earnest. */
- deposit->policy_json = dc->policy_json;
deposit->timestamp = dc->timestamp;
deposit->refund_deadline = dc->refund_deadline;
deposit->wire_deadline = dc->wire_deadline;
diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c
index f44775c0..ab431f8f 100644
--- a/src/exchange/taler-exchange-httpd_deposit.c
+++ b/src/exchange/taler-exchange-httpd_deposit.c
@@ -132,8 +132,25 @@ struct DepositContext
*/
uint64_t known_coin_id;
+ /*
+ * True if @e policy_json was provided
+ */
+ bool has_policy;
+
+ /**
+ * If @e has_policy is true, the corresponding policy extension calculates
+ * these details. These will be persisted in the policy_details table.
+ */
+ struct TALER_PolicyDetails policy_details;
+
/**
- * When deposit->has_policy is true, and deposit->policy_details are
+ * Hash over the policy data for this deposit (remains unknown to the
+ * Exchange). Needed for the verification of the deposit's signature
+ */
+ struct TALER_ExtensionPolicyHashP h_policy;
+
+ /**
+ * When has_policy is true, and deposit->policy_details are
* persisted, this contains the id of the record in the policy_details table.
*/
uint64_t policy_details_serial_id;
@@ -173,17 +190,14 @@ deposit_transaction (void *cls,
/* If the deposit has a policy associated to it, persist it. This will
* insert or update the record. */
- if (dc->deposit->has_policy)
+ if (dc->has_policy)
{
- struct TALER_Amount accumulated_total;
- enum TALER_PolicyFulfillmentState fulfillment_state;
- qs = TEH_plugin->persist_policy_details (TEH_plugin->cls,
- &dc->deposit->policy_details,
- &dc->policy_details_serial_id,
- &accumulated_total,
- &fulfillment_state);
-
- /* FIXME: what to do with accumulated_total and fulfillment_state ? */
+ qs = TEH_plugin->persist_policy_details (
+ TEH_plugin->cls,
+ &dc->policy_details,
+ &dc->policy_details_serial_id,
+ &dc->policy_details.accumulated_total,
+ &dc->policy_details.fulfillment_state);
if (qs < 0)
return qs;
@@ -194,7 +208,7 @@ deposit_transaction (void *cls,
dc->deposit,
dc->known_coin_id,
&dc->h_payto,
- (dc->deposit->has_policy)
+ (dc->has_policy)
? &dc->policy_details_serial_id
: NULL,
&dc->exchange_timestamp,
@@ -283,7 +297,7 @@ TEH_handler_deposit (struct MHD_Connection *connection,
&deposit.wire_deadline),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_json ("policy",
- &deposit.policy_json),
+ &dc.policy_details.policy_json),
&no_policy_json),
GNUNET_JSON_spec_end ()
};
@@ -312,7 +326,7 @@ TEH_handler_deposit (struct MHD_Connection *connection,
}
/* set the state of the policy presence in the deposit struct */
- deposit.has_policy = ! no_policy_json;
+ dc.has_policy = ! no_policy_json;
/* validate merchant's wire details (as far as we can) */
{
@@ -463,23 +477,23 @@ TEH_handler_deposit (struct MHD_Connection *connection,
}
/* Check policy input and create policy details */
- if (deposit.has_policy)
+ if (dc.has_policy)
{
const char *error_hint = NULL;
if (GNUNET_OK !=
TALER_extensions_create_policy_details (
- deposit.policy_json,
- &deposit.policy_details,
+ dc.policy_details.policy_json,
+ &dc.policy_details,
&error_hint))
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED,
error_hint);
- TALER_deposit_policy_hash (deposit.policy_json,
- &deposit.h_policy);
- ph_policy = &deposit.h_policy;
+ TALER_deposit_policy_hash (dc.policy_details.policy_json,
+ &dc.h_policy);
+ ph_policy = &dc.h_policy;
}
diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c
index fb6bc21d..90284300 100644
--- a/src/exchange/taler-exchange-httpd_responses.c
+++ b/src/exchange/taler-exchange-httpd_responses.c
@@ -76,7 +76,7 @@ TEH_RESPONSE_compile_transaction_history (
&h_wire,
&deposit->h_contract_terms,
&deposit->h_age_commitment,
- &deposit->h_policy,
+ (deposit->has_policy) ? &deposit->h_policy : NULL,
&deposit->h_denom_pub,
deposit->timestamp,
&deposit->merchant_pub,
@@ -111,6 +111,10 @@ TEH_RESPONSE_compile_transaction_history (
GNUNET_JSON_pack_data_auto ("h_wire",
&h_wire),
GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_data_auto (
+ "h_policy",
+ ((deposit->has_policy) ? &deposit->h_policy : NULL))),
+ GNUNET_JSON_pack_allow_null (
deposit->no_age_commitment ?
GNUNET_JSON_pack_string (
"h_age_commitment", NULL) :
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index 881e0cef..6d8b8ec2 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -1448,30 +1448,6 @@ struct TALER_EXCHANGEDB_Deposit
char *receiver_wire_account;
/**
- * Additional policy and its options, relevant for this deposit operation,
- * possibly NULL!
- */
- json_t *policy_json;
-
- /*
- * True if @e policy_json was provided
- */
- bool has_policy;
-
- /**
- * Hash over the @e policy_options. Only filled if @e has_policy is true.
- * Needed for the verification of the deposit's signature
- */
- struct TALER_ExtensionPolicyHashP h_policy;
-
- /**
- * If @e policy_json was present, the corresponding policy extension
- * calculates these details. These will be persisted in the policy_details
- * table.
- */
- struct TALER_PolicyDetails policy_details;
-
- /**
* Time when this request was generated. Used, for example, to
* assess when (roughly) the income was achieved for tax purposes.
* Note that the Exchange will only check that the timestamp is not "too
@@ -1512,6 +1488,17 @@ struct TALER_EXCHANGEDB_Deposit
*/
struct TALER_Amount deposit_fee;
+ /*
+ * True if @e policy_json was provided
+ */
+ bool has_policy;
+
+ /**
+ * Hash over the policy data for this deposit (remains unknown to the
+ * Exchange). Needed for the verification of the deposit's signature
+ */
+ struct TALER_ExtensionPolicyHashP h_policy;
+
};
@@ -1543,12 +1530,6 @@ struct TALER_EXCHANGEDB_DepositListEntry
struct TALER_PrivateContractHashP h_contract_terms;
/**
- * Hash over the policy data for this deposit (remains unknown to the
- * Exchange). Needed for the verification of the deposit's signature
- */
- struct TALER_ExtensionPolicyHashP h_policy;
-
- /**
* Hash of the public denomination key used to sign the coin.
*/
struct TALER_DenominationHashP h_denom_pub;
@@ -1616,6 +1597,18 @@ struct TALER_EXCHANGEDB_DepositListEntry
*/
struct TALER_Amount deposit_fee;
+ /*
+ * True if a policy was provided with the deposit request
+ */
+ bool has_policy;
+
+ /**
+ * Hash over the policy data for this deposit (remains unknown to the
+ * Exchange). Needed for the verification of the deposit's signature
+ */
+ struct TALER_ExtensionPolicyHashP h_policy;
+
+
/**
* Has the deposit been wired?
*/
diff --git a/src/include/taler_extensions_policy.h b/src/include/taler_extensions_policy.h
index 4e92d37d..14a581f3 100644
--- a/src/include/taler_extensions_policy.h
+++ b/src/include/taler_extensions_policy.h
@@ -66,7 +66,7 @@ struct TALER_PolicyDetails
struct GNUNET_HashCode hash_code;
/* Content of the policy in its original JSON form */
- const json_t *policy_json;
+ json_t *policy_json;
/* When the deadline is meat and the policy is still in "Ready" state,
* a timeout-handler will transfer the amount