diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_deposit.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_deposit.c | 100 |
1 files changed, 60 insertions, 40 deletions
diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c index 12741c6b..f44775c0 100644 --- a/src/exchange/taler-exchange-httpd_deposit.c +++ b/src/exchange/taler-exchange-httpd_deposit.c @@ -132,6 +132,12 @@ struct DepositContext */ uint64_t known_coin_id; + /** + * When deposit->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; + }; @@ -165,14 +171,36 @@ deposit_transaction (void *cls, if (qs < 0) return qs; + /* If the deposit has a policy associated to it, persist it. This will + * insert or update the record. */ + if (dc->deposit->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 ? */ + + if (qs < 0) + return qs; + } + + qs = TEH_plugin->do_deposit ( + TEH_plugin->cls, + dc->deposit, + dc->known_coin_id, + &dc->h_payto, + (dc->deposit->has_policy) + ? &dc->policy_details_serial_id + : NULL, + &dc->exchange_timestamp, + &balance_ok, + &in_conflict); - qs = TEH_plugin->do_deposit (TEH_plugin->cls, - dc->deposit, - dc->known_coin_id, - &dc->h_payto, - &dc->exchange_timestamp, - &balance_ok, - &in_conflict); if (qs < 0) { if (GNUNET_DB_STATUS_SOFT_ERROR == qs) @@ -219,7 +247,7 @@ TEH_handler_deposit (struct MHD_Connection *connection, struct TALER_EXCHANGEDB_Deposit deposit; const char *payto_uri; struct TALER_ExtensionPolicyHashP *ph_policy = NULL; - bool no_policy_details; + bool no_policy_json; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("merchant_payto_uri", &payto_uri), @@ -255,8 +283,8 @@ TEH_handler_deposit (struct MHD_Connection *connection, &deposit.wire_deadline), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_json ("policy", - &deposit.policy_details), - &no_policy_details), + &deposit.policy_json), + &no_policy_json), GNUNET_JSON_spec_end () }; struct TALER_MerchantWireHashP h_wire; @@ -284,7 +312,7 @@ TEH_handler_deposit (struct MHD_Connection *connection, } /* set the state of the policy presence in the deposit struct */ - deposit.has_policy_details = ! no_policy_details; + deposit.has_policy = ! no_policy_json; /* validate merchant's wire details (as far as we can) */ { @@ -333,28 +361,6 @@ TEH_handler_deposit (struct MHD_Connection *connection, &h_wire); dc.deposit = &deposit; - /* Check policy */ - if (deposit.has_policy_details) - { - const char *error_hint = NULL; - enum TALER_PolicyFulfilmentState state_on_timeout; - - if (GNUNET_OK != - TALER_extensions_extract_meta_data_from_policy_details ( - deposit.policy_details, - &deposit.policy_serial_id, - &deposit.policy_deadline, - &state_on_timeout, - &error_hint)) - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED, - error_hint); - - GNUNET_assert (TALER_PolicyFulfilmentStateMax >= state_on_timeout); - deposit.policy_state_on_timeout = state_on_timeout; - } - /* new deposit */ dc.exchange_timestamp = GNUNET_TIME_timestamp_get (); /* check denomination exists and is valid */ @@ -420,13 +426,6 @@ TEH_handler_deposit (struct MHD_Connection *connection, NULL); } - if (deposit.has_policy_details) - { - TALER_deposit_policy_hash (deposit.policy_details, - &deposit.h_policy); - ph_policy = &deposit.h_policy; - } - deposit.deposit_fee = dk->meta.fees.deposit; /* check coin signature */ switch (dk->denom_pub.cipher) @@ -463,6 +462,27 @@ TEH_handler_deposit (struct MHD_Connection *connection, NULL); } + /* Check policy input and create policy details */ + if (deposit.has_policy) + { + const char *error_hint = NULL; + + if (GNUNET_OK != + TALER_extensions_create_policy_details ( + deposit.policy_json, + &deposit.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; + } + + TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++; if (GNUNET_OK != TALER_wallet_deposit_verify (&deposit.amount_with_fee, |