zcash-android-wallet-sdk / cash.z.wallet.sdk / Initializer

Initializer

class Initializer

Responsible for initialization, which can be considered as setup that must happen before synchronizing begins. This begins with one of three actions, a call to either new, import or open, where the last option is the most common case--when a user is opening a wallet they have used before on this device.

Parameters

appContext - the application context, used to extract the storage paths for the databases and param files. A reference to the context is not held beyond initialization.

host - the host that the synchronizer should use.

port - the port that the synchronizer should use when connecting to the host.

alias - the alias to use for this synchronizer. Think of it as a unique name that allows multiple synchronizers to function in the same app. The alias is mapped to database names for the cache and data DBs. This value is optional and is usually not required because most apps only need one synchronizer.

Types

DefaultBirthdayStore

Default implementation of the WalletBirthdayStore interface that loads checkpoints from the assets directory, in JSON format and stores the current birthday in shared preferences.

class DefaultBirthdayStore : WalletBirthdayStore

WalletBirthday

Model object for holding a wallet birthday. It is only used by this class.

data class WalletBirthday

WalletBirthdayStore

Interface for classes that can handle birthday storage. This makes it possible to bridge into existing storage logic. Instances of this interface can also be used as property delegates, which enables the syntax val birthday by birthdayStore

interface WalletBirthdayStore : ReadWriteProperty<R, WalletBirthday>

Constructors

<init>

Responsible for initialization, which can be considered as setup that must happen before synchronizing begins. This begins with one of three actions, a call to either new, import or open, where the last option is the most common case--when a user is opening a wallet they have used before on this device.

Initializer(appContext: Context, host: String = ZcashSdk.DEFAULT_LIGHTWALLETD_HOST, port: Int = ZcashSdk.DEFAULT_LIGHTWALLETD_PORT, alias: String = ZcashSdk.DEFAULT_DB_NAME_PREFIX)

Properties

birthday

The birthday that was ultimately used for initializing the accounts.

lateinit var birthday: WalletBirthday

host

the host that the synchronizer should use.

val host: String

isInitialized

Returns true when either 'open', 'new' or 'import' have already been called. Each of those functions calls initRustLibrary before returning. The entire point of the initializer is to setup everything necessary for the Synchronizer to function, which mainly boils down to loading the rust backend.

val isInitialized: Boolean

port

the port that the synchronizer should use when connecting to the host.

val port: Int

rustBackend

A wrapped version of cash.z.wallet.sdk.jni.RustBackendWelding that will be passed to the SDK when it is constructed. It provides access to all Librustzcash features and is configured based on this initializer.

lateinit var rustBackend: RustBackend

Functions

clear

Delete all local data related to this wallet, as though the wallet was never created on this device. Simply put, this call deletes the "cache db" and "data db."

fun clear(): Unit

deriveAddress

Given a seed and account index, return the associated address.

fun deriveAddress(seed: ByteArray, accountIndex: Int = 0): String

Given a viewing key string, return the associated address.

fun deriveAddress(viewingKey: String): String

deriveSpendingKeys

Given a seed and a number of accounts, return the associated spending keys. These keys can be used to derive the viewing keys.

fun deriveSpendingKeys(seed: ByteArray, numberOfAccounts: Int = 1): Array<String>

deriveViewingKey

Given a spending key, return the associated viewing key.

fun deriveViewingKey(spendingKey: String): String

deriveViewingKeys

Given a seed and a number of accounts, return the associated viewing keys.

fun deriveViewingKeys(seed: ByteArray, numberOfAccounts: Int = 1): Array<String>

import

Initialize a new wallet with the imported seed and birthday. It creates the required database tables and loads and configures the rustBackend property for use by all other components.

fun import(seed: ByteArray, previousWalletBirthday: WalletBirthday, clearCacheDb: Boolean = false, clearDataDb: Boolean = false): Array<String>

new

Initialize a new wallet with the given seed and birthday. It creates the required database tables and loads and configures the rustBackend property for use by all other components.

fun new(seed: ByteArray, newWalletBirthday: WalletBirthday, numberOfAccounts: Int = 1, clearCacheDb: Boolean = false, clearDataDb: Boolean = false): Array<String>

open

Loads the rust library and previously used birthday for use by all other components. This is the most common use case for the initializer--reopening a wallet that was previously created.

fun open(birthday: WalletBirthday): Initializer

Companion Object Functions

cacheDbPath

Returns the path to the cache database that would correspond to the given alias.

fun cacheDbPath(appContext: Context, alias: String): String

dataDbPath

Returns the path to the data database that would correspond to the given alias.

fun dataDbPath(appContext: Context, alias: String): String