2020-06-10 00:08:19 -07:00
|
|
|
package cash.z.ecc.android.sdk.jni
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2022-09-06 03:44:33 -07:00
|
|
|
import cash.z.ecc.android.sdk.internal.SaplingParamTool
|
2021-10-21 13:05:02 -07:00
|
|
|
import cash.z.ecc.android.sdk.internal.SdkDispatchers
|
|
|
|
import cash.z.ecc.android.sdk.internal.ext.deleteSuspend
|
2022-07-12 05:40:09 -07:00
|
|
|
import cash.z.ecc.android.sdk.internal.model.Checkpoint
|
2021-11-18 04:10:30 -08:00
|
|
|
import cash.z.ecc.android.sdk.internal.twig
|
2022-07-12 05:40:09 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.BlockHeight
|
2022-09-27 06:01:53 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.UnifiedSpendingKey
|
2022-07-07 05:52:07 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.WalletBalance
|
2022-06-21 16:34:42 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.Zatoshi
|
2022-08-02 06:29:09 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.ZcashNetwork
|
2021-03-31 23:23:41 -07:00
|
|
|
import cash.z.ecc.android.sdk.tool.DerivationTool
|
2022-08-04 10:09:19 -07:00
|
|
|
import cash.z.ecc.android.sdk.type.UnifiedFullViewingKey
|
2021-10-21 13:05:02 -07:00
|
|
|
import kotlinx.coroutines.withContext
|
2019-10-21 03:26:02 -07:00
|
|
|
import java.io.File
|
2019-05-23 21:37:17 -07:00
|
|
|
|
|
|
|
/**
|
2019-09-26 09:58:37 -07:00
|
|
|
* Serves as the JNI boundary between the Kotlin and Rust layers. Functions in this class should
|
|
|
|
* not be called directly by code outside of the SDK. Instead, one of the higher-level components
|
|
|
|
* should be used such as Wallet.kt or CompactBlockProcessor.kt.
|
2019-05-23 21:37:17 -07:00
|
|
|
*/
|
2022-08-23 06:49:00 -07:00
|
|
|
@Suppress("TooManyFunctions")
|
2022-07-12 05:40:09 -07:00
|
|
|
internal class RustBackend private constructor(
|
|
|
|
override val network: ZcashNetwork,
|
|
|
|
val birthdayHeight: BlockHeight,
|
2022-08-12 08:05:00 -07:00
|
|
|
val dataDbFile: File,
|
|
|
|
val cacheDbFile: File,
|
2022-09-06 03:44:33 -07:00
|
|
|
override val saplingParamDir: File
|
2022-07-12 05:40:09 -07:00
|
|
|
) : RustBackendWelding {
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
suspend fun clear(clearCacheDb: Boolean = true, clearDataDb: Boolean = true) {
|
2020-02-11 16:56:31 -08:00
|
|
|
if (clearCacheDb) {
|
2020-09-11 00:33:25 -07:00
|
|
|
twig("Deleting the cache database!")
|
2022-08-12 08:05:00 -07:00
|
|
|
cacheDbFile.deleteSuspend()
|
2020-02-11 16:56:31 -08:00
|
|
|
}
|
|
|
|
if (clearDataDb) {
|
2020-09-11 00:33:25 -07:00
|
|
|
twig("Deleting the data database!")
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.deleteSuspend()
|
2020-02-11 16:56:31 -08:00
|
|
|
}
|
2019-10-21 03:26:02 -07:00
|
|
|
}
|
|
|
|
|
2019-09-26 09:58:37 -07:00
|
|
|
//
|
|
|
|
// Wrapper Functions
|
|
|
|
//
|
|
|
|
|
2022-09-20 17:41:43 -07:00
|
|
|
override suspend fun initDataDb(seed: ByteArray?) = withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
initDataDb(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-09-20 17:41:43 -07:00
|
|
|
seed,
|
2021-10-21 13:05:02 -07:00
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2022-09-27 06:01:53 -07:00
|
|
|
override suspend fun createAccount(seed: ByteArray): UnifiedSpendingKey {
|
|
|
|
return withContext(SdkDispatchers.DATABASE_IO) {
|
|
|
|
createAccount(
|
|
|
|
dataDbFile.absolutePath,
|
|
|
|
seed,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-04 10:09:19 -07:00
|
|
|
override suspend fun initAccountsTable(vararg keys: UnifiedFullViewingKey): Boolean {
|
|
|
|
val ufvks = Array(keys.size) { keys[it].encoding }
|
|
|
|
|
2022-01-19 10:39:07 -08:00
|
|
|
return withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
initAccountsTableWithKeys(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-08-04 10:09:19 -07:00
|
|
|
ufvks,
|
2021-10-21 13:05:02 -07:00
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2021-03-31 23:23:41 -07:00
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override suspend fun initAccountsTable(
|
2019-11-01 13:25:28 -07:00
|
|
|
seed: ByteArray,
|
|
|
|
numberOfAccounts: Int
|
2022-08-04 10:09:19 -07:00
|
|
|
): Array<UnifiedFullViewingKey> {
|
|
|
|
return DerivationTool.deriveUnifiedFullViewingKeys(seed, network, numberOfAccounts).apply {
|
2022-08-23 06:49:00 -07:00
|
|
|
@Suppress("SpreadOperator")
|
2021-03-31 23:23:41 -07:00
|
|
|
initAccountsTable(*this)
|
|
|
|
}
|
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override suspend fun initBlocksTable(
|
2022-07-12 05:40:09 -07:00
|
|
|
checkpoint: Checkpoint
|
2019-11-01 13:25:28 -07:00
|
|
|
): Boolean {
|
2022-01-19 10:39:07 -08:00
|
|
|
return withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
initBlocksTable(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-07-12 05:40:09 -07:00
|
|
|
checkpoint.height.value,
|
|
|
|
checkpoint.hash,
|
|
|
|
checkpoint.epochSeconds,
|
|
|
|
checkpoint.tree,
|
2021-10-21 13:05:02 -07:00
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2019-11-01 13:25:28 -07:00
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2022-09-19 11:34:10 -07:00
|
|
|
override suspend fun getCurrentAddress(account: Int) =
|
2022-06-21 16:34:42 -07:00
|
|
|
withContext(SdkDispatchers.DATABASE_IO) {
|
2022-09-19 11:34:10 -07:00
|
|
|
getCurrentAddress(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-06-21 16:34:42 -07:00
|
|
|
account,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2021-02-17 13:07:57 -08:00
|
|
|
|
2022-10-06 10:40:49 -07:00
|
|
|
override fun getTransparentReceiver(ua: String) = getTransparentReceiverForUnifiedAddress(ua)
|
|
|
|
|
|
|
|
override fun getSaplingReceiver(ua: String) = getSaplingReceiverForUnifiedAddress(ua)
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2022-06-21 16:34:42 -07:00
|
|
|
override suspend fun getBalance(account: Int): Zatoshi {
|
|
|
|
val longValue = withContext(SdkDispatchers.DATABASE_IO) {
|
|
|
|
getBalance(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-06-21 16:34:42 -07:00
|
|
|
account,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Zatoshi(longValue)
|
2021-10-21 13:05:02 -07:00
|
|
|
}
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2022-06-21 16:34:42 -07:00
|
|
|
override suspend fun getVerifiedBalance(account: Int): Zatoshi {
|
|
|
|
val longValue = withContext(SdkDispatchers.DATABASE_IO) {
|
|
|
|
getVerifiedBalance(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-06-21 16:34:42 -07:00
|
|
|
account,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Zatoshi(longValue)
|
2021-10-21 13:05:02 -07:00
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override suspend fun getReceivedMemoAsUtf8(idNote: Long) =
|
2022-06-21 16:34:42 -07:00
|
|
|
withContext(SdkDispatchers.DATABASE_IO) {
|
|
|
|
getReceivedMemoAsUtf8(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-06-21 16:34:42 -07:00
|
|
|
idNote,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2022-01-19 10:39:07 -08:00
|
|
|
override suspend fun getSentMemoAsUtf8(idNote: Long) = withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
getSentMemoAsUtf8(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2021-10-21 13:05:02 -07:00
|
|
|
idNote,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2022-01-19 10:39:07 -08:00
|
|
|
override suspend fun validateCombinedChain() = withContext(SdkDispatchers.DATABASE_IO) {
|
2022-07-12 05:40:09 -07:00
|
|
|
val validationResult = validateCombinedChain(
|
2022-08-12 08:05:00 -07:00
|
|
|
cacheDbFile.absolutePath,
|
|
|
|
dataDbFile.absolutePath,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId = network.id
|
2021-10-21 13:05:02 -07:00
|
|
|
)
|
2022-07-12 05:40:09 -07:00
|
|
|
|
|
|
|
if (-1L == validationResult) {
|
|
|
|
null
|
|
|
|
} else {
|
|
|
|
BlockHeight.new(network, validationResult)
|
|
|
|
}
|
2021-10-21 13:05:02 -07:00
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2022-07-12 05:40:09 -07:00
|
|
|
override suspend fun getNearestRewindHeight(height: BlockHeight): BlockHeight =
|
2022-06-21 16:34:42 -07:00
|
|
|
withContext(SdkDispatchers.DATABASE_IO) {
|
2022-07-12 05:40:09 -07:00
|
|
|
BlockHeight.new(
|
|
|
|
network,
|
|
|
|
getNearestRewindHeight(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-07-12 05:40:09 -07:00
|
|
|
height.value,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
2022-06-21 16:34:42 -07:00
|
|
|
)
|
|
|
|
}
|
2021-04-14 15:44:17 -07:00
|
|
|
|
2021-04-09 18:25:21 -07:00
|
|
|
/**
|
|
|
|
* Deletes data for all blocks above the given height. Boils down to:
|
|
|
|
*
|
|
|
|
* DELETE FROM blocks WHERE height > ?
|
|
|
|
*/
|
2022-07-12 05:40:09 -07:00
|
|
|
override suspend fun rewindToHeight(height: BlockHeight) =
|
2022-06-21 16:34:42 -07:00
|
|
|
withContext(SdkDispatchers.DATABASE_IO) {
|
|
|
|
rewindToHeight(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-07-12 05:40:09 -07:00
|
|
|
height.value,
|
2022-06-21 16:34:42 -07:00
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override suspend fun scanBlocks(limit: Int): Boolean {
|
2022-10-14 18:39:18 -07:00
|
|
|
return withContext(SdkDispatchers.DATABASE_IO) {
|
|
|
|
scanBlocks(
|
|
|
|
cacheDbFile.absolutePath,
|
|
|
|
dataDbFile.absolutePath,
|
|
|
|
limit,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
2020-01-14 09:56:03 -08:00
|
|
|
}
|
|
|
|
}
|
2019-09-26 09:58:37 -07:00
|
|
|
|
2022-06-21 16:34:42 -07:00
|
|
|
override suspend fun decryptAndStoreTransaction(tx: ByteArray) =
|
|
|
|
withContext(SdkDispatchers.DATABASE_IO) {
|
|
|
|
decryptAndStoreTransaction(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-06-21 16:34:42 -07:00
|
|
|
tx,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2020-03-12 21:41:17 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override suspend fun createToAddress(
|
2022-09-29 10:04:00 -07:00
|
|
|
usk: UnifiedSpendingKey,
|
2019-09-26 09:58:37 -07:00
|
|
|
to: String,
|
|
|
|
value: Long,
|
2019-11-12 08:58:15 -08:00
|
|
|
memo: ByteArray?
|
2022-01-19 10:39:07 -08:00
|
|
|
): Long = withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
createToAddress(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-10-04 05:25:13 -07:00
|
|
|
usk.copyBytes(),
|
2021-10-21 13:05:02 -07:00
|
|
|
to,
|
|
|
|
value,
|
2021-02-17 13:07:57 -08:00
|
|
|
memo ?: ByteArray(0),
|
2022-09-06 03:44:33 -07:00
|
|
|
File(saplingParamDir, SaplingParamTool.SPEND_PARAM_FILE_NAME).absolutePath,
|
|
|
|
File(saplingParamDir, SaplingParamTool.OUTPUT_PARAM_FILE_NAME).absolutePath,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId = network.id
|
2021-02-17 13:07:57 -08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override suspend fun shieldToAddress(
|
2022-09-29 10:04:00 -07:00
|
|
|
usk: UnifiedSpendingKey,
|
2021-10-21 13:05:02 -07:00
|
|
|
memo: ByteArray?
|
|
|
|
): Long {
|
2022-08-12 08:05:00 -07:00
|
|
|
twig("TMP: shieldToAddress with db path: $dataDbFile, ${memo?.size}")
|
2022-01-19 10:39:07 -08:00
|
|
|
return withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
shieldToAddress(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2022-10-04 05:25:13 -07:00
|
|
|
usk.copyBytes(),
|
2021-10-21 13:05:02 -07:00
|
|
|
memo ?: ByteArray(0),
|
2022-09-06 03:44:33 -07:00
|
|
|
File(saplingParamDir, SaplingParamTool.SPEND_PARAM_FILE_NAME).absolutePath,
|
|
|
|
File(saplingParamDir, SaplingParamTool.OUTPUT_PARAM_FILE_NAME).absolutePath,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId = network.id
|
2021-10-21 13:05:02 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun putUtxo(
|
2021-02-17 13:07:57 -08:00
|
|
|
tAddress: String,
|
|
|
|
txId: ByteArray,
|
|
|
|
index: Int,
|
|
|
|
script: ByteArray,
|
|
|
|
value: Long,
|
2022-07-12 05:40:09 -07:00
|
|
|
height: BlockHeight
|
2022-01-19 10:39:07 -08:00
|
|
|
): Boolean = withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
putUtxo(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2021-10-21 13:05:02 -07:00
|
|
|
tAddress,
|
|
|
|
txId,
|
|
|
|
index,
|
|
|
|
script,
|
|
|
|
value,
|
2022-07-12 05:40:09 -07:00
|
|
|
height.value,
|
2021-10-21 13:05:02 -07:00
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2021-02-17 13:07:57 -08:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override suspend fun getDownloadedUtxoBalance(address: String): WalletBalance {
|
2022-01-19 10:39:07 -08:00
|
|
|
val verified = withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
getVerifiedTransparentBalance(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2021-10-21 13:05:02 -07:00
|
|
|
address,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2022-01-19 10:39:07 -08:00
|
|
|
val total = withContext(SdkDispatchers.DATABASE_IO) {
|
2021-10-21 13:05:02 -07:00
|
|
|
getTotalTransparentBalance(
|
2022-08-12 08:05:00 -07:00
|
|
|
dataDbFile.absolutePath,
|
2021-10-21 13:05:02 -07:00
|
|
|
address,
|
|
|
|
networkId = network.id
|
|
|
|
)
|
|
|
|
}
|
2022-06-21 16:34:42 -07:00
|
|
|
return WalletBalance(Zatoshi(total), Zatoshi(verified))
|
2021-02-17 13:07:57 -08:00
|
|
|
}
|
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override fun isValidShieldedAddr(addr: String) =
|
|
|
|
isValidShieldedAddress(addr, networkId = network.id)
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
override fun isValidTransparentAddr(addr: String) =
|
|
|
|
isValidTransparentAddress(addr, networkId = network.id)
|
2020-06-09 19:14:22 -07:00
|
|
|
|
2022-06-17 05:06:21 -07:00
|
|
|
override fun isValidUnifiedAddr(addr: String) =
|
|
|
|
isValidUnifiedAddress(addr, networkId = network.id)
|
|
|
|
|
2022-07-12 05:40:09 -07:00
|
|
|
override fun getBranchIdForHeight(height: BlockHeight): Long =
|
|
|
|
branchIdForHeight(height.value, networkId = network.id)
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2021-02-17 13:07:57 -08:00
|
|
|
// /**
|
|
|
|
// * This is a proof-of-concept for doing Local RPC, where we are effectively using the JNI
|
|
|
|
// * boundary as a grpc server. It is slightly inefficient in terms of both space and time but
|
|
|
|
// * given that it is all done locally, on the heap, it seems to be a worthwhile tradeoff because
|
|
|
|
// * it reduces the complexity and expands the capacity for the two layers to communicate.
|
|
|
|
// *
|
|
|
|
// * We're able to keep the "unsafe" byteArray functions private and wrap them in typeSafe
|
|
|
|
// * equivalents and, eventually, surface any parse errors (for now, errors are only logged).
|
|
|
|
// */
|
2022-08-23 06:49:00 -07:00
|
|
|
// override fun parseTransactionDataList(
|
|
|
|
// tdl: LocalRpcTypes.TransactionDataList
|
|
|
|
// ): LocalRpcTypes.TransparentTransactionList {
|
|
|
|
// return try {
|
|
|
|
// // serialize the list, send it over to rust and get back a serialized set of results that we parse out
|
|
|
|
// // and return
|
|
|
|
// return LocalRpcTypes.TransparentTransactionList.parseFrom(parseTransactionDataList(tdl.toByteArray()))
|
|
|
|
// } catch (t: Throwable) {
|
|
|
|
// twig("ERROR: failed to parse transaction data list due to: $t caused by: ${t.cause}")
|
|
|
|
// LocalRpcTypes.TransparentTransactionList.newBuilder().build()
|
|
|
|
// }
|
|
|
|
// }
|
2020-08-13 18:03:19 -07:00
|
|
|
|
2019-11-01 13:25:28 -07:00
|
|
|
/**
|
|
|
|
* Exposes all of the librustzcash functions along with helpers for loading the static library.
|
|
|
|
*/
|
|
|
|
companion object {
|
2021-10-21 13:05:02 -07:00
|
|
|
internal val rustLibraryLoader = NativeLibraryLoader("zcashwalletsdk")
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2020-09-21 19:43:50 -07:00
|
|
|
/**
|
|
|
|
* Loads the library and initializes path variables. Although it is best to only call this
|
|
|
|
* function once, it is idempotent.
|
|
|
|
*/
|
2021-10-21 13:05:02 -07:00
|
|
|
suspend fun init(
|
2022-09-06 03:44:33 -07:00
|
|
|
cacheDbFile: File,
|
|
|
|
dataDbFile: File,
|
|
|
|
saplingParamsDir: File,
|
2021-04-09 18:43:07 -07:00
|
|
|
zcashNetwork: ZcashNetwork,
|
2022-07-12 05:40:09 -07:00
|
|
|
birthdayHeight: BlockHeight
|
2020-09-21 19:43:50 -07:00
|
|
|
): RustBackend {
|
2021-10-21 13:05:02 -07:00
|
|
|
rustLibraryLoader.load()
|
|
|
|
|
2022-07-12 05:40:09 -07:00
|
|
|
return RustBackend(
|
|
|
|
zcashNetwork,
|
|
|
|
birthdayHeight,
|
2022-09-06 03:44:33 -07:00
|
|
|
dataDbFile = dataDbFile,
|
|
|
|
cacheDbFile = cacheDbFile,
|
|
|
|
saplingParamDir = saplingParamsDir
|
2022-07-12 05:40:09 -07:00
|
|
|
)
|
2020-09-21 19:43:50 -07:00
|
|
|
}
|
|
|
|
|
2021-07-29 10:23:45 -07:00
|
|
|
/**
|
|
|
|
* Forwards Rust logs to logcat. This is a function that is intended for debug purposes. All
|
|
|
|
* logs will be tagged with `cash.z.rust.logs`. Typically, a developer would clone
|
|
|
|
* librustzcash locally and then modify Cargo.toml in this project to point to their local
|
|
|
|
* build (see Cargo.toml for details). From there, they can add any log messages they want
|
|
|
|
* and have them surfaced into the Android logging system. By default, this behavior is
|
|
|
|
* disabled and this is the function that enables it. Initially only the logs in
|
|
|
|
* [src/main/rust/lib.rs] will appear and any additional logs would need to be added by the
|
|
|
|
* developer.
|
|
|
|
*/
|
|
|
|
fun enableRustLogs() = initLogs()
|
|
|
|
|
2019-11-01 13:25:28 -07:00
|
|
|
//
|
|
|
|
// External Functions
|
|
|
|
//
|
2019-06-04 07:15:19 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
2022-09-20 17:41:43 -07:00
|
|
|
private external fun initDataDb(dbDataPath: String, seed: ByteArray?, networkId: Int): Int
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun initAccountsTableWithKeys(
|
2020-09-11 00:23:08 -07:00
|
|
|
dbDataPath: String,
|
2022-08-04 10:09:19 -07:00
|
|
|
ufvks: Array<out String>,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2020-09-11 00:23:08 -07:00
|
|
|
): Boolean
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
2022-08-23 06:49:00 -07:00
|
|
|
@Suppress("LongParameterList")
|
2021-10-21 13:05:02 -07:00
|
|
|
private external fun initBlocksTable(
|
2019-11-01 13:25:28 -07:00
|
|
|
dbDataPath: String,
|
2022-07-12 05:40:09 -07:00
|
|
|
height: Long,
|
2019-11-01 13:25:28 -07:00
|
|
|
hash: String,
|
|
|
|
time: Long,
|
2021-04-09 18:43:07 -07:00
|
|
|
saplingTree: String,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2019-11-01 13:25:28 -07:00
|
|
|
): Boolean
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2022-09-27 06:01:53 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun createAccount(dbDataPath: String, seed: ByteArray, networkId: Int): UnifiedSpendingKey
|
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
2022-09-19 11:34:10 -07:00
|
|
|
private external fun getCurrentAddress(
|
2021-04-09 18:43:07 -07:00
|
|
|
dbDataPath: String,
|
|
|
|
account: Int,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-04-09 18:43:07 -07:00
|
|
|
): String
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2022-10-06 10:40:49 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun getTransparentReceiverForUnifiedAddress(ua: String): String?
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
private external fun getSaplingReceiverForUnifiedAddress(ua: String): String?
|
|
|
|
|
2022-09-29 10:04:00 -07:00
|
|
|
internal fun validateUnifiedSpendingKey(bytes: ByteArray) =
|
|
|
|
isValidSpendingKey(bytes)
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
private external fun isValidSpendingKey(bytes: ByteArray): Boolean
|
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun isValidShieldedAddress(addr: String, networkId: Int): Boolean
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun isValidTransparentAddress(addr: String, networkId: Int): Boolean
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2022-06-17 05:06:21 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun isValidUnifiedAddress(addr: String, networkId: Int): Boolean
|
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun getBalance(dbDataPath: String, account: Int, networkId: Int): Long
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun getVerifiedBalance(
|
|
|
|
dbDataPath: String,
|
|
|
|
account: Int,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-04-09 18:43:07 -07:00
|
|
|
): Long
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun getReceivedMemoAsUtf8(
|
|
|
|
dbDataPath: String,
|
|
|
|
idNote: Long,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2022-10-24 06:09:29 -07:00
|
|
|
): String?
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun getSentMemoAsUtf8(
|
|
|
|
dbDataPath: String,
|
|
|
|
dNote: Long,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2022-10-24 06:09:29 -07:00
|
|
|
): String?
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun validateCombinedChain(
|
|
|
|
dbCachePath: String,
|
|
|
|
dbDataPath: String,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2022-07-12 05:40:09 -07:00
|
|
|
): Long
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2021-04-14 15:44:17 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun getNearestRewindHeight(
|
|
|
|
dbDataPath: String,
|
2022-07-12 05:40:09 -07:00
|
|
|
height: Long,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2022-07-12 05:40:09 -07:00
|
|
|
): Long
|
2021-04-14 15:44:17 -07:00
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun rewindToHeight(
|
|
|
|
dbDataPath: String,
|
2022-07-12 05:40:09 -07:00
|
|
|
height: Long,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-04-09 18:43:07 -07:00
|
|
|
): Boolean
|
2019-11-01 13:25:28 -07:00
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun scanBlocks(
|
|
|
|
dbCachePath: String,
|
|
|
|
dbDataPath: String,
|
|
|
|
limit: Int,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-04-09 18:43:07 -07:00
|
|
|
): Boolean
|
2020-01-14 09:56:03 -08:00
|
|
|
|
2021-04-09 18:43:07 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun decryptAndStoreTransaction(
|
|
|
|
dbDataPath: String,
|
|
|
|
tx: ByteArray,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-04-09 18:43:07 -07:00
|
|
|
)
|
2020-03-12 21:41:17 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
2022-08-23 06:49:00 -07:00
|
|
|
@Suppress("LongParameterList")
|
2021-10-21 13:05:02 -07:00
|
|
|
private external fun createToAddress(
|
2019-11-01 13:25:28 -07:00
|
|
|
dbDataPath: String,
|
2022-09-29 10:04:00 -07:00
|
|
|
usk: ByteArray,
|
2019-11-01 13:25:28 -07:00
|
|
|
to: String,
|
|
|
|
value: Long,
|
|
|
|
memo: ByteArray,
|
|
|
|
spendParamsPath: String,
|
2021-04-09 18:43:07 -07:00
|
|
|
outputParamsPath: String,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2019-11-01 13:25:28 -07:00
|
|
|
): Long
|
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
2022-05-18 18:04:30 -07:00
|
|
|
@Suppress("LongParameterList")
|
2021-10-21 13:05:02 -07:00
|
|
|
private external fun shieldToAddress(
|
2021-02-17 13:07:57 -08:00
|
|
|
dbDataPath: String,
|
2022-09-29 10:04:00 -07:00
|
|
|
usk: ByteArray,
|
2021-02-17 13:07:57 -08:00
|
|
|
memo: ByteArray,
|
|
|
|
spendParamsPath: String,
|
2021-04-09 18:43:07 -07:00
|
|
|
outputParamsPath: String,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-02-17 13:07:57 -08:00
|
|
|
): Long
|
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun initLogs()
|
2019-05-23 21:37:17 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
2022-07-12 05:40:09 -07:00
|
|
|
private external fun branchIdForHeight(height: Long, networkId: Int): Long
|
2020-08-13 18:03:19 -07:00
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
2022-08-23 06:49:00 -07:00
|
|
|
@Suppress("LongParameterList")
|
2021-10-21 13:05:02 -07:00
|
|
|
private external fun putUtxo(
|
2021-02-17 13:07:57 -08:00
|
|
|
dbDataPath: String,
|
|
|
|
tAddress: String,
|
|
|
|
txId: ByteArray,
|
|
|
|
index: Int,
|
|
|
|
script: ByteArray,
|
|
|
|
value: Long,
|
2022-07-12 05:40:09 -07:00
|
|
|
height: Long,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-02-17 13:07:57 -08:00
|
|
|
): Boolean
|
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun getVerifiedTransparentBalance(
|
2021-02-17 13:07:57 -08:00
|
|
|
pathDataDb: String,
|
2021-04-09 18:43:07 -07:00
|
|
|
taddr: String,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-02-17 13:07:57 -08:00
|
|
|
): Long
|
|
|
|
|
2021-10-21 13:05:02 -07:00
|
|
|
@JvmStatic
|
|
|
|
private external fun getTotalTransparentBalance(
|
2021-02-17 13:07:57 -08:00
|
|
|
pathDataDb: String,
|
2021-04-09 18:43:07 -07:00
|
|
|
taddr: String,
|
2022-06-23 05:31:02 -07:00
|
|
|
networkId: Int
|
2021-02-17 13:07:57 -08:00
|
|
|
): Long
|
2019-11-01 13:25:28 -07:00
|
|
|
}
|
2020-06-09 19:14:22 -07:00
|
|
|
}
|