From 48ebda9a68b01780cfb7de802f4eee3dbe708e80 Mon Sep 17 00:00:00 2001 From: Christian Blättler Date: Thu, 29 Feb 2024 15:21:08 +0100 Subject: serialize v0 contract --- .../taler-merchant-httpd_private-post-orders.c | 340 +-------------------- 1 file changed, 13 insertions(+), 327 deletions(-) (limited to 'src/backend/taler-merchant-httpd_private-post-orders.c') diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index f886d9f2..1440dcc4 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -226,201 +226,7 @@ struct OrderContext */ struct { - /** - * Specified version of the order. - */ - enum TALER_MerchantContractVersion version; - - /** - * URL where the same contract could be ordered again (if available). - */ - const char *public_reorder_url; - - /** - * Our order ID. - */ - const char *order_id; - - /** - * Merchant base URL. - */ - char *merchant_base_url; - - /** - * TODO: Maybe remove this and set it from settings where we serialize - * the order to JSON? - * - * Merchant's public key - */ - struct TALER_MerchantPublicKeyP merchant_pub; - - /** - * TODO: Maybe remove this and set it from settings where we serialize - * the order to JSON? - * - * Information like name, website, email, etc. about the merchant. - */ - json_t *merchant; - - /** - * Timestamp of the order. - */ - struct GNUNET_TIME_Timestamp timestamp; - - /** - * Deadline for refunds. - */ - struct GNUNET_TIME_Timestamp refund_deadline; - - /** - * Specifies for how long the wallet should try to get an - * automatic refund for the purchase. - */ - struct GNUNET_TIME_Relative auto_refund; - - /** - * Payment deadline. - */ - struct GNUNET_TIME_Timestamp pay_deadline; - - /** - * Wire transfer deadline. - */ - struct GNUNET_TIME_Timestamp wire_deadline; - - /** - * Delivery date. - */ - struct GNUNET_TIME_Timestamp delivery_date; - - /** - * Delivery location. - */ - json_t *delivery_location; - - /** - * Nonce generated by the wallet and echoed by the merchant - * in this field when the proposal is generated. - */ - const char *nonce; - - /** - * Extra data that is only interpreted by the merchant frontend. - */ - const json_t *extra; - - /** - * Order information in v0 format. - */ - struct - { - /** - * Summary of the order. - */ - const char *summary; - - /** - * Internationalized summary. - */ - json_t *summary_i18n; - - /** - * URL that will show that the order was successful - * after it has been paid for. - */ - const char *fulfillment_url; - - /** - * Message shown to the customer after paying for the order. - * Either fulfillment_url or fulfillment_message must be specified. - */ - const char *fulfillment_message; - - /** - * Map from IETF BCP 47 language tags to localized fulfillment messages. - */ - json_t *fulfillment_message_i18n; - - /** - * Array of products that are part of the purchase. - */ - const json_t *products; - - /** - * Gross amount value of the contract. Used to - * compute @e max_stefan_fee. - */ - struct TALER_Amount brutto; - - /** - * Maximum fee as given by the client request. - */ - struct TALER_Amount max_fee; - } v0; - - /** - * Order information passed in in v1 format. - */ - struct - { - /** - * Array of possible specific contracts the wallet/customer may choose - * from by selecting the respective index when signing the deposit - * confirmation. - */ - struct TALER_MerchantContractChoice *choices; - - /** - * Length of the @e choices array. - */ - unsigned int choices_len; - - /** - * TODO: This was moved out a level: Change design document according to this. - * Array of token authorities. - */ - struct - { - /** - * Label of the token authority. - */ - const char *label; - - /** - * Human-readable description of the semantics of the tokens issued by - * this authority. - */ - const char *summary; - - /** - * Map from IETF BCP 47 language tags to localized summaries. - */ - json_t *summary_i18n; - - /** - * Public key used to validate tokens signed by this authority. - */ - struct TALER_TokenFamilyPublicKey key; - - /** - * When will tokens signed by this key expire? - */ - struct GNUNET_TIME_Timestamp token_expiration; - - } *token_authorities; - - /** - * Length of the @e token_authorities array. - */ - unsigned int token_authorities_len; - - /** - * TODO: Model this - * Fee limits and wire account details by currency. - * limits: { [currency:string] : CurrencyLimit }; - */ - } v1; - + struct TALER_MerchantContract contract; } parse_order; /** @@ -677,11 +483,6 @@ clean_order (void *cls) json_decref (oc->set_exchanges.exchanges); oc->set_exchanges.exchanges = NULL; } - if (NULL != oc->parse_order.merchant) - { - json_decref (oc->parse_order.merchant); - oc->parse_order.merchant = NULL; - } if (NULL != oc->parse_order.fulfillment_message_i18n) { json_decref (oc->parse_order.fulfillment_message_i18n); @@ -1336,86 +1137,18 @@ get_exchange_keys (void *cls, static void serialize_order (struct OrderContext *oc) { - oc->serialize_order.contract = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("summary", - oc->parse_order.summary), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_object_incref ("summary_i18n", - oc->parse_order.summary_i18n)), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("public_reorder_url", - oc->parse_order.public_reorder_url)), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("fulfillment_message", - oc->parse_order.fulfillment_message)), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_object_incref ("fulfillment_message_i18n", - oc->parse_order.fulfillment_message_i18n)), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("fulfillment_url", - oc->parse_order.fulfillment_url)), - GNUNET_JSON_pack_array_incref ("products", - oc->merge_inventory.products), - GNUNET_JSON_pack_data_auto ("h_wire", - &oc->add_payment_details.wm->h_wire), - GNUNET_JSON_pack_string ("wire_method", - oc->add_payment_details.wm->wire_method), - GNUNET_JSON_pack_string ("order_id", - oc->parse_order.order_id), - GNUNET_JSON_pack_timestamp ("timestamp", - oc->parse_order.timestamp), - GNUNET_JSON_pack_timestamp ("pay_deadline", - oc->parse_order.pay_deadline), - GNUNET_JSON_pack_timestamp ("wire_transfer_deadline", - oc->parse_order.wire_deadline), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_timestamp ("delivery_date", - oc->parse_order.delivery_date)), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_object_incref ("delivery_location", - oc->parse_order.delivery_location)), - GNUNET_JSON_pack_string ("merchant_base_url", - oc->parse_order.merchant_base_url), - GNUNET_JSON_pack_object_incref ("merchant", - oc->parse_order.merchant), - GNUNET_JSON_pack_data_auto ("merchant_pub", - &oc->hc->instance->merchant_pub), - GNUNET_JSON_pack_array_incref ("exchanges", - oc->set_exchanges.exchanges), - TALER_JSON_pack_amount ("max_fee", - &oc->set_max_fee.max_fee), - TALER_JSON_pack_amount ("amount", - &oc->parse_order.brutto), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_object_incref ("extra", - (json_t *) oc->parse_order.extra)) - ); - - /* Pack does not work here, because it doesn't set zero-values for timestamps */ - GNUNET_assert (0 == - json_object_set_new (oc->serialize_order.contract, - "refund_deadline", - GNUNET_JSON_from_timestamp ( - oc->parse_order.refund_deadline))); - GNUNET_log ( - GNUNET_ERROR_TYPE_INFO, - "Refund deadline for contact is %llu\n", - (unsigned long long) oc->parse_order.refund_deadline.abs_time.abs_value_us); - GNUNET_log ( - GNUNET_ERROR_TYPE_INFO, - "Wallet timestamp for contact is %llu\n", - (unsigned long long) oc->parse_order.timestamp.abs_time.abs_value_us); - - /* Pack does not work here, because it sets zero-values for relative times */ - /* auto_refund should only be set if it is not 0 */ - if (! GNUNET_TIME_relative_is_zero (oc->parse_order.auto_refund)) - { - GNUNET_assert (0 == - json_object_set_new (oc->serialize_order.contract, - "auto_refund", - GNUNET_JSON_from_time_rel ( - oc->parse_order.auto_refund))); - } + const struct TALER_MERCHANTDB_InstanceSettings *settings = + &oc->hc->instance->settings; + + ret = TMH_serialize_contract_v0( + oc->parse_order.contract, + oc->hc->instance, + oc->add_payment_details.wm, + oc->set_exchanges.exchanges, + oc->merge_inventory.products, + oc->set_max_fee.max_fee, + oc->serialize_order.contract + ); oc->phase++; } @@ -1929,53 +1662,6 @@ parse_order_v0 (struct OrderContext *oc) return; } - { - oc->parse_order.merchant = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("name", - settings->name), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("website", - settings->website)), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("email", - settings->email)), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("logo", - settings->logo))); - GNUNET_assert (NULL != oc->parse_order.merchant); - { - json_t *loca; - - /* Handle merchant address */ - loca = settings->address; - if (NULL != loca) - { - loca = json_deep_copy (loca); - GNUNET_assert (NULL != loca); - GNUNET_assert (0 == - json_object_set_new (oc->parse_order.merchant, - "address", - loca)); - } - } - { - json_t *juri; - - /* Handle merchant jurisdiction */ - juri = settings->jurisdiction; - if (NULL != juri) - { - juri = json_deep_copy (juri); - GNUNET_assert (NULL != juri); - GNUNET_assert (0 == - json_object_set_new (oc->parse_order.merchant, - "jurisdiction", - juri)); - } - } - } - - oc->parse_order.merchant_pub = oc->hc->instance->merchant_pub; if ( (NULL != oc->parse_order.delivery_location) && (! TMH_location_object_valid (oc->parse_order.delivery_location)) ) { -- cgit v1.2.3