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

173 lines
5.4 KiB
Kotlin
Raw Normal View History

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
import cash.z.ecc.android.sdk.internal.model.SubtreeRoot
import cash.z.ecc.android.sdk.internal.model.TreeState
import cash.z.ecc.android.sdk.internal.model.WalletSummary
import cash.z.ecc.android.sdk.internal.model.ZcashProtocol
import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.FirstClassByteArray
import cash.z.ecc.android.sdk.model.Proposal
import cash.z.ecc.android.sdk.model.UnifiedSpendingKey
import cash.z.ecc.android.sdk.model.Zatoshi
import cash.z.ecc.android.sdk.model.ZcashNetwork
@Suppress("TooManyFunctions")
internal interface TypesafeBackend {
val network: ZcashNetwork
suspend fun createAccountAndGetSpendingKey(
seed: ByteArray,
treeState: TreeState,
recoverUntil: BlockHeight?
): UnifiedSpendingKey
suspend fun proposeTransferFromUri(
account: Account,
uri: String
): Proposal
@Suppress("LongParameterList")
suspend fun proposeTransfer(
account: Account,
to: String,
value: Long,
memo: ByteArray? = byteArrayOf()
): Proposal
suspend fun proposeShielding(
account: Account,
shieldingThreshold: Long,
memo: ByteArray? = byteArrayOf(),
transparentReceiver: String? = null
): Proposal?
suspend fun createProposedTransactions(
proposal: Proposal,
usk: UnifiedSpendingKey
): List<FirstClassByteArray>
suspend fun getCurrentAddress(account: Account): String
suspend fun listTransparentReceivers(account: Account): List<String>
fun getBranchIdForHeight(height: BlockHeight): Long
suspend fun getNearestRewindHeight(height: BlockHeight): BlockHeight
suspend fun rewindToHeight(height: BlockHeight)
suspend fun getLatestCacheHeight(): BlockHeight?
suspend fun findBlockMetadata(height: BlockHeight): JniBlockMeta?
suspend fun rewindBlockMetadataToHeight(height: BlockHeight)
suspend fun getDownloadedUtxoBalance(address: String): Zatoshi
@Suppress("LongParameterList")
suspend fun putUtxo(
tAddress: String,
txId: ByteArray,
index: Int,
script: ByteArray,
value: Long,
height: BlockHeight
)
suspend fun getMemoAsUtf8(
txId: ByteArray,
protocol: ZcashProtocol,
outputIndex: Int
): String?
@Throws(InitializeException::class)
suspend fun initDataDb(seed: ByteArray?)
/**
* @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: UInt,
saplingRoots: List<SubtreeRoot>,
orchardStartIndex: UInt,
orchardRoots: List<SubtreeRoot>,
)
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun updateChainTip(height: BlockHeight)
/**
* 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(): BlockHeight?
/**
* 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(): BlockHeight?
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun scanBlocks(
fromHeight: BlockHeight,
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: TreeState,
limit: Long
): ScanSummary
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun getWalletSummary(): WalletSummary?
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun suggestScanRanges(): List<ScanRange>
suspend fun decryptAndStoreTransaction(tx: ByteArray)
fun getSaplingReceiver(ua: String): String?
fun getTransparentReceiver(ua: String): String?
suspend fun initBlockMetaDb(): Int
/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun writeBlockMetadata(blockMetadata: List<JniBlockMeta>)
fun isValidSaplingAddr(addr: String): Boolean
fun isValidTransparentAddr(addr: String): Boolean
fun isValidUnifiedAddr(addr: String): Boolean
}