Various bug fixes and improvements.
- Exposed primary constructor in initializer and added more convenience functions - Fix: error handler not being passed through when changing server - New: warn developer when a critical error occurs but is not covered with a callback - New: Typed exceptions for missing birthday or viewingKey values during initialization - New: updated default server for checkpoint tool
This commit is contained in:
parent
fca75169c4
commit
0601ec488b
|
@ -13,7 +13,7 @@ import java.io.File
|
|||
/**
|
||||
* Simplified Initializer focused on starting from a ViewingKey.
|
||||
*/
|
||||
class Initializer private constructor(appContext: Context, builder: Builder): SdkSynchronizer.SdkInitializer {
|
||||
class Initializer constructor(appContext: Context, builder: Builder): SdkSynchronizer.SdkInitializer {
|
||||
override val context = appContext.applicationContext
|
||||
override val rustBackend: RustBackend
|
||||
override val alias: String
|
||||
|
@ -255,8 +255,34 @@ class Initializer private constructor(appContext: Context, builder: Builder): S
|
|||
importedWalletBirthday(birthdayHeight)
|
||||
}
|
||||
|
||||
fun new(seed: ByteArray) {
|
||||
fun import(
|
||||
viewingKey: String,
|
||||
birthdayHeight: Int,
|
||||
host: String = ZcashSdk.DEFAULT_LIGHTWALLETD_HOST,
|
||||
port: Int = ZcashSdk.DEFAULT_LIGHTWALLETD_PORT
|
||||
) {
|
||||
setViewingKeys(viewingKey)
|
||||
server(host, port)
|
||||
this.birthdayHeight = birthdayHeight
|
||||
}
|
||||
|
||||
fun new(
|
||||
seed: ByteArray,
|
||||
host: String = ZcashSdk.DEFAULT_LIGHTWALLETD_HOST,
|
||||
port: Int = ZcashSdk.DEFAULT_LIGHTWALLETD_PORT
|
||||
) {
|
||||
setSeed(seed)
|
||||
server(host, port)
|
||||
newWalletBirthday()
|
||||
}
|
||||
|
||||
fun new(
|
||||
viewingKey: String,
|
||||
host: String = ZcashSdk.DEFAULT_LIGHTWALLETD_HOST,
|
||||
port: Int = ZcashSdk.DEFAULT_LIGHTWALLETD_PORT
|
||||
) {
|
||||
setViewingKeys(viewingKey)
|
||||
server(host, port)
|
||||
newWalletBirthday()
|
||||
}
|
||||
|
||||
|
|
|
@ -231,7 +231,10 @@ class SdkSynchronizer internal constructor(
|
|||
override suspend fun changeServer(host: String, port: Int, errorHandler: (Throwable) -> Unit) {
|
||||
val info =
|
||||
(processor.downloader.lightWalletService as LightWalletGrpcService).connectionInfo
|
||||
processor.downloader.changeService(LightWalletGrpcService(info.appContext, host, port))
|
||||
processor.downloader.changeService(
|
||||
LightWalletGrpcService(info.appContext, host, port),
|
||||
errorHandler
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
@ -305,6 +308,15 @@ class SdkSynchronizer internal constructor(
|
|||
if (error.cause?.cause != null) twig("******** caused by ${error.cause?.cause}")
|
||||
twig("********")
|
||||
|
||||
if (onCriticalErrorHandler == null) {
|
||||
twig(
|
||||
"WARNING: a critical error occurred but no callback is registered to be notified " +
|
||||
"of critical errors! THIS IS PROBABLY A MISTAKE. To respond to these " +
|
||||
"errors (perhaps to update the UI or alert the user) set " +
|
||||
"synchronizer.onCriticalErrorHandler to a non-null value."
|
||||
)
|
||||
}
|
||||
|
||||
onCriticalErrorHandler?.invoke(error)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cash.z.ecc.android.sdk.block
|
||||
|
||||
import cash.z.ecc.android.sdk.exception.LightWalletException
|
||||
import cash.z.ecc.android.sdk.ext.tryCatchWith
|
||||
import cash.z.ecc.android.sdk.ext.tryWarn
|
||||
import cash.z.ecc.android.sdk.service.LightWalletService
|
||||
import cash.z.wallet.sdk.rpc.Service
|
||||
|
|
|
@ -80,11 +80,6 @@ sealed class BirthdayException(message: String, cause: Throwable? = null) : SdkE
|
|||
class MissingBirthdayFilesException(directory: String) : BirthdayException(
|
||||
"Cannot initialize wallet because no birthday files were found in the $directory directory."
|
||||
)
|
||||
class MissingBirthdayException(val alias: String) : BirthdayException(
|
||||
"Failed to initialize wallet with alias=$alias because its birthday could not be found." +
|
||||
" Verify the alias or perhaps a new wallet should be created, instead."
|
||||
)
|
||||
|
||||
class ExactBirthdayNotFoundException(height: Int, nearestMatch: Int? = null): BirthdayException(
|
||||
"Unable to find birthday that exactly matches $height.${
|
||||
if (nearestMatch != null)
|
||||
|
@ -108,6 +103,18 @@ sealed class InitializerException(message: String, cause: Throwable? = null) :
|
|||
class FalseStart(cause: Throwable?) : InitializerException("Failed to initialize accounts due to: $cause", cause)
|
||||
class AlreadyInitializedException(cause: Throwable, dbPath: String) : InitializerException("Failed to initialize the blocks table" +
|
||||
" because it already exists in $dbPath", cause)
|
||||
object MissingBirthdayException : InitializerException(
|
||||
"Expected a birthday for this wallet but failed to find one. This usually means that " +
|
||||
"wallet setup did not happen correctly. A workaround might be to interpret the " +
|
||||
"birthday, based on the contents of the wallet data but it is probably better " +
|
||||
"not to mask this error because the root issue should be addressed."
|
||||
)
|
||||
object MissingViewingKeyException : InitializerException(
|
||||
"Expected a viewingKey for this wallet but failed to find one. This usually means that " +
|
||||
"wallet setup happened incorrectly. A workaround might be to derive the " +
|
||||
"viewingKey from the seed or seedPhrase, if they exist, but it is probably " +
|
||||
"better not to mask this error because the root issue should be addressed."
|
||||
)
|
||||
object DatabasePathException :
|
||||
InitializerException("Critical failure to locate path for storing databases. Perhaps this" +
|
||||
" device prevents apps from storing data? We cannot initialize the wallet unless" +
|
||||
|
|
|
@ -13,14 +13,14 @@ use zcash_primitives::{merkle_tree::CommitmentTree, sapling::Node};
|
|||
#[cfg(feature = "mainnet")]
|
||||
const START_HEIGHT: u64 = 419200;
|
||||
#[cfg(feature = "mainnet")]
|
||||
const LIGHTWALLETD_HOST: &str = "lightwalletd.z.cash";
|
||||
const LIGHTWALLETD_HOST: &str = "lightwalletd.electriccoin.co";
|
||||
#[cfg(feature = "mainnet")]
|
||||
const NETWORK: &str = "mainnet";
|
||||
|
||||
#[cfg(not(feature = "mainnet"))]
|
||||
const START_HEIGHT: u64 = 280000;
|
||||
#[cfg(not(feature = "mainnet"))]
|
||||
const LIGHTWALLETD_HOST: &str = "lightwalletd.testnet.z.cash";
|
||||
const LIGHTWALLETD_HOST: &str = "lightwalletd.testnet.electriccoin.co";
|
||||
#[cfg(not(feature = "mainnet"))]
|
||||
const NETWORK: &str = "testnet";
|
||||
|
||||
|
|
|
@ -711,9 +711,9 @@ pub unsafe extern "C" fn Java_cash_z_ecc_android_sdk_tool_DerivationTool_deriveT
|
|||
let secp = Secp256k1::new();
|
||||
let pk = PublicKey::from_secret_key(&secp, &address_sk);
|
||||
let mut hash160 = ripemd160::Ripemd160::new();
|
||||
hash160.input(Sha256::digest(&pk.serialize()[..].to_vec()));
|
||||
hash160.update(Sha256::digest(&pk.serialize()[..].to_vec()));
|
||||
let address_string = hash160
|
||||
.result()
|
||||
.finalize()
|
||||
.to_base58check(&B58_PUBKEY_ADDRESS_PREFIX, &[]);
|
||||
|
||||
let output = env
|
||||
|
|
Loading…
Reference in New Issue