2023-05-18 04:36:15 -07:00
|
|
|
package cash.z.ecc.android.sdk.internal
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
|
2023-07-11 08:17:44 -07:00
|
|
|
import cash.z.ecc.android.sdk.internal.model.JniScanRange
|
2023-07-18 14:39:26 -07:00
|
|
|
import cash.z.ecc.android.sdk.internal.model.JniSubtreeRoot
|
2023-05-18 04:36:15 -07:00
|
|
|
import cash.z.ecc.android.sdk.internal.model.JniUnifiedSpendingKey
|
2023-11-08 01:57:23 -08:00
|
|
|
import cash.z.ecc.android.sdk.internal.model.JniWalletSummary
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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")
|
2023-05-18 04:36:15 -07:00
|
|
|
interface Backend {
|
|
|
|
val networkId: Int
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
suspend fun initBlockMetaDb(): Int
|
|
|
|
|
|
|
|
@Suppress("LongParameterList")
|
|
|
|
suspend fun createToAddress(
|
|
|
|
account: Int,
|
|
|
|
unifiedSpendingKey: ByteArray,
|
|
|
|
to: String,
|
|
|
|
value: Long,
|
|
|
|
memo: ByteArray? = byteArrayOf()
|
2023-08-07 12:17:28 -07:00
|
|
|
): ByteArray
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
suspend fun shieldToAddress(
|
|
|
|
account: Int,
|
|
|
|
unifiedSpendingKey: ByteArray,
|
|
|
|
memo: ByteArray? = byteArrayOf()
|
2023-08-07 12:17:28 -07:00
|
|
|
): ByteArray
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
suspend fun decryptAndStoreTransaction(tx: ByteArray)
|
|
|
|
|
2023-09-07 09:00:34 -07:00
|
|
|
/**
|
|
|
|
* 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 requested migrations, or -1
|
|
|
|
* otherwise.
|
|
|
|
*
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
2023-04-10 07:35:40 -07:00
|
|
|
suspend fun initDataDb(seed: ByteArray?): Int
|
|
|
|
|
2023-09-06 06:24:27 -07:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
2024-01-04 12:21:32 -08:00
|
|
|
suspend fun createAccount(
|
|
|
|
seed: ByteArray,
|
|
|
|
treeState: ByteArray,
|
|
|
|
recoverUntil: Long?
|
|
|
|
): JniUnifiedSpendingKey
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
fun isValidShieldedAddr(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
|
|
|
|
|
2023-07-31 04:34:41 -07:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
2023-09-06 06:24:27 -07:00
|
|
|
@Throws(RuntimeException::class)
|
2024-01-04 12:21:32 -08:00
|
|
|
suspend fun getMemoAsUtf8(
|
|
|
|
txId: ByteArray,
|
|
|
|
outputIndex: Int
|
|
|
|
): String?
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
suspend fun getNearestRewindHeight(height: Long): Long
|
|
|
|
|
2023-06-09 01:29:33 -07:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
|
|
|
suspend fun rewindToHeight(height: Long)
|
2023-04-10 07:35:40 -07:00
|
|
|
|
2023-07-18 14:39:26 -07:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
|
|
|
suspend fun putSaplingSubtreeRoots(
|
|
|
|
startIndex: Long,
|
|
|
|
roots: List<JniSubtreeRoot>,
|
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
|
|
|
suspend fun updateChainTip(height: Long)
|
|
|
|
|
2023-09-06 12:28:45 -07:00
|
|
|
/**
|
|
|
|
* 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?
|
|
|
|
|
2023-09-05 18:54:59 -07:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
2023-11-08 01:57:23 -08:00
|
|
|
suspend fun getWalletSummary(): JniWalletSummary?
|
2023-09-05 18:54:59 -07:00
|
|
|
|
2023-06-09 01:29:33 -07:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
2023-07-11 08:17:44 -07:00
|
|
|
suspend fun suggestScanRanges(): List<JniScanRange>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
2024-01-04 12:21:32 -08:00
|
|
|
suspend fun scanBlocks(
|
|
|
|
fromHeight: Long,
|
|
|
|
limit: Long
|
|
|
|
)
|
2023-04-10 07:35:40 -07:00
|
|
|
|
2023-06-09 01:29:33 -07:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
|
|
|
@Throws(RuntimeException::class)
|
|
|
|
suspend fun writeBlockMetadata(blockMetadata: List<JniBlockMeta>)
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The latest height in the CompactBlock cache metadata DB, or Null if no blocks have been cached.
|
|
|
|
*/
|
2023-09-06 12:28:45 -07:00
|
|
|
suspend fun getLatestCacheHeight(): Long?
|
2023-04-10 07:35:40 -07:00
|
|
|
|
|
|
|
suspend fun findBlockMetadata(height: Long): JniBlockMeta?
|
|
|
|
|
|
|
|
suspend fun rewindBlockMetadataToHeight(height: Long)
|
|
|
|
|
|
|
|
suspend fun getVerifiedTransparentBalance(address: String): Long
|
2024-01-04 12:21:32 -08:00
|
|
|
|
2023-04-10 07:35:40 -07:00
|
|
|
suspend fun getTotalTransparentBalance(address: String): Long
|
|
|
|
|
2023-06-09 01:29:33 -07:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException as a common indicator of the operation failure
|
|
|
|
*/
|
2023-04-10 07:35:40 -07:00
|
|
|
@Suppress("LongParameterList")
|
2023-06-09 01:29:33 -07:00
|
|
|
@Throws(RuntimeException::class)
|
2023-04-10 07:35:40 -07:00
|
|
|
suspend fun putUtxo(
|
|
|
|
tAddress: String,
|
|
|
|
txId: ByteArray,
|
|
|
|
index: Int,
|
|
|
|
script: ByteArray,
|
|
|
|
value: Long,
|
2023-05-18 04:36:15 -07:00
|
|
|
height: Long
|
2023-06-09 01:29:33 -07:00
|
|
|
)
|
2023-04-10 07:35:40 -07:00
|
|
|
}
|