diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2022-10-14 18:56:59 +0200 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2022-10-14 18:56:59 +0200 |
commit | 054e157af8c768062dd0a8e66614da18407fca28 (patch) | |
tree | fcd792c6ed7f4384e9b29f8e200f62837cd00f1e /src/include/taler_exchangedb_plugin.h | |
parent | 956e3c3065ddb762dbe01fd720cc5ef403232564 (diff) |
WIP: policy_details handling continued
- policy details generated on deposit/batch-deposit requests
- insert or update of policy details in the DB
- accumulation of amounts of multiple deposits for the same
policy_details
Diffstat (limited to 'src/include/taler_exchangedb_plugin.h')
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 117 |
1 files changed, 79 insertions, 38 deletions
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 80a19b67..881e0cef 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -26,6 +26,7 @@ #include <gnunet/gnunet_db_lib.h> #include "taler_json_lib.h" #include "taler_signatures.h" +#include "taler_extensions_policy.h" /** @@ -223,7 +224,6 @@ enum TALER_EXCHANGEDB_ReplicatedTable TALER_EXCHANGEDB_RT_EXTENSIONS, TALER_EXCHANGEDB_RT_POLICY_DETAILS, TALER_EXCHANGEDB_RT_POLICY_FULFILMENTS, - TALER_EXCHANGEDB_RT_POLICY_DETAILS_FULFILMENTS, TALER_EXCHANGEDB_RT_PURSE_REQUESTS, TALER_EXCHANGEDB_RT_PURSE_REFUNDS, TALER_EXCHANGEDB_RT_PURSE_MERGES, @@ -528,24 +528,27 @@ struct TALER_EXCHANGEDB_TableData struct { - char *policy_options; - struct GNUNET_HashCode serial_id; + struct GNUNET_HashCode hash_code; + json_t *policy_json; + bool no_policy_json; struct GNUNET_TIME_Timestamp deadline; - uint16_t timeout_fulfilment_state; - uint16_t fulfilment_state; + struct TALER_Amount commitment; + struct TALER_Amount accumulated_total; + struct TALER_Amount fee; + struct TALER_Amount transferable; + uint16_t fulfillment_state; /* will also be recomputed */ + uint64_t fulfillment_id; + bool no_fulfillment_id; } policy_details; struct { - struct GNUNET_HashCode serial_id; - uint64_t fulfilment_id; - } policy_details_fulfilments; - - struct - { - char *fulfilment_proof; - struct GNUNET_TIME_Timestamp fulfilment_timestamp; - } policy_fulfilments; + struct GNUNET_TIME_Timestamp fulfillment_timestamp; + char *fulfillment_proof; + struct GNUNET_HashCode h_fulfillment_proof; + struct GNUNET_HashCode *policy_hash_codes; + size_t policy_hash_codes_count; + } policy_fulfillments; struct { @@ -889,7 +892,6 @@ struct TALER_EXCHANGEDB_DenominationKeyMetaData struct TALER_AgeMask age_mask; }; - /** * Signature of a function called with information about the exchange's * denomination keys. @@ -1446,36 +1448,28 @@ struct TALER_EXCHANGEDB_Deposit char *receiver_wire_account; /** - * Additional details for a policy relevant for this - * deposit operation, possibly NULL! + * Additional policy and its options, relevant for this deposit operation, + * possibly NULL! */ - json_t *policy_details; - bool has_policy_details; + json_t *policy_json; - /** - * If policy_details are present, the corresponding policy extension - * calculates a serial id under which the policy_details shall be stored in - * the policy_details table. + /* + * True if @e policy_json was provided */ - struct GNUNET_HashCode policy_serial_id; + bool has_policy; /** - * If policy_details are present, the corresponding policy extension can set - * a deadline for this policy. Can be "forever". + * Hash over the @e policy_options. Only filled if @e has_policy is true. + * Needed for the verification of the deposit's signature */ - struct GNUNET_TIME_Timestamp policy_deadline; - - /** - * The state that a _pending_ policy should be put into once the timeout triggers - */ - uint16_t policy_state_on_timeout; - + struct TALER_ExtensionPolicyHashP h_policy; /** - * Hash over the @e policy_details. Only filled if has_policy_details is - * true. + * If @e policy_json was present, the corresponding policy extension + * calculates these details. These will be persisted in the policy_details + * table. */ - struct TALER_ExtensionPolicyHashP h_policy; + struct TALER_PolicyDetails policy_details; /** * Time when this request was generated. Used, for example, to @@ -1549,8 +1543,8 @@ struct TALER_EXCHANGEDB_DepositListEntry struct TALER_PrivateContractHashP h_contract_terms; /** - * Hash over the poliy data for this deposit - * (remains unknown to the Exchange). + * 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; @@ -3342,6 +3336,39 @@ struct TALER_EXCHANGEDB_Plugin bool *conflict, bool *nonce_reuse); + /** + * Retrieve the details to a policy given by its hash_code + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @param hc Hash code that identifies the policy + * @param[out] detail retrieved policy details + * @return query execution status + */ + enum GNUNET_DB_QueryStatus + (*get_policy_details)( + void *cls, + const struct GNUNET_HashCode *hc, + struct TALER_PolicyDetails *detail); + + /** + * Persist the policy details that extends a deposit. The particular policy + * - referenced by details->hash_code - might already exist in the table, in + * which case the call will update the contents of the record with @e details + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @param details The parsed `struct TALER_PolicyDetails` according to the responsible policy extension. + * @param[out] policy_details_serial_id The ID of the entry in the policy_details table + * @param[out] accumulated_total The total amount accumulated in that policy + * @param[out] fulfillment_state The state of policy. If the state was Insufficient prior to the call and the provided deposit raises the accumulated_total above the commitment, it will be set to Ready. + * @return query execution status + */ + enum GNUNET_DB_QueryStatus + (*persist_policy_details)( + void *cls, + const struct TALER_PolicyDetails *details, + uint64_t *policy_details_serial_id, + struct TALER_Amount *accumulated_total, + enum TALER_PolicyFulfillmentState *fulfillment_state); /** * Perform deposit operation, checking for sufficient balance @@ -3351,6 +3378,7 @@ struct TALER_EXCHANGEDB_Plugin * @param deposit deposit operation details * @param known_coin_id row of the coin in the known_coins table * @param h_payto hash of the merchant's payto URI + * @param policy_details_serial_id (pointer to) the row ID of the policy details, maybe NULL * @param[in,out] exchange_timestamp time to use for the deposit (possibly updated) * @param[out] balance_ok set to true if the balance was sufficient * @param[out] in_conflict set to true if the deposit conflicted @@ -3362,6 +3390,7 @@ struct TALER_EXCHANGEDB_Plugin const struct TALER_EXCHANGEDB_Deposit *deposit, uint64_t known_coin_id, const struct TALER_PaytoHashP *h_payto, + uint64_t *policy_details_serial_id, struct GNUNET_TIME_Timestamp *exchange_timestamp, bool *balance_ok, bool *in_conflict); @@ -3389,6 +3418,18 @@ struct TALER_EXCHANGEDB_Plugin bool *zombie_required, bool *balance_ok); + /** + * Add a proof of fulfillment of an policy + * + * @param cls the plugin-specific state + * @param[in,out] fulfillment The proof of fulfillment and serial_ids of the policy_details along with their new state and potential new amounts. + * @return query execution status + */ + enum GNUNET_DB_QueryStatus + (*add_policy_fulfillment_proof)( + void *cls, + struct TALER_PolicyFulfillmentTransactionData *fulfillment); + /** * Check if the given @a nonce was properly locked to the given @a old_coin_pub. If so, check if we already |