commit 93810883d000ecb01f2db4bd33a643dc5d150e9c
parent 39caed545966566f8934780682ddc39643e0ac5b
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 28 Mar 2026 22:16:16 +0100
return accounts from GET /management/instances/ endpoint
Diffstat:
2 files changed, 137 insertions(+), 6 deletions(-)
diff --git a/src/include/taler/taler-merchant/get-management-instances-INSTANCE.h b/src/include/taler/taler-merchant/get-management-instances-INSTANCE.h
@@ -32,6 +32,41 @@ struct TALER_MERCHANT_GetManagementInstanceHandle;
/**
+ * Account details for a merchant wire account
+ * as returned by GET /management/instances/$INSTANCE.
+ */
+struct TALER_MERCHANT_ManagementAccountEntry
+{
+
+ /**
+ * Full payto URI of the account.
+ */
+ struct TALER_FullPayto payto_uri;
+
+ /**
+ * URL of the credit facade (optional, may be NULL).
+ */
+ const char *credit_facade_url;
+
+ /**
+ * Hash of the wire details.
+ */
+ struct TALER_MerchantWireHashP h_wire;
+
+ /**
+ * Salt used to compute @e h_wire.
+ */
+ struct TALER_WireSaltP salt;
+
+ /**
+ * True if the account is active.
+ */
+ bool active;
+
+};
+
+
+/**
* Detailed information about a merchant instance.
*/
struct TALER_MERCHANT_GetManagementInstanceDetails
@@ -145,6 +180,16 @@ struct TALER_MERCHANT_GetManagementInstanceResponse
*/
struct TALER_MERCHANT_GetManagementInstanceDetails details;
+ /**
+ * Number of accounts in @a accounts.
+ */
+ unsigned int accounts_length;
+
+ /**
+ * Array of account entries.
+ */
+ const struct TALER_MERCHANT_ManagementAccountEntry *accounts;
+
} ok;
} details;
diff --git a/src/lib/merchant_api_get-management-instances-INSTANCE.c b/src/lib/merchant_api_get-management-instances-INSTANCE.c
@@ -15,7 +15,7 @@
<http://www.gnu.org/licenses/>
*/
/**
- * @file merchant_api_get-management-instances-INSTANCE-new.c
+ * @file merchant_api_get-management-instances-INSTANCE.c
* @brief Implementation of the GET /management/instances/$INSTANCE request
* @author Christian Grothoff
*/
@@ -31,6 +31,12 @@
/**
+ * Maximum number of accounts permitted.
+ */
+#define MAX_ACCOUNTS 1024
+
+
+/**
* Handle for a GET /management/instances/$INSTANCE operation.
*/
struct TALER_MERCHANT_GetManagementInstanceHandle
@@ -73,6 +79,75 @@ struct TALER_MERCHANT_GetManagementInstanceHandle
/**
+ * Parse account information from @a ia.
+ *
+ * @param ia JSON array (or NULL!) with account data
+ * @param[in,out] igr partially filled response
+ * @param gmi operation handle
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_accounts (const json_t *ia,
+ struct TALER_MERCHANT_GetManagementInstanceResponse *igr,
+ struct TALER_MERCHANT_GetManagementInstanceHandle *gmi)
+{
+ unsigned int accounts_len = (unsigned int) json_array_size (ia);
+
+ if ( (json_array_size (ia) != (size_t) accounts_len) ||
+ (accounts_len > MAX_ACCOUNTS) )
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ {
+ struct TALER_MERCHANT_ManagementAccountEntry accounts[
+ GNUNET_NZL (accounts_len)];
+ size_t index;
+ json_t *value;
+
+ memset (accounts,
+ 0,
+ sizeof (accounts));
+ json_array_foreach (ia, index, value) {
+ struct TALER_MERCHANT_ManagementAccountEntry *ae =
+ &accounts[index];
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_full_payto_uri ("payto_uri",
+ &ae->payto_uri),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string (
+ "credit_facade_url",
+ &ae->credit_facade_url),
+ NULL),
+ GNUNET_JSON_spec_fixed_auto ("h_wire",
+ &ae->h_wire),
+ GNUNET_JSON_spec_fixed_auto ("salt",
+ &ae->salt),
+ GNUNET_JSON_spec_bool ("active",
+ &ae->active),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (value,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ igr->details.ok.accounts_length = accounts_len;
+ igr->details.ok.accounts = accounts;
+ gmi->cb (gmi->cb_cls,
+ igr);
+ gmi->cb = NULL;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
* Function called when we're done processing the
* HTTP GET /management/instances/$INSTANCE request.
*
@@ -102,6 +177,7 @@ handle_get_instance_finished (void *cls,
{
const json_t *address;
const json_t *jurisdiction;
+ const json_t *accounts;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string (
"name",
@@ -164,6 +240,9 @@ handle_get_instance_finished (void *cls,
"logo",
&igr.details.ok.details.logo),
NULL),
+ GNUNET_JSON_spec_array_const (
+ "accounts",
+ &accounts),
GNUNET_JSON_spec_end ()
};
@@ -179,10 +258,17 @@ handle_get_instance_finished (void *cls,
}
igr.details.ok.details.address = address;
igr.details.ok.details.jurisdiction = jurisdiction;
- gmi->cb (gmi->cb_cls,
- &igr);
- TALER_MERCHANT_get_management_instance_cancel (gmi);
- return;
+ if (GNUNET_OK ==
+ parse_accounts (accounts,
+ &igr,
+ gmi))
+ {
+ TALER_MERCHANT_get_management_instance_cancel (gmi);
+ return;
+ }
+ igr.hr.http_status = 0;
+ igr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
}
case MHD_HTTP_UNAUTHORIZED:
igr.hr.ec = TALER_JSON_get_error_code (json);
@@ -283,4 +369,4 @@ TALER_MERCHANT_get_management_instance_cancel (
}
-/* end of merchant_api_get-management-instances-INSTANCE-new.c */
+/* end of merchant_api_get-management-instances-INSTANCE.c */