Merge pull request #1416 from Electric-Coin-Company/fix-init-seed-required
Correctly throw `InitializeException.SeedRequired`
This commit is contained in:
commit
5fdaa6c935
|
@ -6,6 +6,13 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- SDK release 1.11.0-beta01 documented that `Synchronizer.new` would throw an
|
||||
exception indicating that an internal migration requires the wallet seed, if
|
||||
called with `null`. This has been unintentionally broken the entire time: the
|
||||
handling logic for this case was accidentally removed shortly after it was
|
||||
added. The SDK now correctly throws `InitializeException.SeedRequired`.
|
||||
|
||||
### Changed
|
||||
- The SDK uses ZIP-317 fee system internally
|
||||
- `ZcashSdk.MINERS_FEE` has been deprecated, and will be removed in 2.1.0
|
||||
|
|
|
@ -47,8 +47,8 @@ interface Backend {
|
|||
*
|
||||
* If `seed` is `null`, database migrations will be attempted without it.
|
||||
*
|
||||
* @return 0 if successful, 1 if the seed must be provided in order to execute the requested migrations, or -1
|
||||
* otherwise.
|
||||
* @return 0 if successful, 1 if the seed must be provided in order to execute the
|
||||
* requested migrations.
|
||||
*
|
||||
* @throws RuntimeException as a common indicator of the operation failure
|
||||
*/
|
||||
|
|
|
@ -53,13 +53,6 @@ sealed class CompactBlockProcessorException(message: String, cause: Throwable? =
|
|||
|
||||
class FailedReorgRepair(message: String) : CompactBlockProcessorException(message)
|
||||
|
||||
class Uninitialized(cause: Throwable? = null) : CompactBlockProcessorException(
|
||||
"Cannot process blocks because the wallet has not been" +
|
||||
" initialized. Verify that the seed phrase was properly created or imported. If so, then this problem" +
|
||||
" can be fixed by re-importing the wallet.",
|
||||
cause
|
||||
)
|
||||
|
||||
data object NoAccount : CompactBlockProcessorException(
|
||||
"Attempting to scan without an account. This is probably a setup error or a race condition."
|
||||
) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cash.z.ecc.android.sdk.internal
|
||||
|
||||
import cash.z.ecc.android.sdk.exception.InitializeException
|
||||
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
|
||||
import cash.z.ecc.android.sdk.internal.model.ScanRange
|
||||
import cash.z.ecc.android.sdk.internal.model.ScanSummary
|
||||
|
@ -77,7 +78,8 @@ internal interface TypesafeBackend {
|
|||
outputIndex: Int
|
||||
): String?
|
||||
|
||||
suspend fun initDataDb(seed: ByteArray?): Int
|
||||
@Throws(InitializeException::class)
|
||||
suspend fun initDataDb(seed: ByteArray?)
|
||||
|
||||
/**
|
||||
* @throws RuntimeException as a common indicator of the operation failure
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cash.z.ecc.android.sdk.internal
|
||||
|
||||
import cash.z.ecc.android.sdk.exception.InitializeException
|
||||
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
|
||||
import cash.z.ecc.android.sdk.internal.model.JniSubtreeRoot
|
||||
import cash.z.ecc.android.sdk.internal.model.ScanRange
|
||||
|
@ -149,7 +150,15 @@ internal class TypesafeBackendImpl(private val backend: Backend) : TypesafeBacke
|
|||
outputIndex: Int
|
||||
): String? = backend.getMemoAsUtf8(txId, outputIndex)
|
||||
|
||||
override suspend fun initDataDb(seed: ByteArray?): Int = backend.initDataDb(seed)
|
||||
override suspend fun initDataDb(seed: ByteArray?) {
|
||||
val ret = backend.initDataDb(seed)
|
||||
when (ret) {
|
||||
1 -> throw InitializeException.SeedRequired
|
||||
0 -> { /* Successful case - no action needed */ }
|
||||
-1 -> error("Rust backend only uses -1 as an error sentinel")
|
||||
else -> error("Rust backend used a code that needs to be defined here")
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun putSaplingSubtreeRoots(
|
||||
startIndex: UInt,
|
||||
|
|
|
@ -2,7 +2,6 @@ package cash.z.ecc.android.sdk.internal.db.derived
|
|||
|
||||
import android.content.Context
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import cash.z.ecc.android.sdk.exception.CompactBlockProcessorException
|
||||
import cash.z.ecc.android.sdk.internal.NoBackupContextWrapper
|
||||
import cash.z.ecc.android.sdk.internal.Twig
|
||||
import cash.z.ecc.android.sdk.internal.TypesafeBackend
|
||||
|
@ -48,14 +47,7 @@ internal class DerivedDataDb private constructor(
|
|||
numberOfAccounts: Int,
|
||||
recoverUntil: BlockHeight?
|
||||
): DerivedDataDb {
|
||||
runCatching {
|
||||
val result = backend.initDataDb(seed)
|
||||
if (result < 0) {
|
||||
throw CompactBlockProcessorException.Uninitialized()
|
||||
}
|
||||
}.onFailure {
|
||||
throw CompactBlockProcessorException.Uninitialized(it)
|
||||
}
|
||||
backend.initDataDb(seed)
|
||||
|
||||
val database =
|
||||
ReadOnlySupportSqliteOpenHelper.openExistingDatabaseAsReadOnly(
|
||||
|
|
Loading…
Reference in New Issue