simplify datastructures

This commit is contained in:
Özgür Kesim 2022-10-14 20:10:06 +02:00
parent 29e5cd0ef5
commit 63b19fad0c
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
5 changed files with 76 additions and 70 deletions

View File

@ -509,19 +509,19 @@ parse_coin (struct MHD_Connection *connection,
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++; TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
if (GNUNET_OK != if (GNUNET_OK !=
TALER_wallet_deposit_verify (&deposit->amount_with_fee, TALER_wallet_deposit_verify (
&deposit->deposit_fee, &deposit->amount_with_fee,
&dc->h_wire, &deposit->deposit_fee,
&dc->h_contract_terms, &dc->h_wire,
&deposit->coin.h_age_commitment, &dc->h_contract_terms,
dc->has_policy ? &dc->h_policy : &deposit->coin.h_age_commitment,
NULL, dc->has_policy ? &dc->h_policy : NULL,
&deposit->coin.denom_pub_hash, &deposit->coin.denom_pub_hash,
dc->timestamp, dc->timestamp,
&dc->merchant_pub, &dc->merchant_pub,
dc->refund_deadline, dc->refund_deadline,
&deposit->coin.coin_pub, &deposit->coin.coin_pub,
&deposit->csig)) &deposit->csig))
{ {
TALER_LOG_WARNING ("Invalid signature on /batch-deposit request\n"); TALER_LOG_WARNING ("Invalid signature on /batch-deposit request\n");
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
@ -537,11 +537,6 @@ parse_coin (struct MHD_Connection *connection,
deposit->h_contract_terms = dc->h_contract_terms; deposit->h_contract_terms = dc->h_contract_terms;
deposit->wire_salt = dc->wire_salt; deposit->wire_salt = dc->wire_salt;
deposit->receiver_wire_account = (char *) dc->payto_uri; 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->timestamp = dc->timestamp;
deposit->refund_deadline = dc->refund_deadline; deposit->refund_deadline = dc->refund_deadline;
deposit->wire_deadline = dc->wire_deadline; deposit->wire_deadline = dc->wire_deadline;

View File

@ -132,8 +132,25 @@ struct DepositContext
*/ */
uint64_t known_coin_id; uint64_t known_coin_id;
/*
* True if @e policy_json was provided
*/
bool has_policy;
/** /**
* When deposit->has_policy is true, and deposit->policy_details are * 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;
/**
* 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. * persisted, this contains the id of the record in the policy_details table.
*/ */
uint64_t policy_details_serial_id; 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 /* If the deposit has a policy associated to it, persist it. This will
* insert or update the record. */ * insert or update the record. */
if (dc->deposit->has_policy) if (dc->has_policy)
{ {
struct TALER_Amount accumulated_total; qs = TEH_plugin->persist_policy_details (
enum TALER_PolicyFulfillmentState fulfillment_state; TEH_plugin->cls,
qs = TEH_plugin->persist_policy_details (TEH_plugin->cls, &dc->policy_details,
&dc->deposit->policy_details, &dc->policy_details_serial_id,
&dc->policy_details_serial_id, &dc->policy_details.accumulated_total,
&accumulated_total, &dc->policy_details.fulfillment_state);
&fulfillment_state);
/* FIXME: what to do with accumulated_total and fulfillment_state ? */
if (qs < 0) if (qs < 0)
return qs; return qs;
@ -194,7 +208,7 @@ deposit_transaction (void *cls,
dc->deposit, dc->deposit,
dc->known_coin_id, dc->known_coin_id,
&dc->h_payto, &dc->h_payto,
(dc->deposit->has_policy) (dc->has_policy)
? &dc->policy_details_serial_id ? &dc->policy_details_serial_id
: NULL, : NULL,
&dc->exchange_timestamp, &dc->exchange_timestamp,
@ -283,7 +297,7 @@ TEH_handler_deposit (struct MHD_Connection *connection,
&deposit.wire_deadline), &deposit.wire_deadline),
GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_json ("policy", GNUNET_JSON_spec_json ("policy",
&deposit.policy_json), &dc.policy_details.policy_json),
&no_policy_json), &no_policy_json),
GNUNET_JSON_spec_end () 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 */ /* 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) */ /* 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 */ /* Check policy input and create policy details */
if (deposit.has_policy) if (dc.has_policy)
{ {
const char *error_hint = NULL; const char *error_hint = NULL;
if (GNUNET_OK != if (GNUNET_OK !=
TALER_extensions_create_policy_details ( TALER_extensions_create_policy_details (
deposit.policy_json, dc.policy_details.policy_json,
&deposit.policy_details, &dc.policy_details,
&error_hint)) &error_hint))
return TALER_MHD_reply_with_error (connection, return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST, MHD_HTTP_BAD_REQUEST,
TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED, TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED,
error_hint); error_hint);
TALER_deposit_policy_hash (deposit.policy_json, TALER_deposit_policy_hash (dc.policy_details.policy_json,
&deposit.h_policy); &dc.h_policy);
ph_policy = &deposit.h_policy; ph_policy = &dc.h_policy;
} }

View File

@ -76,7 +76,7 @@ TEH_RESPONSE_compile_transaction_history (
&h_wire, &h_wire,
&deposit->h_contract_terms, &deposit->h_contract_terms,
&deposit->h_age_commitment, &deposit->h_age_commitment,
&deposit->h_policy, (deposit->has_policy) ? &deposit->h_policy : NULL,
&deposit->h_denom_pub, &deposit->h_denom_pub,
deposit->timestamp, deposit->timestamp,
&deposit->merchant_pub, &deposit->merchant_pub,
@ -110,6 +110,10 @@ TEH_RESPONSE_compile_transaction_history (
&deposit->h_contract_terms), &deposit->h_contract_terms),
GNUNET_JSON_pack_data_auto ("h_wire", GNUNET_JSON_pack_data_auto ("h_wire",
&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 ( GNUNET_JSON_pack_allow_null (
deposit->no_age_commitment ? deposit->no_age_commitment ?
GNUNET_JSON_pack_string ( GNUNET_JSON_pack_string (

View File

@ -1447,30 +1447,6 @@ struct TALER_EXCHANGEDB_Deposit
*/ */
char *receiver_wire_account; 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 * Time when this request was generated. Used, for example, to
* assess when (roughly) the income was achieved for tax purposes. * assess when (roughly) the income was achieved for tax purposes.
@ -1512,6 +1488,17 @@ struct TALER_EXCHANGEDB_Deposit
*/ */
struct TALER_Amount deposit_fee; 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;
}; };
@ -1542,12 +1529,6 @@ struct TALER_EXCHANGEDB_DepositListEntry
*/ */
struct TALER_PrivateContractHashP h_contract_terms; 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. * Hash of the public denomination key used to sign the coin.
*/ */
@ -1616,6 +1597,18 @@ struct TALER_EXCHANGEDB_DepositListEntry
*/ */
struct TALER_Amount deposit_fee; 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? * Has the deposit been wired?
*/ */

View File

@ -66,7 +66,7 @@ struct TALER_PolicyDetails
struct GNUNET_HashCode hash_code; struct GNUNET_HashCode hash_code;
/* Content of the policy in its original JSON form */ /* 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, /* When the deadline is meat and the policy is still in "Ready" state,
* a timeout-handler will transfer the amount * a timeout-handler will transfer the amount