diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-05-30 23:09:34 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-05-30 23:09:34 +0200 |
commit | 1ea6a4f5a191a721ca76ae42e9a0e9ec1b3ad807 (patch) | |
tree | d905155fadb03c1cedbb1f919687ad82dae01b14 /src/testing/testing_api_cmd_get_instance.c | |
parent | 44a32b527ec1570bd1a6fd1b0b059dbef818e652 (diff) | |
download | merchant-1ea6a4f5a191a721ca76ae42e9a0e9ec1b3ad807.tar.gz merchant-1ea6a4f5a191a721ca76ae42e9a0e9ec1b3ad807.tar.bz2 merchant-1ea6a4f5a191a721ca76ae42e9a0e9ec1b3ad807.zip |
add new commands for merchant instance account CRUD API
Diffstat (limited to 'src/testing/testing_api_cmd_get_instance.c')
-rw-r--r-- | src/testing/testing_api_cmd_get_instance.c | 125 |
1 files changed, 123 insertions, 2 deletions
diff --git a/src/testing/testing_api_cmd_get_instance.c b/src/testing/testing_api_cmd_get_instance.c index be492009..4491e8b8 100644 --- a/src/testing/testing_api_cmd_get_instance.c +++ b/src/testing/testing_api_cmd_get_instance.c @@ -29,6 +29,39 @@ /** + * Details about a merchant's bank account. + */ +struct MERCHANT_Account +{ + /** + * salt used to compute h_wire + */ + struct TALER_WireSaltP salt; + + /** + * payto:// URI of the account. + */ + char *payto_uri; + + /** + * Credit facade URL of the account. + */ + char *credit_facade_url; + + /** + * Hash of @e payto_uri and @e salt. + */ + struct TALER_MerchantWireHashP h_wire; + + /** + * true if the account is active, + * false if it is historic. + */ + bool active; +}; + + +/** * State of a "GET instance" CMD. */ struct GetInstanceState @@ -80,6 +113,17 @@ struct GetInstanceState const char **inactive_accounts; /** + * Length of the @e accounts array. + */ + unsigned int accounts_length; + + /** + * Array of @e accounts_length bank accounts of the merchant instance as + * returned by the request. + */ + struct MERCHANT_Account *accounts; + + /** * The length of @e inactive_accounts. */ unsigned int inactive_accounts_length; @@ -126,6 +170,22 @@ get_instance_cb (void *cls, { const struct TALER_MERCHANT_InstanceDetails *details = &igr->details.ok.details; + + gis->accounts_length = igr->details.ok.accounts_length; + gis->accounts = GNUNET_new_array (gis->accounts_length, + struct MERCHANT_Account); + for (unsigned int i = 0; i<gis->accounts_length; i++) + { + const struct TALER_MERCHANT_Account *src = &igr->details.ok.accounts[i]; + struct MERCHANT_Account *dst = &gis->accounts[i]; + + dst->salt = src->salt; + dst->payto_uri = GNUNET_strdup (src->payto_uri); + if (NULL != src->credit_facade_url) + dst->credit_facade_url = GNUNET_strdup (src->credit_facade_url); + dst->h_wire = src->h_wire; + dst->active = src->active; + } { const char **name; @@ -383,10 +443,69 @@ get_instance_cleanup (void *cls, "GET /instances/$ID operation did not complete\n"); TALER_MERCHANT_instance_get_cancel (gis->igh); } + for (unsigned int i = 0; i<gis->accounts_length; i++) + { + struct MERCHANT_Account *acc = &gis->accounts[i]; + + GNUNET_free (acc->payto_uri); + GNUNET_free (acc->credit_facade_url); + } + GNUNET_free (gis->accounts); GNUNET_free (gis); } +/** + * Offers information from the GET /instance/$ID CMD state to other + * commands. + * + * @param cls closure + * @param[out] ret result (could be anything) + * @param trait name of the trait + * @param index index number of the object to extract. + * @return #GNUNET_OK on success + */ +static enum GNUNET_GenericReturnValue +get_instance_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct GetInstanceState *pps = cls; + + if (index < pps->accounts_length) + { + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_merchant_base_url (&pps->merchant_url), + TALER_TESTING_make_trait_h_wires ( + index, + &pps->accounts[index].h_wire), + TALER_TESTING_make_trait_payto_uris ( + index, + (const char **) &pps->accounts[index].payto_uri), + TALER_TESTING_trait_end (), + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); + } + else + { + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_merchant_base_url (&pps->merchant_url), + TALER_TESTING_trait_end (), + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); + } +} + + struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_instance (const char *label, const char *merchant_url, @@ -407,7 +526,8 @@ TALER_TESTING_cmd_merchant_get_instance (const char *label, .cls = gis, .label = label, .run = &get_instance_run, - .cleanup = &get_instance_cleanup + .cleanup = &get_instance_cleanup, + .traits = &get_instance_traits }; return cmd; @@ -443,7 +563,8 @@ TALER_TESTING_cmd_merchant_get_instance2 (const char *label, .cls = gis, .label = label, .run = &get_instance_run, - .cleanup = &get_instance_cleanup + .cleanup = &get_instance_cleanup, + .traits = &get_instance_traits }; return cmd; |