Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1170] Regular transaction flow emitting #1204

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
- etc.

### Fixed
- `Synchronizer.getMemos()` now correctly returns a flow of strings for sent and received transactions.
- `Synchronizer.getMemos()` now correctly returns a flow of strings for sent and received transactions. Issue **#1154**.
- `CompactBlockProcessor` now triggers transaction polling while block synchronization is in progress as expected.
Clients will be notified briefly after every new transaction is discovered via `Synchronizer.transactions` API.
Issue **#1170**.

## 1.20.0-beta01
- The SDK internally migrated from `BackendExt` rust backend extension functions to more type-safe `TypesafeBackend`.
Expand Down
1 change: 1 addition & 0 deletions demo-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ dependencies {

implementation(libs.bundles.grpc)
implementation(libs.kotlinx.datetime)
implementation(libs.kotlinx.immutable)
}

fladle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import cash.z.ecc.android.sdk.demoapp.R
import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.model.TransactionOverview
import cash.z.ecc.android.sdk.model.WalletAddresses
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
Expand All @@ -41,7 +43,7 @@ private fun ComposablePreview() {
MaterialTheme {
// TODO [#1090]: Demo: Add Addresses and Transactions Compose Previews
// TODO [#1090]: https://github.com/zcash/zcash-android-wallet-sdk/issues/1090
// Transactions()
// TransactionsView()
}
}

Expand Down Expand Up @@ -72,6 +74,7 @@ fun Transactions(
paddingValues = paddingValues,
synchronizer,
synchronizer.transactions.collectAsStateWithLifecycle(initialValue = emptyList()).value
.toPersistentList()
)
}
}
Expand Down Expand Up @@ -110,7 +113,7 @@ private fun TransactionsTopAppBar(
private fun TransactionsMainContent(
paddingValues: PaddingValues,
synchronizer: Synchronizer,
transactions: List<TransactionOverview>
transactions: ImmutableList<TransactionOverview>
) {
val queryScope = rememberCoroutineScope()
Column(
Expand All @@ -127,7 +130,7 @@ private fun TransactionsMainContent(
val memos = synchronizer.getMemos(it)
queryScope.launch {
memos.toList().run {
Twig.debug {
Twig.info {
"Transaction memos: count: $size, contains: ${joinToString().ifEmpty { "-" }}"
}
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ JAVAX_ANNOTATION_VERSION=1.3.2
JUNIT_VERSION=5.9.3
KOTLINX_COROUTINES_VERSION=1.7.3
KOTLINX_DATETIME_VERSION=0.4.0
KOTLINX_IMMUTABLE_COLLECTIONS_VERSION=0.3.5
KOTLIN_VERSION=1.9.10
MOCKITO_KOTLIN_VERSION=2.2.0
MOCKITO_VERSION=5.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ class CompactBlockProcessor internal constructor(
SyncingResult.UpdateBirthday -> {
updateBirthdayHeight()
}
SyncingResult.EnhanceSuccess -> {
Twig.info { "Triggering transaction refresh now" }
// Invalidate transaction data
refreshTransactions(transactionStorage = repository)
}
is SyncingResult.Failure -> {
syncingResult = rangeSyncProgress.resultState
return@collect
Expand Down Expand Up @@ -553,6 +558,12 @@ class CompactBlockProcessor internal constructor(
updateBirthdayHeight()
SyncingResult.AllSuccess
}
SyncingResult.EnhanceSuccess -> {
Twig.info { "Triggering transaction refresh now" }
// Invalidate transaction data and return the common batch syncing success result to the caller
refreshTransactions(transactionStorage = repository)
SyncingResult.AllSuccess
}
is SyncingResult.Failure -> {
rangeSyncProgress.resultState
} else -> {
Expand Down Expand Up @@ -598,6 +609,13 @@ class CompactBlockProcessor internal constructor(
return BlockProcessingResult.Success
}

/**
* This invalidates transaction storage to trigger data refreshing for its subscribers.
*/
private fun refreshTransactions(transactionStorage: DerivedDataRepository) {
transactionStorage.invalidate()
}

@Suppress("ReturnCount")
internal suspend fun runSbSSyncingPreparation(
backend: TypesafeBackend,
Expand Down Expand Up @@ -701,6 +719,11 @@ class CompactBlockProcessor internal constructor(
SyncingResult.UpdateBirthday -> {
updateBirthdayHeight()
}
SyncingResult.EnhanceSuccess -> {
Twig.info { "Triggering transaction refresh now" }
// Invalidate transaction data
refreshTransactions(transactionStorage = repository)
}
is SyncingResult.Failure -> {
syncingResult = rangeSyncProgress.resultState
return@collect
Expand Down Expand Up @@ -1418,8 +1441,8 @@ class CompactBlockProcessor internal constructor(
enhancingResult
}
else -> {
// Transactions enhanced correctly. Now we return common sync success state.
SyncingResult.AllSuccess
// Transactions enhanced correctly. Let's continue with block processing.
enhancingResult
}
}
emit(
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ dependencyResolutionManagement {
val kotlinVersion = extra["KOTLIN_VERSION"].toString()
val kotlinxCoroutinesVersion = extra["KOTLINX_COROUTINES_VERSION"].toString()
val kotlinxDateTimeVersion = extra["KOTLINX_DATETIME_VERSION"].toString()
val kotlinxImmutableCollectionsVersion = extra["KOTLINX_IMMUTABLE_COLLECTIONS_VERSION"].toString()
val mockitoKotlinVersion = extra["MOCKITO_KOTLIN_VERSION"].toString()
val mockitoVersion = extra["MOCKITO_VERSION"].toString()
val protocVersion = extra["PROTOC_VERSION"].toString()
Expand Down Expand Up @@ -167,6 +168,7 @@ dependencyResolutionManagement {
library("kotlinx-coroutines-android", "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinxCoroutinesVersion")
library("kotlinx-coroutines-core", "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
library("kotlinx-datetime", "org.jetbrains.kotlinx:kotlinx-datetime:$kotlinxDateTimeVersion")
library("kotlinx-immutable", "org.jetbrains.kotlinx:kotlinx-collections-immutable:$kotlinxImmutableCollectionsVersion")
library("material", "com.google.android.material:material:$googleMaterialVersion")
library("zcashwalletplgn", "com.github.zcash:zcash-android-wallet-plugins:$zcashWalletPluginVersion")

Expand Down