zcash-android-wallet-sdk/backend-lib/src/main/java/cash/z/ecc/android/sdk/internal/Backend.kt

207 lines
6.5 KiB
Kotlin
Raw Normal View History

package cash.z.ecc.android.sdk.internal
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
import cash.z.ecc.android.sdk.internal.model.JniScanRange
import cash.z.ecc.android.sdk.internal.model.JniScanSummary
import cash.z.ecc.android.sdk.internal.model.JniSubtreeRoot
import cash.z.ecc.android.sdk.internal.model.JniUnifiedSpendingKey
import cash.z.ecc.android.sdk.internal.model.JniWalletSummary
import cash.z.ecc.android.sdk.internal.model.ProposalUnsafe
/**
* Contract defining the exposed capabilities of the Rust backend.
* This is what welds the SDK to the Rust layer.
* It is not documented because it is not intended to be used, directly.
* Instead, use the synchronizer or one of its subcomponents.
*/
@Suppress("TooManyFunctions")
interface Backend {
val networkId: Int
suspend fun initBlockMetaDb(): Int
@Suppress("LongParameterList")
suspend fun proposeTransfer(
account: Int,
to: String,
value: Long,
memo: ByteArray? = byteArrayOf()
): ProposalUnsafe
suspend fun proposeTransferFromUri(
account: Int,
uri: String
): ProposalUnsafe
suspend fun proposeShielding(
account: Int,
shieldingThreshold: Long,
memo: ByteArray? = byteArrayOf(),
transparentReceiver: String? = null
): ProposalUnsafe?
suspend fun createProposedTransactions(
proposal: ProposalUnsafe,
unifiedSpendingKey: ByteArray
): List<ByteArray>
suspend fun decryptAndStoreTransaction(tx: ByteArray)
/**
* Sets up the internal structure of the data database.
*
* 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
Feature branch for SDK 2.1.0 (#1411) * CompactBlockProcessor: Remove `withDownload` parameter * backend-lib: Migrate to latest in-progress revision of Rust crates Includes changes to how accounts are stored and referenced. We now need to remember and provide the seed fingerprint; for now, given that we know we only create derived accounts from a single seed, we search for an account with a matching ZIP 32 account index. * backend-lib: Add `Backend.isSeedRelevantToWallet` * Remove nullability of DownloadSuccess param * Comment update * Fix Detekt warnings * backend-lib: Migrate to latest in-progress revision of Rust crates Includes some renames, and a built-in seed relevancy API that we now use. * Separate tree state fetching - Added continuable retry logic * Integrate Orchard support Closes Electric-Coin-Company/zcash-android-wallet-sdk#528. Closes Electric-Coin-Company/zcash-android-wallet-sdk#761. * Detekt warnings fix * Fix unit tests * Update `TxOutputsView` to use correct column names. (#1425) * Return an error instead of a panic in the case of data corruption. (#1426) This removes an `expect` call that risked crashing the app in the case of database corruption, potentially hiding other bugs. * Include `orchardSubtreeRootList` in final check * Revert `orchardSubtreeRootList` check Explanation comment added * Changelog update * Update to zcash_client_sqlite version 0.10.3 (#1428) --------- Co-authored-by: Honza <rychnovsky.honza@gmail.com> Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
2024-04-09 04:49:52 -07:00
* requested migrations, 2 if the provided seed is not relevant to any of the
* derived accounts in the wallet.
*
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun initDataDb(seed: ByteArray?): Int
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun createAccount(
seed: ByteArray,
treeState: ByteArray,
recoverUntil: Long?
): JniUnifiedSpendingKey
Feature branch for SDK 2.1.0 (#1411) * CompactBlockProcessor: Remove `withDownload` parameter * backend-lib: Migrate to latest in-progress revision of Rust crates Includes changes to how accounts are stored and referenced. We now need to remember and provide the seed fingerprint; for now, given that we know we only create derived accounts from a single seed, we search for an account with a matching ZIP 32 account index. * backend-lib: Add `Backend.isSeedRelevantToWallet` * Remove nullability of DownloadSuccess param * Comment update * Fix Detekt warnings * backend-lib: Migrate to latest in-progress revision of Rust crates Includes some renames, and a built-in seed relevancy API that we now use. * Separate tree state fetching - Added continuable retry logic * Integrate Orchard support Closes Electric-Coin-Company/zcash-android-wallet-sdk#528. Closes Electric-Coin-Company/zcash-android-wallet-sdk#761. * Detekt warnings fix * Fix unit tests * Update `TxOutputsView` to use correct column names. (#1425) * Return an error instead of a panic in the case of data corruption. (#1426) This removes an `expect` call that risked crashing the app in the case of database corruption, potentially hiding other bugs. * Include `orchardSubtreeRootList` in final check * Revert `orchardSubtreeRootList` check Explanation comment added * Changelog update * Update to zcash_client_sqlite version 0.10.3 (#1428) --------- Co-authored-by: Honza <rychnovsky.honza@gmail.com> Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
2024-04-09 04:49:52 -07:00
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun isSeedRelevantToAnyDerivedAccounts(seed: ByteArray): Boolean
fun isValidSaplingAddr(addr: String): Boolean
fun isValidTransparentAddr(addr: String): Boolean
fun isValidUnifiedAddr(addr: String): Boolean
suspend fun getCurrentAddress(account: Int): String
fun getTransparentReceiver(ua: String): String?
fun getSaplingReceiver(ua: String): String?
suspend fun listTransparentReceivers(account: Int): List<String>
fun getBranchIdForHeight(height: Long): Long
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun getMemoAsUtf8(
txId: ByteArray,
protocol: Int,
outputIndex: Int
): String?
suspend fun getNearestRewindHeight(height: Long): Long
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun rewindToHeight(height: Long)
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
Feature branch for SDK 2.1.0 (#1411) * CompactBlockProcessor: Remove `withDownload` parameter * backend-lib: Migrate to latest in-progress revision of Rust crates Includes changes to how accounts are stored and referenced. We now need to remember and provide the seed fingerprint; for now, given that we know we only create derived accounts from a single seed, we search for an account with a matching ZIP 32 account index. * backend-lib: Add `Backend.isSeedRelevantToWallet` * Remove nullability of DownloadSuccess param * Comment update * Fix Detekt warnings * backend-lib: Migrate to latest in-progress revision of Rust crates Includes some renames, and a built-in seed relevancy API that we now use. * Separate tree state fetching - Added continuable retry logic * Integrate Orchard support Closes Electric-Coin-Company/zcash-android-wallet-sdk#528. Closes Electric-Coin-Company/zcash-android-wallet-sdk#761. * Detekt warnings fix * Fix unit tests * Update `TxOutputsView` to use correct column names. (#1425) * Return an error instead of a panic in the case of data corruption. (#1426) This removes an `expect` call that risked crashing the app in the case of database corruption, potentially hiding other bugs. * Include `orchardSubtreeRootList` in final check * Revert `orchardSubtreeRootList` check Explanation comment added * Changelog update * Update to zcash_client_sqlite version 0.10.3 (#1428) --------- Co-authored-by: Honza <rychnovsky.honza@gmail.com> Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
2024-04-09 04:49:52 -07:00
suspend fun putSubtreeRoots(
saplingStartIndex: Long,
saplingRoots: List<JniSubtreeRoot>,
orchardStartIndex: Long,
orchardRoots: List<JniSubtreeRoot>,
)
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun updateChainTip(height: Long)
/**
* Returns the height to which the wallet has been fully scanned.
*
* This is the height for which the wallet has fully trial-decrypted this and all
* preceding blocks above the wallet's birthday height.
*
* @return The height to which the wallet has been fully scanned, or Null if no blocks have been scanned.
* @throws RuntimeException as a common indicator of the operation failure
*/
suspend fun getFullyScannedHeight(): Long?
/**
* Returns the maximum height that the wallet has scanned.
*
* If the wallet is fully synced, this will be equivalent to `getFullyScannedHeight`;
* otherwise the maximal scanned height is likely to be greater than the fully scanned
* height due to the fact that out-of-order scanning can leave gaps.
*
* @return The maximum height that the wallet has scanned, or Null if no blocks have been scanned.
* @throws RuntimeException as a common indicator of the operation failure
*/
suspend fun getMaxScannedHeight(): Long?
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun getWalletSummary(): JniWalletSummary?
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun suggestScanRanges(): List<JniScanRange>
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun scanBlocks(
fromHeight: Long,
Feature branch for SDK 2.1.0 (#1411) * CompactBlockProcessor: Remove `withDownload` parameter * backend-lib: Migrate to latest in-progress revision of Rust crates Includes changes to how accounts are stored and referenced. We now need to remember and provide the seed fingerprint; for now, given that we know we only create derived accounts from a single seed, we search for an account with a matching ZIP 32 account index. * backend-lib: Add `Backend.isSeedRelevantToWallet` * Remove nullability of DownloadSuccess param * Comment update * Fix Detekt warnings * backend-lib: Migrate to latest in-progress revision of Rust crates Includes some renames, and a built-in seed relevancy API that we now use. * Separate tree state fetching - Added continuable retry logic * Integrate Orchard support Closes Electric-Coin-Company/zcash-android-wallet-sdk#528. Closes Electric-Coin-Company/zcash-android-wallet-sdk#761. * Detekt warnings fix * Fix unit tests * Update `TxOutputsView` to use correct column names. (#1425) * Return an error instead of a panic in the case of data corruption. (#1426) This removes an `expect` call that risked crashing the app in the case of database corruption, potentially hiding other bugs. * Include `orchardSubtreeRootList` in final check * Revert `orchardSubtreeRootList` check Explanation comment added * Changelog update * Update to zcash_client_sqlite version 0.10.3 (#1428) --------- Co-authored-by: Honza <rychnovsky.honza@gmail.com> Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
2024-04-09 04:49:52 -07:00
fromState: ByteArray,
limit: Long
): JniScanSummary
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun writeBlockMetadata(blockMetadata: List<JniBlockMeta>)
/**
* @return The latest height in the CompactBlock cache metadata DB, or Null if no blocks have been cached.
*/
suspend fun getLatestCacheHeight(): Long?
suspend fun findBlockMetadata(height: Long): JniBlockMeta?
suspend fun rewindBlockMetadataToHeight(height: Long)
suspend fun getTotalTransparentBalance(address: String): Long
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Suppress("LongParameterList")
@Throws(RuntimeException::class)
suspend fun putUtxo(
tAddress: String,
txId: ByteArray,
index: Int,
script: ByteArray,
value: Long,
height: Long
)
}