From ba51b5e541d888cafdbf479a7e03a116af7050c5 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 14 Nov 2023 14:13:51 -0600 Subject: [wallet] Proper DB import/export functionality --- .../net/taler/wallet/backend/WalletBackendApi.kt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'wallet/src/main/java/net/taler/wallet/backend') diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt index bf6f371..ea58dd7 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt @@ -23,6 +23,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.serialization.KSerializer +import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.decodeFromJsonElement import net.taler.wallet.backend.TalerErrorCode.NONE import org.json.JSONObject @@ -86,4 +87,26 @@ class WalletBackendApi( WalletResponse.Error(info) } } + + // Returns raw JSON response instead of serialized object + suspend inline fun rawRequest( + operation: String, + noinline args: (JSONObject.() -> JSONObject)? = null, + ): WalletResponse = withContext(Dispatchers.Default) { + val json = BackendManager.json + try { + when (val response = sendRequest(operation, args?.invoke(JSONObject()))) { + is ApiResponse.Response -> { + WalletResponse.Success(response.result) + } + is ApiResponse.Error -> { + val error: TalerErrorInfo = json.decodeFromJsonElement(response.error) + WalletResponse.Error(error) + } + } + } catch (e: Exception) { + val info = TalerErrorInfo(NONE, "", e.toString()) + WalletResponse.Error(info) + } + } } -- cgit v1.2.3