From 741831e87b3b189d3f75bdd9fa2ccc9a8d2ba8e2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 17 Nov 2022 13:28:15 +0100 Subject: bank API refactoring for #7276 (incomplete) --- src/include/taler_bank_service.h | 167 +++++++++++++++++++++++++++++---------- 1 file changed, 125 insertions(+), 42 deletions(-) (limited to 'src/include') diff --git a/src/include/taler_bank_service.h b/src/include/taler_bank_service.h index bb7f3d33b..7b26bceab 100644 --- a/src/include/taler_bank_service.h +++ b/src/include/taler_bank_service.h @@ -260,6 +260,11 @@ struct TALER_BANK_CreditHistoryHandle; */ struct TALER_BANK_CreditDetails { + /** + * Serial ID of the wire transfer. + */ + uint64_t serial_id; + /** * Amount that was transferred */ @@ -271,49 +276,85 @@ struct TALER_BANK_CreditDetails struct GNUNET_TIME_Timestamp execution_date; /** - * Reserve public key encoded in the wire - * transfer subject. + * Reserve public key encoded in the wire transfer subject. */ struct TALER_ReservePublicKeyP reserve_pub; /** - * payto://-URL of the source account that - * send the funds. + * payto://-URL of the source account that send the funds. */ const char *debit_account_uri; /** - * payto://-URL of the target account that - * received the funds. + * payto://-URL of the target account that received the funds. */ const char *credit_account_uri; }; +/** + * Response details for a history request. + */ +struct TALER_BANK_CreditHistoryResponse +{ + + /** + * HTTP status. Note that #MHD_HTTP_OK and #MHD_HTTP_NO_CONTENT are both + * successful replies, but @e details will only contain @e success information + * if this is set to #MHD_HTTP_OK. + */ + unsigned int http_status; + + /** + * Taler error code, #TALER_EC_NONE on success. + */ + enum TALER_ErrorCode ec; + + /** + * Full response, NULL if body was not in JSON format. + */ + const json_t *response; + + /** + * Details returned depending on the @e http_status. + */ + union + { + + /** + * Details if status was #MHD_HTTP_OK + */ + struct + { + + /** + * Array of transactions recevied. + */ + const struct TALER_BANK_CreditDetails *details; + + /** + * Length of the @e details array. + */ + unsigned int details_length; + + } success; + + } details; + +}; + + /** * Callbacks of this type are used to serve the result of asking * the bank for the credit transaction history. * * @param cls closure - * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request - * 0 if the bank's reply is bogus (fails to follow the protocol), - * #MHD_HTTP_NO_CONTENT if there are no more results; on success the - * last callback is always of this status (even if `abs(num_results)` were - * already returned). - * @param ec detailed error code - * @param serial_id monotonically increasing counter corresponding to the transaction - * @param details details about the wire transfer - * @param json detailed response from the HTTPD, or NULL if reply was not in JSON - * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration + * @param reply details about the response */ -typedef enum GNUNET_GenericReturnValue +typedef void (*TALER_BANK_CreditHistoryCallback)( void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - uint64_t serial_id, - const struct TALER_BANK_CreditDetails *details, - const json_t *json); + const struct TALER_BANK_CreditHistoryResponse *reply); /** @@ -369,6 +410,11 @@ struct TALER_BANK_DebitHistoryHandle; */ struct TALER_BANK_DebitDetails { + /** + * Serial ID of the wire transfer. + */ + uint64_t serial_id; + /** * Amount that was transferred */ @@ -390,44 +436,81 @@ struct TALER_BANK_DebitDetails const char *exchange_base_url; /** - * payto://-URI of the source account that - * send the funds. + * payto://-URI of the source account that send the funds. */ const char *debit_account_uri; /** - * payto://-URI of the target account that - * received the funds. + * payto://-URI of the target account that received the funds. */ const char *credit_account_uri; }; +/** + * Response details for a history request. + */ +struct TALER_BANK_DebitHistoryResponse +{ + + /** + * HTTP status. Note that #MHD_HTTP_OK and #MHD_HTTP_NO_CONTENT are both + * successful replies, but @e details will only contain @e success information + * if this is set to #MHD_HTTP_OK. + */ + unsigned int http_status; + + /** + * Taler error code, #TALER_EC_NONE on success. + */ + enum TALER_ErrorCode ec; + + /** + * Full response, NULL if body was not in JSON format. + */ + const json_t *response; + + /** + * Details returned depending on the @e http_status. + */ + union + { + + /** + * Details if status was #MHD_HTTP_OK + */ + struct + { + + /** + * Array of transactions initiated. + */ + const struct TALER_BANK_DebitDetails *details; + + /** + * Length of the @e details array. + */ + unsigned int details_length; + + } success; + + } details; + +}; + + /** * Callbacks of this type are used to serve the result of asking * the bank for the debit transaction history. * * @param cls closure - * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request - * 0 if the bank's reply is bogus (fails to follow the protocol), - * #MHD_HTTP_NO_CONTENT if there are no more results; on success the - * last callback is always of this status (even if `abs(num_results)` were - * already returned). - * @param ec detailed error code - * @param serial_id monotonically increasing counter corresponding to the transaction - * @param details details about the wire transfer - * @param json detailed response from the HTTPD, or NULL if reply was not in JSON - * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration + * @param reply details about the response */ -typedef enum GNUNET_GenericReturnValue +typedef void (*TALER_BANK_DebitHistoryCallback)( void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - uint64_t serial_id, - const struct TALER_BANK_DebitDetails *details, - const json_t *json); + const struct TALER_BANK_DebitHistoryResponse *reply); /** -- cgit v1.2.3