taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 72decf7c89cf8c8ed1c5d7d169203a5281f2cf64
parent 2ecdf4ae9327674d48009e918031b2733504f0a4
Author: Marc Stibane <marc@taler.net>
Date:   Mon, 20 Jul 2026 10:24:16 +0200

simplify WalletBackendFormattedRequest

Diffstat:
MTalerWallet1/Backend/WalletBackendRequest.swift | 16++++++++--------
MTalerWallet1/Backend/WalletCore.swift | 4++--
MTalerWallet1/Model/Model+Balances.swift | 10+++++-----
MTalerWallet1/Model/Model+Deposit.swift | 22+++++++++++-----------
MTalerWallet1/Model/Model+Exchange.swift | 18+++++++++---------
MTalerWallet1/Model/Model+P2P.swift | 18+++++++++---------
MTalerWallet1/Model/Model+Payment.swift | 10+++++-----
MTalerWallet1/Model/Model+Pending.swift | 2+-
MTalerWallet1/Model/Model+Refund.swift | 4++--
MTalerWallet1/Model/Model+Settings.swift | 6+++---
MTalerWallet1/Model/Model+Transactions.swift | 36++++++------------------------------
MTalerWallet1/Model/Model+Withdraw.swift | 14+++++++-------
MTalerWallet1/Model/WalletModel.swift | 34+++++++++++++++++-----------------
13 files changed, 85 insertions(+), 109 deletions(-)

diff --git a/TalerWallet1/Backend/WalletBackendRequest.swift b/TalerWallet1/Backend/WalletBackendRequest.swift @@ -23,7 +23,7 @@ protocol WalletBackendFormattedRequest { associatedtype Args: Encodable associatedtype Response: Decodable - func operation() -> String + var operation: String { get } func args() -> Args } // MARK: - @@ -156,7 +156,7 @@ struct OrderShortInfo: Codable { // MARK: - /// A request to force update an exchange. struct WalletBackendForceUpdateRequest: WalletBackendFormattedRequest { - func operation() -> String { "addRequest" } + var operation: String { "addRequest" } func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl) } var exchangeBaseUrl: String @@ -169,7 +169,7 @@ struct WalletBackendForceUpdateRequest: WalletBackendFormattedRequest { /// A request to deposit funds. struct WalletBackendCreateDepositGroupRequest: WalletBackendFormattedRequest { - func operation() -> String { "createDepositGroup" } + var operation: String { "createDepositGroup" } func args() -> Args { Args(depositPayToUri: depositePayToUri, amount: amount) } var depositePayToUri: String @@ -187,7 +187,7 @@ struct WalletBackendCreateDepositGroupRequest: WalletBackendFormattedRequest { /// A request to get information about a payment request. struct WalletBackendPreparePayRequest: WalletBackendFormattedRequest { - func operation() -> String { "preparePay" } + var operation: String { "preparePay" } func args() -> Args { Args(talerPayUri: talerPayUri) } var talerPayUri: String @@ -210,7 +210,7 @@ struct IntegrationTestArgs: Codable { /// A request to run a basic integration test. struct WalletBackendRunIntegrationTestRequest: WalletBackendFormattedRequest { - func operation() -> String { "runIntegrationTest" } + var operation: String { "runIntegrationTest" } func args() -> Args { integrationTestArgs } var integrationTestArgs: IntegrationTestArgs @@ -228,7 +228,7 @@ struct TestPayArgs: Codable { /// A request to make a test payment. struct WalletBackendTestPayRequest: WalletBackendFormattedRequest { - func operation() -> String { "testPay" } + var operation: String { "testPay" } func args() -> Args { testPayArgs } var testPayArgs: TestPayArgs @@ -251,7 +251,7 @@ struct Coin: Codable { /// A request to dump all coins to JSON. struct WalletBackendDumpCoinsRequest: WalletBackendFormattedRequest { - func operation() -> String { "dumpCoins" } + var operation: String { "dumpCoins" } func args() -> Args { Args() } struct Args: Encodable { } @@ -264,7 +264,7 @@ struct WalletBackendDumpCoinsRequest: WalletBackendFormattedRequest { /// A request to suspend or unsuspend a coin. struct WalletBackendSuspendCoinRequest: WalletBackendFormattedRequest { struct Response: Decodable {} - func operation() -> String { "setCoinSuspended" } + var operation: String { "setCoinSuspended" } func args() -> Args { Args(coinPub: coinPub, suspended: suspended) } var coinPub: String diff --git a/TalerWallet1/Backend/WalletCore.swift b/TalerWallet1/Backend/WalletCore.swift @@ -522,7 +522,7 @@ extension WalletCore { extension WalletCore { /// send async requests to wallet-core func sendFormattedRequest<T: WalletBackendFormattedRequest> (_ request: T, asJSON: Bool = false) async throws -> (T.Response, UInt) { - let reqData = WalletBackendRequest(operation: request.operation(), + let reqData = WalletBackendRequest(operation: request.operation, args: AnyEncodable(request.args())) return try await withCheckedThrowingContinuation { continuation in encodeAndSend(reqData) { [self] requestId, timeSent, message, result, error in @@ -570,7 +570,7 @@ extension WalletCore { } } else if let error { // TODO: WALLET_CORE_REQUEST_CANCELLED - lastError = FullError(type: "error", operation: request.operation(), id: requestId, error: error) + lastError = FullError(type: "error", operation: request.operation, id: requestId, error: error) err = WalletBackendError.walletCoreError(error) } else { // both result and error are nil lastError = nil diff --git a/TalerWallet1/Model/Model+Balances.swift b/TalerWallet1/Model/Model+Balances.swift @@ -75,7 +75,7 @@ struct BalancesResponse: Decodable, Hashable, Sendable { /// A request to get the balances held in the wallet. fileprivate struct Balances: WalletBackendFormattedRequest { - func operation() -> String { "getBalances" } + var operation: String { "getBalances" } func args() -> Args { Args() } struct Args: Encodable {} // no arguments needed @@ -116,7 +116,7 @@ struct DiscountsResponse: Decodable, Hashable, Sendable { /// A request to get the discounts held in the wallet. fileprivate struct ListDiscounts: WalletBackendFormattedRequest { - func operation() -> String { "listDiscounts" } + var operation: String { "listDiscounts" } func args() -> Args { Args() } struct Args: Encodable {} // no arguments needed @@ -126,7 +126,7 @@ fileprivate struct ListDiscounts: WalletBackendFormattedRequest { /// A request to delete a discount by ID. struct DeleteDiscount: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "deleteDiscount" } + var operation: String { "deleteDiscount" } func args() -> Args { Args(tokenFamilyHash: tokenFamilyHash) } var tokenFamilyHash: String @@ -141,7 +141,7 @@ struct SubscriptionsResponse: Decodable, Hashable, Sendable { /// A request to get the subscriptions held in the wallet. fileprivate struct ListSubscriptions: WalletBackendFormattedRequest { - func operation() -> String { "listSubscriptions" } + var operation: String { "listSubscriptions" } func args() -> Args { Args() } struct Args: Encodable {} // no arguments needed @@ -151,7 +151,7 @@ fileprivate struct ListSubscriptions: WalletBackendFormattedRequest { /// A request to delete a subscription by ID. struct DeleteSubscription: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "deleteSubscription" } + var operation: String { "deleteSubscription" } func args() -> Args { Args(tokenFamilyHash: tokenFamilyHash) } var tokenFamilyHash: String diff --git a/TalerWallet1/Model/Model+Deposit.swift b/TalerWallet1/Model/Model+Deposit.swift @@ -25,7 +25,7 @@ struct ValidateIbanResult: Codable { /// A request to validate an IBAN. fileprivate struct ValidateIban: WalletBackendFormattedRequest { typealias Response = ValidateIbanResult - func operation() -> String { "validateIban" } + var operation: String { "validateIban" } func args() -> Args { Args(iban: iban) } var iban: String @@ -60,7 +60,7 @@ struct IbanAccountFieldToPaytoResponse: Codable { /// A request to convert an IBAN/BBAN to PayTo. fileprivate struct IbanAccountFieldToPayto: WalletBackendFormattedRequest { typealias Response = IbanAccountFieldToPaytoResponse - func operation() -> String { "convertIbanAccountFieldToPayto" } + var operation: String { "convertIbanAccountFieldToPayto" } func args() -> Args { Args(value: value, currency: currency) } var value: String @@ -79,7 +79,7 @@ struct IbanPaytoToAccountFieldResponse: Codable { /// A request to convert PayTo to IBAN/BBAN. fileprivate struct IbanPaytoToAccountField: WalletBackendFormattedRequest { typealias Response = IbanPaytoToAccountFieldResponse - func operation() -> String { "convertIbanPaytoToAccountField" } + var operation: String { "convertIbanPaytoToAccountField" } func args() -> Args { Args(paytoUri: paytoUri) } var paytoUri: String @@ -119,7 +119,7 @@ struct DepositWireTypesResponse: Codable { /// A request to get wire types that can be used for a deposit operation. fileprivate struct DepositWireTypes: WalletBackendFormattedRequest { typealias Response = DepositWireTypesResponse - func operation() -> String { "getDepositWireTypes" } + var operation: String { "getDepositWireTypes" } func args() -> Args { Args(currency: currency, scopeInfo: scopeInfo) } var currency: String? @@ -147,7 +147,7 @@ fileprivate struct AmountResponse: Codable { } fileprivate struct GetMaxDepositAmount: WalletBackendFormattedRequest { typealias Response = AmountResponse - func operation() -> String { "getMaxDepositAmount" } + var operation: String { "getMaxDepositAmount" } func args() -> Args { Args(currency: scope.currency, restrictScope: scope) } var scope: ScopeInfo @@ -182,7 +182,7 @@ struct CheckDepositResponse: Codable { /// A request to get an exchange's deposit contract terms. fileprivate struct CheckDeposit: WalletBackendFormattedRequest { typealias Response = CheckDepositResponse - func operation() -> String { "checkDeposit" } + var operation: String { "checkDeposit" } func args() -> Args { Args(depositPaytoUri: depositPaytoUri, amount: amount, clientCancellationId: "cancel") } @@ -211,7 +211,7 @@ struct DepositGroupResult: Decodable { /// A request to deposit some coins. fileprivate struct CreateDepositGroup: WalletBackendFormattedRequest { typealias Response = DepositGroupResult - func operation() -> String { "createDepositGroup" } + var operation: String { "createDepositGroup" } func args() -> Args { Args(depositPaytoUri: depositPaytoUri, restrictScope: scope, amount: amount) } @@ -258,7 +258,7 @@ struct BankAccounts: Decodable, Hashable { /// A request to list known bank accounts. fileprivate struct ListBankAccounts: WalletBackendFormattedRequest { typealias Response = BankAccounts - func operation() -> String { "listBankAccounts" } + var operation: String { "listBankAccounts" } func args() -> Args { Args(currency: currency) } var currency: String? struct Args: Encodable { @@ -278,7 +278,7 @@ extension WalletModel { /// A request to get one bank account. fileprivate struct GetBankAccountById: WalletBackendFormattedRequest { typealias Response = BankAccountsInfo - func operation() -> String { "getBankAccountById" } + var operation: String { "getBankAccountById" } func args() -> Args { Args(bankAccountId: bankAccountId) } var bankAccountId: String struct Args: Encodable { @@ -301,7 +301,7 @@ struct AddBankAccountResponse: Decodable, Hashable { /// A request to add a known bank account. fileprivate struct AddBankAccount: WalletBackendFormattedRequest { typealias Response = AddBankAccountResponse - func operation() -> String { "addBankAccount" } + var operation: String { "addBankAccount" } func args() -> Args { Args(paytoUri: uri, label: label, replaceBankAccountId: replace) } @@ -330,7 +330,7 @@ extension WalletModel { /// A request to forget a known bank account. fileprivate struct ForgetBankAccount: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "forgetBankAccount" } + var operation: String { "forgetBankAccount" } func args() -> Args { Args(bankAccountId: accountId) } var accountId: String struct Args: Encodable { diff --git a/TalerWallet1/Model/Model+Exchange.swift b/TalerWallet1/Model/Model+Exchange.swift @@ -142,7 +142,7 @@ extension DefaultExchange: Identifiable { // MARK: - /// A request to list exchanges names for a currency fileprivate struct ListExchanges: WalletBackendFormattedRequest { - func operation() -> String { "listExchanges" } + var operation: String { "listExchanges" } func args() -> Args { Args(filterByScope: scope, filterByType: filterByType, filterByExchangeEntryStatus: filterByStatus) } var scope: ScopeInfo? @@ -159,7 +159,7 @@ fileprivate struct ListExchanges: WalletBackendFormattedRequest { } fileprivate struct DefaultExchanges: WalletBackendFormattedRequest { - func operation() -> String { "getDefaultExchanges" } + var operation: String { "getDefaultExchanges" } func args() -> Args { Args() } // func args() -> Args { Args(stage: stage) } @@ -175,7 +175,7 @@ fileprivate struct DefaultExchanges: WalletBackendFormattedRequest { /// A request to get info for one exchange. fileprivate struct GetExchangeByUrl: WalletBackendFormattedRequest { - func operation() -> String { "getExchangeEntryByUrl" } + var operation: String { "getExchangeEntryByUrl" } func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl) } var exchangeBaseUrl: String @@ -188,7 +188,7 @@ fileprivate struct GetExchangeByUrl: WalletBackendFormattedRequest { /// A request to update a single exchange. fileprivate struct UpdateExchange: WalletBackendFormattedRequest { - func operation() -> String { "updateExchangeEntry" } + var operation: String { "updateExchangeEntry" } // func args() -> Args { Args(scopeInfo: scopeInfo) } func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl, force: force) } @@ -204,7 +204,7 @@ fileprivate struct UpdateExchange: WalletBackendFormattedRequest { /// A request to add an exchange. fileprivate struct AddExchange: WalletBackendFormattedRequest { - func operation() -> String { "addExchange" } + var operation: String { "addExchange" } func args() -> Args { Args(uri: uri, allowCompletion: true) } var uri: String @@ -217,7 +217,7 @@ fileprivate struct AddExchange: WalletBackendFormattedRequest { /// A request to delete an exchange. fileprivate struct DeleteExchange: WalletBackendFormattedRequest { - func operation() -> String { "deleteExchange" } + var operation: String { "deleteExchange" } func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl, purge: purge) } var exchangeBaseUrl: String @@ -231,7 +231,7 @@ fileprivate struct DeleteExchange: WalletBackendFormattedRequest { /// A request to get info about a currency fileprivate struct GetCurrencySpecification: WalletBackendFormattedRequest { - func operation() -> String { "getCurrencySpecification" } + var operation: String { "getCurrencySpecification" } func args() -> Args { Args(scope: scope) } var scope: ScopeInfo @@ -244,7 +244,7 @@ fileprivate struct GetCurrencySpecification: WalletBackendFormattedRequest { } /// A request to make a currency "global" fileprivate struct AddGlobalCurrency: WalletBackendFormattedRequest { - func operation() -> String { "addGlobalCurrencyExchange" } + var operation: String { "addGlobalCurrencyExchange" } func args() -> Args { Args(currency: currency, exchangeBaseUrl: baseUrl, exchangeMasterPub: masterPub) } @@ -259,7 +259,7 @@ fileprivate struct AddGlobalCurrency: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success } fileprivate struct RmvGlobalCurrency: WalletBackendFormattedRequest { - func operation() -> String { "removeGlobalCurrencyExchange" } + var operation: String { "removeGlobalCurrencyExchange" } func args() -> Args { Args(currency: currency, exchangeBaseUrl: baseUrl, exchangeMasterPub: masterPub) } diff --git a/TalerWallet1/Model/Model+P2P.swift b/TalerWallet1/Model/Model+P2P.swift @@ -27,7 +27,7 @@ fileprivate struct AmountResponse: Codable { } fileprivate struct GetMaxPeerPushDebitAmount: WalletBackendFormattedRequest { typealias Response = AmountResponse - func operation() -> String { "getMaxPeerPushDebitAmount" } + var operation: String { "getMaxPeerPushDebitAmount" } func args() -> Args { Args(currency: scope.currency, restrictScope: scope) } var scope: ScopeInfo @@ -55,7 +55,7 @@ struct CheckPeerPushDebitResponse: Codable { } fileprivate struct CheckPeerPushDebit: WalletBackendFormattedRequest { typealias Response = CheckPeerPushDebitResponse - func operation() -> String { "checkPeerPushDebit" } + var operation: String { "checkPeerPushDebit" } func args() -> Args { Args(amount: amount, restrictScope: scope, clientCancellationId: "cancel") } @@ -89,7 +89,7 @@ struct InitiatePeerPushDebitResponse: Codable { } fileprivate struct InitiatePeerPushDebit: WalletBackendFormattedRequest { typealias Response = InitiatePeerPushDebitResponse - func operation() -> String { "initiatePeerPushDebit" } + var operation: String { "initiatePeerPushDebit" } func args() -> Args { Args(restrictScope: scope, partialContractTerms: terms) } var scope: ScopeInfo @@ -120,7 +120,7 @@ struct CheckPeerPullCreditResponse: Codable { } fileprivate struct CheckPeerPullCredit: WalletBackendFormattedRequest { typealias Response = CheckPeerPullCreditResponse - func operation() -> String { "checkPeerPullCredit" } + var operation: String { "checkPeerPullCredit" } func args() -> Args { Args(amount: amount, restrictScope: scope, exchangeBaseUrl: scope?.url, @@ -152,7 +152,7 @@ struct InitiatePeerPullCreditResponse: Codable { } fileprivate struct InitiatePeerPullCredit: WalletBackendFormattedRequest { typealias Response = InitiatePeerPullCreditResponse - func operation() -> String { "initiatePeerPullCredit" } + var operation: String { "initiatePeerPullCredit" } func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl, partialContractTerms: partialContractTerms) } var exchangeBaseUrl: String? @@ -187,7 +187,7 @@ struct PreparePeerPushCreditResponse: Codable { } fileprivate struct PreparePeerPushCredit: WalletBackendFormattedRequest { typealias Response = PreparePeerPushCreditResponse - func operation() -> String { "preparePeerPushCredit" } + var operation: String { "preparePeerPushCredit" } func args() -> Args { Args(talerUri: talerUri) } var talerUri: String @@ -208,7 +208,7 @@ extension WalletModel { /// Accept an incoming peer push payment fileprivate struct AcceptPeerPushCredit: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "confirmPeerPushCredit" } // should be "acceptPeerPushCredit" + var operation: String { "confirmPeerPushCredit" } // should be "acceptPeerPushCredit" func args() -> Args { Args(transactionId: transactionId) } var transactionId: String @@ -239,7 +239,7 @@ struct PreparePeerPullDebitResponse: Codable { } fileprivate struct PreparePeerPullDebit: WalletBackendFormattedRequest { typealias Response = PreparePeerPullDebitResponse - func operation() -> String { "preparePeerPullDebit" } + var operation: String { "preparePeerPullDebit" } func args() -> Args { Args(talerUri: talerUri) } var talerUri: String @@ -260,7 +260,7 @@ extension WalletModel { /// Confirm incoming peer push request(invoice) and pay fileprivate struct ConfirmPeerPullDebit: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "confirmPeerPullDebit" } + var operation: String { "confirmPeerPullDebit" } func args() -> Args { Args(transactionId: transactionId) } var transactionId: String diff --git a/TalerWallet1/Model/Model+Payment.swift b/TalerWallet1/Model/Model+Payment.swift @@ -310,7 +310,7 @@ struct PreparePayResult2: Codable { /// A request to get an exchange's payment contract terms. fileprivate struct PreparePayForUri: WalletBackendFormattedRequest { typealias Response = PreparePayResult2 - func operation() -> String { "preparePayForUriV2" } + var operation: String { "preparePayForUriV2" } func args() -> Args { Args(talerPayUri: talerPayUri) } var talerPayUri: String @@ -413,7 +413,7 @@ struct ChoicesForPayment: Codable { /// A request to get an exchange's payment contract terms. fileprivate struct GetChoicesForPayment: WalletBackendFormattedRequest { typealias Response = ChoicesForPayment - func operation() -> String { "getChoicesForPayment" } + var operation: String { "getChoicesForPayment" } func args() -> Args { Args(transactionId: transactionId, forcedCoinSel: forcedCoinSel) } var transactionId: String @@ -431,7 +431,7 @@ struct TemplateParams: Codable { /// A request to get an exchange's payment contract terms. fileprivate struct PreparePayForTemplateRequest: WalletBackendFormattedRequest { typealias Response = PreparePayResult2 - func operation() -> String { "preparePayForTemplateV2" } + var operation: String { "preparePayForTemplateV2" } func args() -> Args { Args(talerPayTemplateUri: talerPayTemplateUri, templateParams: templateParams) } var talerPayTemplateUri: String @@ -552,7 +552,7 @@ struct WalletTemplateDetails: Codable { /// A request to get an exchange's payment contract terms. fileprivate struct CheckPayForTemplate: WalletBackendFormattedRequest { typealias Response = WalletTemplateDetails - func operation() -> String { "checkPayForTemplate" } + var operation: String { "checkPayForTemplate" } func args() -> Args { Args(talerPayTemplateUri: talerPayTemplateUri) } var talerPayTemplateUri: String @@ -571,7 +571,7 @@ struct ConfirmPayResult: Decodable { /// A request to get an exchange's payment details. fileprivate struct ConfirmPayForUri: WalletBackendFormattedRequest { typealias Response = ConfirmPayResult - func operation() -> String { "confirmPay" } + var operation: String { "confirmPay" } func args() -> Args { Args(transactionId: transactionId, noWait: true, choiceIndex: choiceIndex) } var transactionId: String diff --git a/TalerWallet1/Model/Model+Pending.swift b/TalerWallet1/Model/Model+Pending.swift @@ -13,7 +13,7 @@ import SymLog // MARK: - /// A request to list the backend's currently pending operations. fileprivate struct GetPendingOperations: WalletBackendFormattedRequest { - func operation() -> String { "getPendingOperations" } + var operation: String { "getPendingOperations" } func args() -> Args { Args() } struct Args: Encodable {} diff --git a/TalerWallet1/Model/Model+Refund.swift b/TalerWallet1/Model/Model+Refund.swift @@ -10,7 +10,7 @@ import Foundation // MARK: - /// A request to prepare a refund with an obtained URI struct StartRefundURIRequest: WalletBackendFormattedRequest { - func operation() -> String { "startRefundQueryForUri" } + var operation: String { "startRefundQueryForUri" } func args() -> Args { Args(talerRefundUri: talerRefundUri) } var talerRefundUri: String @@ -27,7 +27,7 @@ struct StartRefundURIRequest: WalletBackendFormattedRequest { /// A request to prepare a refund with a transactionID struct StartRefundQueryRequest: WalletBackendFormattedRequest { - func operation() -> String { "startRefundQuery" } + var operation: String { "startRefundQuery" } func args() -> Args { Args(transactionId: transactionId) } var transactionId: String diff --git a/TalerWallet1/Model/Model+Settings.swift b/TalerWallet1/Model/Model+Settings.swift @@ -15,7 +15,7 @@ fileprivate let MERCHANTAUTHTOKEN = "secret-token:sandbox" /// A request to add a test balance to the wallet. fileprivate struct WithdrawTestBalanceRequest: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "withdrawTestBalance" } + var operation: String { "withdrawTestBalance" } func args() -> Args { Args(amount: amount, corebankApiBaseUrl: bankBaseUrl, useForeignAccount: true, @@ -49,7 +49,7 @@ extension WalletModel { /// A request to add a test balance to the wallet. fileprivate struct RunIntegrationTest: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { newVersion ? "runIntegrationTestV2" : "runIntegrationTest" } + var operation: String { newVersion ? "runIntegrationTestV2" : "runIntegrationTest" } func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl, corebankApiBaseUrl: bankBaseUrl, merchantBaseUrl: merchantBaseUrl, @@ -96,7 +96,7 @@ extension WalletModel { /// A request to add a test balance to the wallet. fileprivate struct InfiniteTransactionLoop: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "testingInfiniteTransactionLoop" } + var operation: String { "testingInfiniteTransactionLoop" } func args() -> Args { Args(delayMs: delayMs, shouldFetch: shouldFetch) } diff --git a/TalerWallet1/Model/Model+Transactions.swift b/TalerWallet1/Model/Model+Transactions.swift @@ -23,30 +23,6 @@ extension WalletModel { } } // MARK: - -/// A request to get the transactions in the wallet's history. -fileprivate struct GetTransactions: WalletBackendFormattedRequest { - func operation() -> String { "getTransactions" } - func args() -> Args { Args(scopeInfo: scopeInfo, currency: currency, search: search, - sort: sort, filterByState: filterByState, includeRefreshes: includeRefreshes) } - var scopeInfo: ScopeInfo? - var currency: String? - var search: String? - var sort: String? - var filterByState: TransactionStateFilter? - var includeRefreshes: Bool? - struct Args: Encodable { - var scopeInfo: ScopeInfo? - var currency: String? - var search: String? - var sort: String? - var filterByState: TransactionStateFilter? - var includeRefreshes: Bool? - } - - struct Response: Decodable { // list of transactions - var transactions: [TalerTransaction] - } -} enum TransactionStateFilter: String, Codable { case done case final // done, aborted, expired, ... @@ -60,7 +36,7 @@ struct TransactionOffset: Codable { } /// A request to get the transactions in the wallet's history. fileprivate struct GetTransactionsV2: WalletBackendFormattedRequest { - func operation() -> String { "getTransactionsV2" } + var operation: String { "getTransactionsV2" } func args() -> Args { Args(scopeInfo: scope, filterByState: filterByState, includeRefreshes: includeRefreshes, @@ -89,7 +65,7 @@ fileprivate struct GetTransactionsV2: WalletBackendFormattedRequest { /// A request to abort a wallet transaction by ID. struct AbortTransaction: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "abortTransaction" } + var operation: String { "abortTransaction" } func args() -> Args { Args(transactionId: transactionId) } var transactionId: String @@ -100,7 +76,7 @@ struct AbortTransaction: WalletBackendFormattedRequest { /// A request to delete a wallet transaction by ID. struct DeleteTransaction: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "deleteTransaction" } + var operation: String { "deleteTransaction" } func args() -> Args { Args(transactionId: transactionId) } var transactionId: String @@ -111,7 +87,7 @@ struct DeleteTransaction: WalletBackendFormattedRequest { /// A request to delete a wallet transaction by ID. struct FailTransaction: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "failTransaction" } + var operation: String { "failTransaction" } func args() -> Args { Args(transactionId: transactionId) } var transactionId: String @@ -122,7 +98,7 @@ struct FailTransaction: WalletBackendFormattedRequest { /// A request to suspend a wallet transaction by ID. struct SuspendTransaction: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "suspendTransaction" } + var operation: String { "suspendTransaction" } func args() -> Args { Args(transactionId: transactionId) } var transactionId: String @@ -133,7 +109,7 @@ struct SuspendTransaction: WalletBackendFormattedRequest { /// A request to suspend a wallet transaction by ID. struct ResumeTransaction: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "resumeTransaction" } + var operation: String { "resumeTransaction" } func args() -> Args { Args(transactionId: transactionId) } var transactionId: String diff --git a/TalerWallet1/Model/Model+Withdraw.swift b/TalerWallet1/Model/Model+Withdraw.swift @@ -87,7 +87,7 @@ struct PrepareBankIntegratedWithdrawalResponse: Decodable { /// A request to get an exchange's withdrawal details. fileprivate struct PrepareBankIntegratedWithdrawal: WalletBackendFormattedRequest { typealias Response = PrepareBankIntegratedWithdrawalResponse - func operation() -> String { "prepareBankIntegratedWithdrawal" } + var operation: String { "prepareBankIntegratedWithdrawal" } func args() -> Args { Args(talerWithdrawUri: talerUri) } var talerUri: String @@ -104,7 +104,7 @@ struct WithdrawExchangeResponse: Decodable { /// A request to get an exchange's withdrawal details. fileprivate struct PrepareWithdrawExchange: WalletBackendFormattedRequest { typealias Response = WithdrawExchangeResponse - func operation() -> String { "prepareWithdrawExchange" } + var operation: String { "prepareWithdrawExchange" } func args() -> Args { Args(talerUri: talerUri, progressToken: "WithdrawExchange") } @@ -128,7 +128,7 @@ struct WithdrawalDetailsForAmount: Decodable { /// A request to get an exchange's withdrawal details. fileprivate struct GetWithdrawalDetailsForAmount: WalletBackendFormattedRequest { typealias Response = WithdrawalDetailsForAmount - func operation() -> String { "getWithdrawalDetailsForAmount" } + var operation: String { "getWithdrawalDetailsForAmount" } func args() -> Args { Args(amount: amount, exchangeBaseUrl: baseUrl, restrictScope: scope, @@ -162,7 +162,7 @@ struct ExchangeTermsOfService: Decodable { /// A request to query an exchange's terms of service. fileprivate struct GetExchangeTermsOfService: WalletBackendFormattedRequest { typealias Response = ExchangeTermsOfService - func operation() -> String { "getExchangeTos" } + var operation: String { "getExchangeTos" } func args() -> Args { Args(exchangeBaseUrl: baseUrl, acceptedFormat: acceptedFormat, acceptLanguage: acceptLanguage, @@ -180,7 +180,7 @@ fileprivate struct GetExchangeTermsOfService: WalletBackendFormattedRequest { /// A request to mark an exchange's terms of service as accepted. fileprivate struct SetExchangeTOSAccepted: WalletBackendFormattedRequest { struct Response: Decodable {} // no result - getting no error back means success - func operation() -> String { "setExchangeTosAccepted" } + var operation: String { "setExchangeTosAccepted" } func args() -> Args { Args(exchangeBaseUrl: baseUrl) } var baseUrl: String @@ -198,7 +198,7 @@ struct AcceptWithdrawalResponse: Decodable { /// A request to accept a bank-integrated withdrawl. fileprivate struct AcceptBankIntegratedWithdrawal: WalletBackendFormattedRequest { typealias Response = AcceptWithdrawalResponse - func operation() -> String { "acceptBankIntegratedWithdrawal" } + var operation: String { "acceptBankIntegratedWithdrawal" } func args() -> Args { Args(talerWithdrawUri: talerUri, exchangeBaseUrl: baseUrl, amount: amount, restrictAge: restrictAge) } var talerUri: String @@ -222,7 +222,7 @@ struct AcceptManualWithdrawalResult: Decodable { /// A request to accept a manual withdrawl. fileprivate struct AcceptManualWithdrawal: WalletBackendFormattedRequest { typealias Response = AcceptManualWithdrawalResult - func operation() -> String { "acceptManualWithdrawal" } + var operation: String { "acceptManualWithdrawal" } func args() -> Args { Args(amount: amount, exchangeBaseUrl: baseUrl, restrictAge: restrictAge) } var amount: Amount diff --git a/TalerWallet1/Model/WalletModel.swift b/TalerWallet1/Model/WalletModel.swift @@ -134,19 +134,19 @@ final class WalletModel: ObservableObject, Sendable { func sendRequest<T: WalletBackendFormattedRequest> (_ request: T, viewHandles: Bool = false, asJSON: Bool = false) async throws -> T.Response { // T for any Thread #if !DEBUG - logger.log("sending: \(request.operation(), privacy: .public)") + logger.log("sending: \(request.operation, privacy: .public)") #endif let sendTime = Date.now do { let (response, id) = try await WalletCore.shared.sendFormattedRequest(request, asJSON: asJSON) #if !DEBUG let timeUsed = Date.now - sendTime - logger.log("received: \(request.operation(), privacy: .public) (\(id, privacy: .public)) after \(timeUsed.milliseconds, privacy: .public) ms") + logger.log("received: \(request.operation, privacy: .public) (\(id, privacy: .public)) after \(timeUsed.milliseconds, privacy: .public) ms") #endif return response } catch { // rethrows let timeUsed = Date.now - sendTime - logger.error("\(request.operation(), privacy: .public) failed after \(timeUsed.milliseconds, privacy: .public) ms\n\(error, privacy: .public)") + logger.error("\(request.operation, privacy: .public) failed after \(timeUsed.milliseconds, privacy: .public) ms\n\(error, privacy: .public)") if !viewHandles { // TODO: symlog + controller sound await setError(error) @@ -159,7 +159,7 @@ final class WalletModel: ObservableObject, Sendable { /// A request to tell wallet-core about the network. fileprivate struct ApplicationResumedRequest: WalletBackendFormattedRequest { struct Response: Decodable {} - func operation() -> String { "hintApplicationResumed" } + var operation: String { "hintApplicationResumed" } func args() -> Args { Args() } struct Args: Encodable {} // no arguments needed @@ -167,7 +167,7 @@ fileprivate struct ApplicationResumedRequest: WalletBackendFormattedRequest { fileprivate struct NetworkAvailabilityRequest: WalletBackendFormattedRequest { struct Response: Decodable {} - func operation() -> String { "hintNetworkAvailability" } + var operation: String { "hintNetworkAvailability" } func args() -> Args { Args(isNetworkAvailable: isNetworkAvailable) } var isNetworkAvailable: Bool @@ -193,7 +193,7 @@ extension WalletModel { /// A request to cancel a wallet transaction by token. fileprivate struct CancelProgressToken: WalletBackendFormattedRequest { struct Response: Decodable {} - func operation() -> String { "cancelProgressToken" } + var operation: String { "cancelProgressToken" } func args() -> Args { Args(operation: op, progressToken: token) } var op: String @@ -207,7 +207,7 @@ fileprivate struct CancelProgressToken: WalletBackendFormattedRequest { /// A request to retry a wallet transaction by token. fileprivate struct RetryProgressTokenNow: WalletBackendFormattedRequest { struct Response: Decodable {} - func operation() -> String { "retryProgressTokenNow" } + var operation: String { "retryProgressTokenNow" } func args() -> Args { Args(operation: op, progressToken: token) } var op: String @@ -222,7 +222,7 @@ fileprivate struct RetryProgressTokenNow: WalletBackendFormattedRequest { /// A request to get a wallet transaction by ID. fileprivate struct GetTransactionById: WalletBackendFormattedRequest { typealias Response = TalerTransaction - func operation() -> String { "getTransactionById" } + var operation: String { "getTransactionById" } func args() -> Args { Args(transactionId: txId, includeContractTerms: inclTerms) } var txId: String @@ -236,7 +236,7 @@ fileprivate struct GetTransactionById: WalletBackendFormattedRequest { fileprivate struct JSONTransactionById: WalletBackendFormattedRequest { typealias Response = String - func operation() -> String { "getTransactionById" } + var operation: String { "getTransactionById" } func args() -> Args { Args(transactionId: transactionId, includeContractTerms: includeContractTerms) } var transactionId: String @@ -315,7 +315,7 @@ fileprivate struct Config: Encodable { fileprivate struct ConfigRequest: WalletBackendFormattedRequest { var setTesting: Bool - func operation() -> String { "setWalletRunConfig" } + var operation: String { "setWalletRunConfig" } func args() -> Args { let testing = Testing(devModeActive: setTesting) let builtin = Builtin(exchanges: []) @@ -346,7 +346,7 @@ fileprivate struct InitRequest: WalletBackendFormattedRequest { var persistentStoragePath: String var setTesting: Bool - func operation() -> String { "init" } + var operation: String { "init" } func args() -> Args { let testing = Testing(devModeActive: setTesting) let builtin = Builtin(exchanges: []) @@ -473,7 +473,7 @@ extension WalletModel { // MARK: - /// A request to reset Wallet-core to a virgin DB. WILL DESTROY ALL COINS fileprivate struct ResetRequest: WalletBackendFormattedRequest { - func operation() -> String { "clearDb" } + var operation: String { "clearDb" } func args() -> Args { Args() } struct Args: Encodable {} // no arguments needed @@ -489,7 +489,7 @@ extension WalletModel { } // MARK: - fileprivate struct ExportDbToFile: WalletBackendFormattedRequest { - func operation() -> String { "exportDbToFile" } + var operation: String { "exportDbToFile" } func args() -> Args { Args(directory: directory, stem: stem, forceFormat: "json") } var directory: String @@ -505,7 +505,7 @@ fileprivate struct ExportDbToFile: WalletBackendFormattedRequest { } fileprivate struct ImportDbFromFile: WalletBackendFormattedRequest { - func operation() -> String { "importDbFromFile" } + var operation: String { "importDbFromFile" } func args() -> Args { Args(path: path ) } var path: String @@ -516,14 +516,14 @@ fileprivate struct ImportDbFromFile: WalletBackendFormattedRequest { } fileprivate struct GetDiagnostics: WalletBackendFormattedRequest { - func operation() -> String { "getDiagnostics" } + var operation: String { "getDiagnostics" } func args() -> Args { Args() } struct Args: Encodable {} // no arguments needed typealias Response = String } fileprivate struct GetPerformanceStats: WalletBackendFormattedRequest { - func operation() -> String { "testingGetPerformanceStats" } + var operation: String { "testingGetPerformanceStats" } func args() -> Args { Args() } struct Args: Encodable {} // no arguments needed typealias Response = String @@ -563,7 +563,7 @@ extension WalletModel { } // MARK: - fileprivate struct DevExperimentRequest: WalletBackendFormattedRequest { - func operation() -> String { "applyDevExperiment" } + var operation: String { "applyDevExperiment" } func args() -> Args { Args(devExperimentUri: talerUri) } var talerUri: String