Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ dependencyResolutionManagement {
library("mlkit-scanning", "com.google.mlkit:barcode-scanning:$mlkitScanningVersion")
library("tink", "com.google.crypto.tink:tink-android:$tinkVersion")
library("zcash-sdk", "cash.z.ecc.android:zcash-android-sdk:$zcashSdkVersion")
library("zcash-sdk-backend", "cash.z.ecc.android:zcash-android-backend:$zcashSdkVersion")
library("zcash-sdk-incubator", "cash.z.ecc.android:zcash-android-sdk-incubator:$zcashSdkVersion")
library("zcash-bip39", "cash.z.ecc.android:kotlin-bip39:$zcashBip39Version")
library("zip321", "org.zecdev:zip321:$zip321Version")
Expand Down Expand Up @@ -384,6 +385,7 @@ if (zcashSdkIncludedBuildPath.isNotEmpty()) {
includeBuild(zcashSdkIncludedBuildPath) {
dependencySubstitution {
substitute(module("cash.z.ecc.android:zcash-android-sdk")).using(project(":sdk-lib"))
substitute(module("cash.z.ecc.android:zcash-android-backend")).using(project(":backend-lib"))
substitute(module("cash.z.ecc.android:zcash-android-sdk-incubator")).using(project(":sdk-incubator-lib"))
}
}
Expand Down
1 change: 1 addition & 0 deletions ui-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ dependencies {
"storeImplementation"(libs.mlkit.scanning)
"internalImplementation"(libs.mlkit.scanning)
api(libs.zcash.sdk)
implementation(libs.zcash.sdk.backend)
implementation(libs.zcash.sdk.incubator)
implementation(libs.zcash.bip39)
implementation(libs.tink)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package co.electriccoin.zcash.di

import cash.z.ecc.android.sdk.internal.TypesafeVotingBackend
import cash.z.ecc.android.sdk.internal.TypesafeVotingBackendImpl
import co.electriccoin.zcash.ui.common.provider.ApplicationStateProvider
import co.electriccoin.zcash.ui.common.provider.ApplicationStateProviderImpl
import co.electriccoin.zcash.ui.common.provider.BlockchainProvider
Expand Down Expand Up @@ -109,7 +107,6 @@ val providerModule =
singleOf(::EphemeralAddressStorageProviderImpl) bind EphemeralAddressStorageProvider::class
singleOf(::CMCApiProviderImpl) bind CMCApiProvider::class
factoryOf(::KeystoneSDKProviderImpl) bind KeystoneSDKProvider::class
singleOf(::TypesafeVotingBackendImpl) bind TypesafeVotingBackend::class
singleOf(::VotingCryptoClientImpl) bind VotingCryptoClient::class
singleOf(::VotingHotkeySeedProviderImpl) bind VotingHotkeySeedProvider::class
singleOf(::KtorVotingApiProvider) bind VotingApiProvider::class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.lang.reflect.InvocationTargetException
import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

interface SynchronizerProvider {
val error: StateFlow<SynchronizerError?>
Expand All @@ -32,6 +37,8 @@ interface SynchronizerProvider {
*/
suspend fun getSynchronizer(): Synchronizer

suspend fun getVotingWalletDbPath(): String

fun resetSynchronizer()
}

Expand Down Expand Up @@ -79,6 +86,9 @@ class SynchronizerProviderImpl(
.first()
}

override suspend fun getVotingWalletDbPath(): String =
getSynchronizer().getVotingWalletDbPathByReflection()

override fun resetSynchronizer() {
walletCoordinator.resetSynchronizer()
}
Expand Down Expand Up @@ -113,3 +123,22 @@ class SynchronizerProviderImpl(
return pipeline
}
}

@Suppress("TooGenericExceptionCaught")
private suspend fun Synchronizer.getVotingWalletDbPathByReflection(): String =
suspendCoroutine { continuation ->
try {
val method = javaClass.methods.firstOrNull { method ->
method.name.startsWith("getWalletDbPathForVoting") &&
method.parameterTypes.size == 1
} ?: error("SDK synchronizer does not expose voting wallet DB path")
val result = method.invoke(this, continuation)
if (result !== COROUTINE_SUSPENDED) {
continuation.resume(result as String)
}
} catch (exception: InvocationTargetException) {
continuation.resumeWithException(exception.targetException ?: exception)
} catch (throwable: Throwable) {
continuation.resumeWithException(throwable)
}
}
Loading