summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/backend
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-11-14 14:13:51 -0600
committerTorsten Grote <t@grobox.de>2023-11-28 13:59:37 -0300
commitba51b5e541d888cafdbf479a7e03a116af7050c5 (patch)
treea8b893bd8dd0212cba11cd0af75e95eb8b7a7bd0 /wallet/src/main/java/net/taler/wallet/backend
parent94ee3a2f114e0345ea7408aacc30e3da9545474c (diff)
downloadtaler-android-ba51b5e541d888cafdbf479a7e03a116af7050c5.tar.gz
taler-android-ba51b5e541d888cafdbf479a7e03a116af7050c5.tar.bz2
taler-android-ba51b5e541d888cafdbf479a7e03a116af7050c5.zip
[wallet] Proper DB import/export functionality
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/backend')
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt23
1 files changed, 23 insertions, 0 deletions
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<JsonObject> = 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)
+ }
+ }
}