gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] 04/31: use v1 contract structure for v0 internally


From: gnunet
Subject: [taler-merchant] 04/31: use v1 contract structure for v0 internally
Date: Thu, 18 Apr 2024 08:38:57 +0200

This is an automated email from the git hooks/post-receive script.

christian-blaettler pushed a commit to branch master
in repository merchant.

commit 6876380ed73fbe15090764691fa10165873aeae4
Author: Christian Blättler <blatc2@bfh.ch>
AuthorDate: Wed Mar 6 08:01:52 2024 +0100

    use v1 contract structure for v0 internally
---
 src/backend/taler-merchant-httpd_contract.c |  37 ++-
 src/backend/taler-merchant-httpd_contract.h | 402 +++++++++++++---------------
 2 files changed, 215 insertions(+), 224 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_contract.c 
b/src/backend/taler-merchant-httpd_contract.c
index 01186bef..35f1f134 100644
--- a/src/backend/taler-merchant-httpd_contract.c
+++ b/src/backend/taler-merchant-httpd_contract.c
@@ -25,10 +25,7 @@
 enum GNUNET_GenericReturnValue
 TMH_serialize_contract_v0 (const struct TALER_MerchantContract *contract,
                            const struct TMH_MerchantInstance *instance,
-                           const struct TMH_WireMethod *wm,
                            json_t *exchanges,
-                           json_t *products,
-                           struct TALER_Amount *max_fee,
                            json_t **out)
 {
   json_t *merchant;
@@ -79,30 +76,44 @@ TMH_serialize_contract_v0 (const struct 
TALER_MerchantContract *contract,
     }
   }
 
+  if (1 != contract->choices_len || NULL == contract->choices)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+
+  if (1 != contract->limits_len || NULL == contract->limits)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+
+  struct TALER_MerchantContractChoice *choice = contract->choices;
+
   *out = GNUNET_JSON_PACK (
     GNUNET_JSON_pack_string ("summary",
-                             contract->v0.summary),
+                             choice->summary),
     GNUNET_JSON_pack_allow_null (
       GNUNET_JSON_pack_object_incref ("summary_i18n",
-                                      contract->v0.summary_i18n)),
+                                      choice->summary_i18n)),
     GNUNET_JSON_pack_allow_null (
       GNUNET_JSON_pack_string ("public_reorder_url",
                                contract->public_reorder_url)),
     GNUNET_JSON_pack_allow_null (
       GNUNET_JSON_pack_string ("fulfillment_message",
-                               contract->v0.fulfillment_message)),
+                               choice->fulfillment_message)),
     GNUNET_JSON_pack_allow_null (
       GNUNET_JSON_pack_object_incref ("fulfillment_message_i18n",
-                                      contract->v0.fulfillment_message_i18n)),
+                                      choice->fulfillment_message_i18n)),
     GNUNET_JSON_pack_allow_null (
       GNUNET_JSON_pack_string ("fulfillment_url",
-                               contract->v0.fulfillment_url)),
+                               choice->fulfillment_url)),
     GNUNET_JSON_pack_array_incref ("products",
-                                   products),
+                                   choice->products),
     GNUNET_JSON_pack_data_auto ("h_wire",
-                                &wm->h_wire),
+                                &contract->limits->h_wire),
     GNUNET_JSON_pack_string ("wire_method",
-                             wm->wire_method),
+                             contract->limits->wire_method),
     GNUNET_JSON_pack_string ("order_id",
                              contract->order_id),
     GNUNET_JSON_pack_timestamp ("timestamp",
@@ -126,9 +137,9 @@ TMH_serialize_contract_v0 (const struct 
TALER_MerchantContract *contract,
     GNUNET_JSON_pack_array_incref ("exchanges",
                                    exchanges),
     TALER_JSON_pack_amount ("max_fee",
-                            max_fee),
+                            &contract->limits->max_fee),
     TALER_JSON_pack_amount ("amount",
-                            &contract->v0.brutto),
+                            &choice->price),
     GNUNET_JSON_pack_allow_null (
       GNUNET_JSON_pack_object_incref ("extra",
                                       (json_t *) contract->extra))
diff --git a/src/backend/taler-merchant-httpd_contract.h 
b/src/backend/taler-merchant-httpd_contract.h
index 5df47bc9..d4b174a9 100644
--- a/src/backend/taler-merchant-httpd_contract.h
+++ b/src/backend/taler-merchant-httpd_contract.h
@@ -40,58 +40,26 @@ enum TALER_MerchantContractVersion
 };
 
 /**
-* Contract fields specific to v0 contract format.
+* Possible token classes.
 */
-struct TALER_MerchantContractV0
+enum TALER_MerchantContractTokenClass
 {
-  /**
-  * 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;
+   * Token class subscription
+   */
+  TALER_MCTC_SUBSCRIPTION = 0,
 
   /**
-  * Maximum fee as given by the client request.
-  */
-  struct TALER_Amount max_fee;
+   * Token class discount
+   */
+  TALER_MCTC_DISCOUNT = 1
 };
 
 /**
 * Possible input types for the contract terms.
 */
-enum TALER_MerchantContractV1InputType
+enum TALER_MerchantContractInputType
 {
 
   /**
@@ -108,17 +76,17 @@ enum TALER_MerchantContractV1InputType
 /**
 * Contract input (part of the v1 contract terms).
 */
-struct TALER_MerchantContractV1Input
+struct TALER_MerchantContractInput
 {
   /**
   * Type of the input.
   */
-  enum TALER_MerchantContractV1InputType type;
+  enum TALER_MerchantContractInputType type;
 
   union
   {
     /**
-    * Coin-based input.
+    * Coin-based input (ration).
     */
     struct
     {
@@ -126,6 +94,11 @@ struct TALER_MerchantContractV1Input
       * Price to be paid.
       */
       struct TALER_Amount price;
+
+      /**
+      * Base URL of the ration authority.
+      */
+      const char *ration_authority_url;
     } coin;
 
     /**
@@ -134,10 +107,10 @@ struct TALER_MerchantContractV1Input
     struct
     {
       /**
-      * Hash over the public key used to sign the type of subscription
-      * token required.
+      * Label of the token authority in the 'token_authorities'
+      * array on the top-level.
       */
-      struct TALER_TokenFamilyPublicKeyHash h_issuer;
+      const char *token_authority_label;
 
       /**
       * Number of tokens of this type required. Defaults to one if the
@@ -151,7 +124,7 @@ struct TALER_MerchantContractV1Input
 /**
 * Possible output types for the contract terms.
 */
-enum TALER_MerchantContractV1OutputType
+enum TALER_MerchantContractOutputType
 {
 
   /**
@@ -171,32 +144,15 @@ enum TALER_MerchantContractV1OutputType
 
 };
 
-/**
-* Possible token output classes.
-*/
-enum TALER_MerchantContractV1OutputTokenClass
-{
-
-  /**
-   * Token class subscription
-   */
-  TALER_MCOTC_SUBSCRIPTION = 0,
-
-  /**
-   * Token class discount
-   */
-  TALER_MCOTC_DISCOUNT = 1
-};
-
 /**
 * Contract output (part of the v1 contract terms).
 */
-struct TALER_MerchantContractV1Output
+struct TALER_MerchantContractOutput
 {
   /**
   * Type of the output.
   */
-  enum TALER_MerchantContractV1OutputType type;
+  enum TALER_MerchantContractOutputType type;
 
   union
   {
@@ -232,78 +188,16 @@ struct TALER_MerchantContractV1Output
     struct
     {
       /**
-      * Label of the token authority in the 'token_authorities' array on the 
top-level.
+      * Label of the token authority in the 'token_authorities'
+      * array on the top-level.
       */
       const char *token_authority_label;
 
       /**
-      * Must a wallet understand this token type to process contracts that
-      * consume or yield it?
-      */
-      bool critical;
-
-      /**
-      * Class of token that will be yielded.
-      */
-      enum TALER_MerchantContractV1OutputTokenClass token_class;
-
-      /**
-      * Information about the class of token that will be yielded.
+      * Number of tokens of this type required. Defaults to one if the
+      * field is not provided.
       */
-      union
-      {
-        /**
-        * Subscription token.
-        */
-        struct
-        {
-          /**
-          * When does the subscription period start?
-          */
-          struct GNUNET_TIME_Absolute start_date;
-
-          /**
-          * When does the subscription period end?
-          */
-          struct GNUNET_TIME_Absolute end_date;
-
-          /**
-          * Array of domain names where this subscription can be safely used
-          * (e.g. the issuer warrants that these sites will re-issue tokens of
-          * this type if the respective contract says so). May contain "*" for
-          * any domain or subdomain.
-          */
-          const char **trusted_domains;
-
-          /**
-          * Length of the @e trusted_domains array.
-          */
-          unsigned int trusted_domains_len;
-        } subscription;
-
-        /**
-        * Discount token.
-        */
-        struct
-        {
-          /**
-          * Array of domain names where this discount token is intended to be
-          * used. May contain "*" for any domain or subdomain. Users should be
-          * warned about sites proposing to consume discount tokens of this
-          * type that are not in this list that the merchant is accepting a
-          * coupon from a competitor and thus may be attaching different
-          * semantics (like get 20% discount for my competitors 30% discount
-          * token).
-          */
-          const char **expected_domains;
-
-          /**
-          * Length of the @e expected_domains array.
-          */
-          unsigned int expected_domains_len;
-
-        } discount;
-      } details;
+      unsigned int number;
     } token;
   } details;
 };
@@ -311,7 +205,7 @@ struct TALER_MerchantContractV1Output
 /**
 * Contract choice (part of the v1 contract terms).
 */
-struct TALER_MerchantContractV1Choice
+struct TALER_MerchantContractChoice
 {
   /**
   * Summary of the order.
@@ -343,13 +237,21 @@ struct TALER_MerchantContractV1Choice
   /**
   * Array of products that are part of the purchase.
   */
-  const json_t *products;
+  json_t *products;
+
+  /**
+  * Price to be paid for the transaction. Could be 0. The price is in addition
+  * to other instruments, such as rations and tokens.
+  * The exchange will subtract deposit fees from that amount
+  * before transferring it to the merchant.
+  */
+  struct TALER_Amount price;
 
   /**
   * List of inputs the wallet must provision (all of them) to satisfy the
   * conditions for the contract.
   */
-  struct TALER_MerchantContractV1Input *inputs;
+  struct TALER_MerchantContractInput *inputs;
 
   /**
   * Length of the @e inputs array.
@@ -360,7 +262,7 @@ struct TALER_MerchantContractV1Choice
   * List of outputs the merchant promises to yield (all of them) once
   * the contract is paid.
   */
-  struct TALER_MerchantContractV1Output *ouputs;
+  struct TALER_MerchantContractOutput *ouputs;
 
   /**
   * Length of the @e outputs array.
@@ -369,71 +271,9 @@ struct TALER_MerchantContractV1Choice
 };
 
 /**
-* Contract fields specific to v1 contract format.
-*/
-struct TALER_MerchantContractV1
-{
-  /**
-  * Array of possible specific contracts the wallet/customer may choose
-  * from by selecting the respective index when signing the deposit
-  * confirmation.
-  */
-  struct TALER_MerchantContractV1Choice *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 };
-  */
-};
-
-/**
-* Struct to hold contract terms in v0 and v1 format. Shared fields are on the
-* top level, while version specific fields are in the respective sub-structs.
+* Struct to hold contract terms in v0 and v1 format. v0 contracts are mdoelled
+* as a v1 contract with a single choice and no inputs and outputs. Use the
+* version field to explicitly differentiate between v0 and v1 contracts.
 */
 struct TALER_MerchantContract
 {
@@ -500,19 +340,162 @@ struct TALER_MerchantContract
   const json_t *extra;
 
   /**
-  * Specified version of the order.
+  * Specified version of the contract.
   */
   enum TALER_MerchantContractVersion version;
 
   /**
-  * Contract information in v0 format.
+  * 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;
+
+  /**
+  * 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;
+
+    /**
+    * Must a wallet understand this token type to process contracts that
+    * consume or yield it?
+    */
+    bool critical;
+
+    /**
+    * Class of token the token.
+    */
+    enum TALER_MerchantContractTokenClass token_class;
+
+    /**
+    * Class-specific information about the token.
+    */
+    union
+    {
+      /**
+      * Subscription token.
+      */
+      struct
+      {
+        /**
+        * When does the subscription period start?
+        */
+        struct GNUNET_TIME_Absolute start_date;
+
+        /**
+        * When does the subscription period end?
+        */
+        struct GNUNET_TIME_Absolute end_date;
+
+        /**
+        * Array of domain names where this subscription can be safely used
+        * (e.g. the issuer warrants that these sites will re-issue tokens of
+        * this type if the respective contract says so). May contain "*" for
+        * any domain or subdomain.
+        */
+        const char **trusted_domains;
+
+        /**
+        * Length of the @e trusted_domains array.
+        */
+        unsigned int trusted_domains_len;
+      } subscription;
+
+      /**
+      * Discount token.
+      */
+      struct
+      {
+        /**
+        * Array of domain names where this discount token is intended to be
+        * used. May contain "*" for any domain or subdomain. Users should be
+        * warned about sites proposing to consume discount tokens of this
+        * type that are not in this list that the merchant is accepting a
+        * coupon from a competitor and thus may be attaching different
+        * semantics (like get 20% discount for my competitors 30% discount
+        * token).
+        */
+        const char **expected_domains;
+
+        /**
+        * Length of the @e expected_domains array.
+        */
+        unsigned int expected_domains_len;
+
+      } discount;
+    } details;
+
+  } *token_authorities;
+
+  /**
+  * Length of the @e token_authorities array.
+  */
+  unsigned int token_authorities_len;
+
+  /**
+  * Fee limits and wire account details by currency.
   */
-  struct TALER_MerchantContractV0 v0;
+  struct
+  {
+    /**
+    * Currency these limits are for.
+    */
+    char currency[TALER_CURRENCY_LEN];
+
+    /**
+    * The hash of the merchant instance's wire details.
+    */
+    struct TALER_MerchantWireHashP h_wire;
+
+    /**
+    * Wire transfer method identifier for the wire method associated with 
``h_wire``.
+    * The wallet may only select exchanges via a matching auditor if the
+    * exchange also supports this wire method.
+    * The wire transfer fees must be added based on this wire transfer method.
+    */
+    char *wire_method;
+
+    /**
+    * Maximum total deposit fee accepted by the merchant for this contract.
+    */
+    struct TALER_Amount max_fee;
+  } *limits;
 
   /**
-  * Order information passed in in v1 format.
+  * Length of the @e limits array;
   */
-  struct TALER_MerchantContractV1 v1;
+  unsigned int limits_len;
 };
 
 /**
@@ -532,10 +515,7 @@ TMH_serialize_contract (const struct 
TALER_MerchantContract *contract,
 enum GNUNET_GenericReturnValue
 TMH_serialize_contract_v0 (const struct TALER_MerchantContract *contract,
                            const struct TMH_MerchantInstance *instance,
-                           const struct TMH_WireMethod *wm,
                            json_t *exchanges,
-                           json_t *products,
-                           struct TALER_Amount *max_fee,
                            json_t **out);
 
 enum GNUNET_GenericReturnValue

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]