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

91 lines
3.6 KiB
Kotlin
Raw Normal View History

package cash.z.ecc.android.sdk.internal.repository
import cash.z.ecc.android.sdk.internal.model.DbTransactionOverview
import cash.z.ecc.android.sdk.internal.model.EncodedTransaction
import cash.z.ecc.android.sdk.internal.model.OutputProperties
import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.FirstClassByteArray
2022-10-31 12:27:34 -07:00
import cash.z.ecc.android.sdk.model.TransactionRecipient
2019-11-01 13:25:28 -07:00
import kotlinx.coroutines.flow.Flow
2020-02-27 00:25:07 -08:00
/**
* Repository of wallet transactions, providing an agnostic interface to the underlying information.
*/
[#366] Fix Detekt warnings * Disable baseline file. Too many functions. * CurrencyFormatter.kt suppress too many functions * PersistentTransactionManager.kt suppress too many functions * OutboundTransactionManager suppress too many functions * Suppress long parameter list * Too many functions * Add log to avoid empty block warning * Fix several magic number warnings * Solve max line length warnings * Solve max line length warnings * Suppress too long method warnings * Suppress too complex method warnings * Suppress large class warning * Fixed empty catch block * Changed directory path to the file * Fix too generic and swallowed exception * Fix print stack trace warning * Suppressed single top level file name declaration * Change parameters name * Suppress Spread operator warning * Remove unused private code * Add Locale to suppress default locale used warning * Solve several forbidden TODOs warnings * Fixed another max line length warning * Simplify return statement * Suppress class to object change * Make DemoConstants variables const * Use error() instead of throwing an IllegalStateException * Solve too complex condition * Suppress intentionally generic and swallowed exception * Suppress TooGenericExceptionCaught * Solve or suppress several TooGenericExceptionCaught * Fix swallowed exception * Suppress warning TooGenericExceptionCaught of PersistentTransactionManager * Suppress warning TooGenericExceptionCaught of WalletTransactionEncoder * Suppress TooGenericExceptionCaught of SdkSynchronizer * Suppress TooGenericExceptionCaught in SaplingParamTool * Suppress TooGenericExceptionCaught in CompactBlockDownloader * Suppress TooGenericExceptionCaught in CheckpointTool * Fix TooGenericExceptionCaught in WalletService * Suppress TooGenericExceptionCaught in DerivedDataDb * Suppress TooGenericExceptionCaught in CompactBlockProcessor * Apply ktlint format after all the previous changes * Remove detekt baseline file * Set Android studio right margin * Address comments from review * Suppress failing tests on CI
2022-08-23 06:49:00 -07:00
@Suppress("TooManyFunctions")
internal interface DerivedDataRepository {
/**
* The height of the first transaction that hasn't been enhanced yet.
*
* @return the height of the first un-enhanced transaction in the repository, or null in case of all transaction
* enhanced or no entry found
*/
suspend fun firstUnenhancedHeight(): BlockHeight?
/**
* Find the encoded transaction associated with the given id.
*
* @param txId the id of the transaction to find.
*
* @return the transaction or null when it cannot be found.
*/
suspend fun findEncodedTransactionByTxId(txId: FirstClassByteArray): EncodedTransaction?
/**
* Find all the newly scanned transactions in the given range, including transactions (like
* change or those only identified by nullifiers) which should not appear in the UI. This method
* is intended for use after a scan, in order to collect all the transactions that were
* discovered and then enhance them with additional details. It returns a list to signal that
* the intention is not to add them to a recyclerview or otherwise show in the UI.
*
* @param blockHeightRange the range of blocks to check for transactions.
*
* @return a list of transactions that were mined in the given range, inclusive.
*/
suspend fun findNewTransactions(blockHeightRange: ClosedRange<BlockHeight>): List<DbTransactionOverview>
suspend fun getOldestTransaction(): DbTransactionOverview?
/**
* Find the mined height that matches the given raw tx_id in bytes. This is useful for matching
* a pending transaction with one that we've decrypted from the blockchain.
*
* @param rawTransactionId the id of the transaction to find.
*
* @return the mined height of the given transaction, if it is known to this wallet.
*/
suspend fun findMinedHeight(rawTransactionId: ByteArray): BlockHeight?
2019-11-01 13:25:28 -07:00
suspend fun findMatchingTransactionId(rawTransactionId: ByteArray): Long?
suspend fun getTransactionCount(): Long
2019-11-01 13:25:28 -07:00
/**
* Provides a way for other components to signal that the underlying data has been modified.
*/
fun invalidate()
suspend fun getAccountCount(): Int
2019-11-01 13:25:28 -07:00
//
// Transactions
//
/*
* Note there are two big limitations with this implementation:
* 1. Clients don't receive notification if the underlying data changes. A flow of flows could help there.
* 2. Pagination isn't supported. Although flow does a good job of allowing the data to be processed as a stream,
* that doesn't work so well in UI when users might scroll forwards/backwards.
*
* We'll come back to this and improve it in the future. This implementation is already an improvement over
* prior versions.
*/
val allTransactions: Flow<List<DbTransactionOverview>>
fun getOutputProperties(transactionId: FirstClassByteArray): Flow<OutputProperties>
2022-10-24 06:09:29 -07:00
fun getRecipients(transactionId: FirstClassByteArray): Flow<TransactionRecipient>
2022-10-31 12:27:34 -07:00
suspend fun close()
}