diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_batch-deposit.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_batch-deposit.c | 91 |
1 files changed, 73 insertions, 18 deletions
diff --git a/src/exchange/taler-exchange-httpd_batch-deposit.c b/src/exchange/taler-exchange-httpd_batch-deposit.c index d4a9666e..14267e2a 100644 --- a/src/exchange/taler-exchange-httpd_batch-deposit.c +++ b/src/exchange/taler-exchange-httpd_batch-deposit.c @@ -90,8 +90,12 @@ struct BatchDepositContext * Additional details for policy relevant for this * deposit operation, possibly NULL! */ - json_t *policy_details; - bool has_policy_details; + json_t *policy_json; + + /** + * Will be true if policy_json were provided + */ + bool has_policy; /** * Hash over @e policy_details, might be all zero; @@ -99,6 +103,19 @@ struct BatchDepositContext 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; + + /** + * When @e policy_details are persisted, this contains the id of the record + * in the policy_details table. + */ + uint64_t policy_details_serial_id; + + /** * 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 @@ -174,7 +191,7 @@ again: &TEH_keys_exchange_sign_, &bdc->h_contract_terms, &bdc->h_wire, - bdc->has_policy_details ? &bdc->h_policy : NULL, + bdc->has_policy ? &bdc->h_policy : NULL, bdc->exchange_timestamp, bdc->wire_deadline, bdc->refund_deadline, @@ -247,6 +264,21 @@ batch_deposit_transaction (void *cls, bool balance_ok; bool in_conflict; + + /* If the deposit has a policy associated to it, persist it. This will + * insert or update the record. */ + if (dc->has_policy) + { + 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; + } + + /* deposit the individutal coins */ for (unsigned int i = 0; i<dc->num_coins; i++) { const struct TALER_EXCHANGEDB_Deposit *deposit = &dc->deposits[i]; @@ -258,13 +290,19 @@ batch_deposit_transaction (void *cls, mhd_ret); if (qs < 0) return qs; - qs = TEH_plugin->do_deposit (TEH_plugin->cls, - deposit, - known_coin_id, - &dc->h_payto, - &dc->exchange_timestamp, - &balance_ok, - &in_conflict); + + qs = TEH_plugin->do_deposit ( + TEH_plugin->cls, + deposit, + known_coin_id, + &dc->h_payto, + (dc->has_policy) + ? &dc->policy_details_serial_id + : NULL, + &dc->exchange_timestamp, + &balance_ok, + &in_conflict); + if (qs < 0) { if (GNUNET_DB_STATUS_SOFT_ERROR == qs) @@ -474,7 +512,7 @@ parse_coin (struct MHD_Connection *connection, &dc->h_wire, &dc->h_contract_terms, &deposit->coin.h_age_commitment, - dc->has_policy_details ? &dc->h_policy : + dc->has_policy ? &dc->h_policy : NULL, &deposit->coin.denom_pub_hash, dc->timestamp, @@ -501,7 +539,7 @@ parse_coin (struct MHD_Connection *connection, 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_details = dc->policy_details; + deposit->policy_json = dc->policy_json; deposit->timestamp = dc->timestamp; deposit->refund_deadline = dc->refund_deadline; deposit->wire_deadline = dc->wire_deadline; @@ -518,7 +556,7 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc, struct BatchDepositContext dc; json_t *coins; bool no_refund_deadline = true; - bool no_policy_details = true; + bool no_policy_json = true; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("merchant_payto_uri", &dc.payto_uri), @@ -532,8 +570,8 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc, &coins), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_json ("policy", - &dc.policy_details), - &no_policy_details), + &dc.policy_json), + &no_policy_json), GNUNET_JSON_spec_timestamp ("timestamp", &dc.timestamp), GNUNET_JSON_spec_mark_optional ( @@ -564,7 +602,7 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc, return MHD_YES; /* failure */ } - dc.has_policy_details = ! no_policy_details; + dc.has_policy = ! no_policy_json; /* validate merchant's wire details (as far as we can) */ { @@ -610,11 +648,26 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc, TALER_merchant_wire_signature_hash (dc.payto_uri, &dc.wire_salt, &dc.h_wire); - if (dc.has_policy_details) + + /* handle policy, if present */ + if (dc.has_policy) { - TALER_deposit_policy_hash (dc.policy_details, + const char *error_hint = NULL; + + if (GNUNET_OK != + TALER_extensions_create_policy_details ( + dc.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 (dc.policy_json, &dc.h_policy); } + dc.num_coins = json_array_size (coins); if (0 == dc.num_coins) { @@ -651,6 +704,8 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc, GNUNET_JSON_parse_free (spec); return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } + + /* FIXME: sum all contributions for the policy_details.accumulated_total */ } dc.exchange_timestamp = GNUNET_TIME_timestamp_get (); |