[#886] Support null block heights

Co-authored-by: Honza <rychnovsky.honza@gmail.com>
This commit is contained in:
Carter Jernigan 2023-01-12 11:32:43 -05:00 committed by GitHub
parent 50efd683ee
commit 4ad1da49d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 11 deletions

View File

@ -47,7 +47,7 @@ jobs:
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- name: Setup
id: setup
timeout-minutes: 30
timeout-minutes: 35
uses: ./.github/actions/setup
check_firebase_secrets:

View File

@ -1,8 +1,11 @@
Change Log
==========
## Unreleased
## 1.12.0-beta01
### Changed
- `TransactionOverview`, `Transaction.Sent`, and `Transaction.Received` have `minedHeight` as a nullable field now. This fixes a potential crash when fetching transactions when a transaction is in the mempool
## 1.11.0-beta01
### Added
- `cash.z.ecc.android.sdk`:
- `Synchronizer.getUnifiedAddress`

View File

@ -22,7 +22,7 @@ ZCASH_ASCII_GPG_KEY=
# Configures whether release is an unstable snapshot, therefore published to the snapshot repository.
IS_SNAPSHOT=true
LIBRARY_VERSION=1.11.0-beta01
LIBRARY_VERSION=1.12.0-beta01
# Kotlin compiler warnings can be considered errors, failing the build.
ZCASH_IS_TREAT_WARNINGS_AS_ERRORS=true

View File

@ -427,7 +427,7 @@ class CompactBlockProcessor internal constructor(
}
}
newTxs.onEach { newTransaction ->
newTxs.filter { it.minedHeight != null }.onEach { newTransaction ->
enhance(newTransaction)
}
twig("Done enhancing transaction details")
@ -443,7 +443,9 @@ class CompactBlockProcessor internal constructor(
// TODO [#683]: https://github.com/zcash/zcash-android-wallet-sdk/issues/683
private suspend fun enhance(transaction: TransactionOverview) = withContext(Dispatchers.IO) {
enhanceHelper(transaction.id, transaction.rawId.byteArray, transaction.minedHeight)
transaction.minedHeight?.let { minedHeight ->
enhanceHelper(transaction.id, transaction.rawId.byteArray, minedHeight)
}
}
private suspend fun enhanceHelper(id: Long, rawTransactionId: ByteArray, minedHeight: BlockHeight) {

View File

@ -20,10 +20,18 @@ internal class AllTransactionView(
) {
companion object {
private const val COLUMN_SORT_HEIGHT = "sort_height" // $NON-NLS
private val COLUMNS = arrayOf(
"*", // $NON-NLS
@Suppress("MaxLineLength")
"IFNULL(${AllTransactionViewDefinition.COLUMN_INTEGER_MINED_HEIGHT}, ${UInt.MAX_VALUE}) AS $COLUMN_SORT_HEIGHT" // $NON-NLS
)
private val ORDER_BY = String.format(
Locale.ROOT,
"%s DESC, %s DESC", // $NON-NLS
AllTransactionViewDefinition.COLUMN_INTEGER_MINED_HEIGHT,
COLUMN_SORT_HEIGHT,
AllTransactionViewDefinition.COLUMN_INTEGER_ID
)
@ -98,6 +106,7 @@ internal class AllTransactionView(
fun getAllTransactions() =
sqliteDatabase.queryAndMap(
table = AllTransactionViewDefinition.VIEW_NAME,
columns = COLUMNS,
orderBy = ORDER_BY,
cursorParser = cursorParser
)
@ -105,6 +114,7 @@ internal class AllTransactionView(
fun getTransactionRange(blockHeightRange: ClosedRange<BlockHeight>) =
sqliteDatabase.queryAndMap(
table = AllTransactionViewDefinition.VIEW_NAME,
columns = COLUMNS,
orderBy = ORDER_BY,
selection = SELECTION_BLOCK_RANGE,
selectionArgs = arrayOf(blockHeightRange.start.value, blockHeightRange.endInclusive.value),
@ -114,6 +124,7 @@ internal class AllTransactionView(
suspend fun getOldestTransaction() =
sqliteDatabase.queryAndMap(
table = AllTransactionViewDefinition.VIEW_NAME,
columns = COLUMNS,
orderBy = ORDER_BY,
limit = "1",
cursorParser = cursorParser

View File

@ -18,10 +18,18 @@ internal class ReceivedTransactionView(
) {
companion object {
private const val COLUMN_SORT_HEIGHT = "sort_height" // $NON-NLS
private val COLUMNS = arrayOf(
"*", // $NON-NLS
@Suppress("MaxLineLength")
"IFNULL(${ReceivedTransactionViewDefinition.COLUMN_INTEGER_MINED_HEIGHT}, ${UInt.MAX_VALUE}) AS $COLUMN_SORT_HEIGHT" // $NON-NLS
)
private val ORDER_BY = String.format(
Locale.ROOT,
"%s DESC, %s DESC", // $NON-NLS
ReceivedTransactionViewDefinition.COLUMN_INTEGER_MINED_HEIGHT,
COLUMN_SORT_HEIGHT,
ReceivedTransactionViewDefinition.COLUMN_INTEGER_ID
)
@ -37,6 +45,7 @@ internal class ReceivedTransactionView(
fun getReceivedTransactions() =
sqliteDatabase.queryAndMap(
table = ReceivedTransactionViewDefinition.VIEW_NAME,
columns = COLUMNS,
orderBy = ORDER_BY,
cursorParser = { cursor ->
val idColumnIndex = cursor.getColumnIndex(ReceivedTransactionViewDefinition.COLUMN_INTEGER_ID)

View File

@ -18,10 +18,18 @@ internal class SentTransactionView(
) {
companion object {
private const val COLUMN_SORT_HEIGHT = "sort_height" // $NON-NLS
private val COLUMNS = arrayOf(
"*", // $NON-NLS
@Suppress("MaxLineLength")
"IFNULL(${SentTransactionViewDefinition.COLUMN_INTEGER_MINED_HEIGHT}, ${UInt.MAX_VALUE}) AS $COLUMN_SORT_HEIGHT" // $NON-NLS
)
private val ORDER_BY = String.format(
Locale.ROOT,
"%s DESC, %s DESC", // $NON-NLS
SentTransactionViewDefinition.COLUMN_INTEGER_MINED_HEIGHT,
COLUMN_SORT_HEIGHT,
SentTransactionViewDefinition.COLUMN_INTEGER_ID
)
@ -37,6 +45,7 @@ internal class SentTransactionView(
fun getSentTransactions() =
sqliteDatabase.queryAndMap(
table = SentTransactionViewDefinition.VIEW_NAME,
columns = COLUMNS,
orderBy = ORDER_BY,
cursorParser = { cursor ->
val idColumnIndex = cursor.getColumnIndex(SentTransactionViewDefinition.COLUMN_INTEGER_ID)

View File

@ -4,7 +4,7 @@ sealed class Transaction {
data class Received internal constructor(
val id: Long,
val rawId: FirstClassByteArray,
val minedHeight: BlockHeight,
val minedHeight: BlockHeight?,
val expiryHeight: BlockHeight?,
val index: Long,
val raw: FirstClassByteArray?,
@ -20,7 +20,7 @@ sealed class Transaction {
data class Sent internal constructor(
val id: Long,
val rawId: FirstClassByteArray,
val minedHeight: BlockHeight,
val minedHeight: BlockHeight?,
val expiryHeight: BlockHeight?,
val index: Long,
val raw: FirstClassByteArray?,

View File

@ -9,7 +9,7 @@ package cash.z.ecc.android.sdk.model
data class TransactionOverview internal constructor(
val id: Long,
val rawId: FirstClassByteArray,
val minedHeight: BlockHeight,
val minedHeight: BlockHeight?,
val expiryHeight: BlockHeight?,
val index: Long,
val raw: FirstClassByteArray?,