2022-10-19 13:52:54 -07:00
|
|
|
package cash.z.ecc.android.sdk.internal.repository
|
2019-06-14 16:24:52 -07:00
|
|
|
|
2022-07-12 05:40:09 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.BlockHeight
|
2023-01-11 07:18:33 -08:00
|
|
|
import cash.z.wallet.sdk.internal.rpc.CompactFormats
|
2019-06-14 16:24:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for storing compact blocks.
|
|
|
|
*/
|
2022-10-19 13:52:54 -07:00
|
|
|
interface CompactBlockRepository {
|
2019-06-14 16:24:52 -07:00
|
|
|
/**
|
|
|
|
* Gets the highest block that is currently stored.
|
2020-02-27 00:25:07 -08:00
|
|
|
*
|
|
|
|
* @return the latest block height.
|
2019-06-14 16:24:52 -07:00
|
|
|
*/
|
2022-07-15 04:09:00 -07:00
|
|
|
suspend fun getLatestHeight(): BlockHeight?
|
2019-06-14 16:24:52 -07:00
|
|
|
|
2020-06-09 19:05:30 -07:00
|
|
|
/**
|
|
|
|
* Fetch the compact block for the given height, if it exists.
|
|
|
|
*
|
|
|
|
* @return the compact block or null when it did not exist.
|
|
|
|
*/
|
2022-07-12 05:40:09 -07:00
|
|
|
suspend fun findCompactBlock(height: BlockHeight): CompactFormats.CompactBlock?
|
2020-06-09 19:05:30 -07:00
|
|
|
|
2019-06-14 16:24:52 -07:00
|
|
|
/**
|
|
|
|
* Write the given blocks to this store, which may be anything from an in-memory cache to a DB.
|
2020-02-27 00:25:07 -08:00
|
|
|
*
|
|
|
|
* @param result the list of compact blocks to persist.
|
2022-07-28 05:39:48 -07:00
|
|
|
* @return Number of blocks that were written.
|
2019-06-14 16:24:52 -07:00
|
|
|
*/
|
2022-07-28 05:39:48 -07:00
|
|
|
suspend fun write(result: Sequence<CompactFormats.CompactBlock>): Int
|
2019-06-14 16:24:52 -07:00
|
|
|
|
|
|
|
/**
|
2021-04-09 18:19:33 -07:00
|
|
|
* Remove every block above the given height.
|
2020-02-27 00:25:07 -08:00
|
|
|
*
|
|
|
|
* @param height the target height to which to rewind.
|
2019-06-14 16:24:52 -07:00
|
|
|
*/
|
2022-07-12 05:40:09 -07:00
|
|
|
suspend fun rewindTo(height: BlockHeight)
|
2020-02-21 15:22:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close any connections to the block store.
|
|
|
|
*/
|
2021-10-21 13:05:02 -07:00
|
|
|
suspend fun close()
|
2020-06-09 20:28:21 -07:00
|
|
|
}
|