Improve `createProposedTransactions`
This commit is contained in:
parent
99e91fa8b7
commit
8e4c83627b
|
@ -68,9 +68,9 @@ import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.flow
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
@ -408,6 +408,7 @@ class SdkSynchronizer private constructor(
|
||||||
lastScanTime = now
|
lastScanTime = now
|
||||||
SYNCED
|
SYNCED
|
||||||
}
|
}
|
||||||
|
|
||||||
is Stopped -> STOPPED
|
is Stopped -> STOPPED
|
||||||
is Disconnected -> DISCONNECTED
|
is Disconnected -> DISCONNECTED
|
||||||
is Syncing, Initialized -> SYNCING
|
is Syncing, Initialized -> SYNCING
|
||||||
|
@ -579,25 +580,28 @@ class SdkSynchronizer private constructor(
|
||||||
proposal: Proposal,
|
proposal: Proposal,
|
||||||
usk: UnifiedSpendingKey
|
usk: UnifiedSpendingKey
|
||||||
): Flow<TransactionSubmitResult> {
|
): Flow<TransactionSubmitResult> {
|
||||||
val transactions = txManager.createProposedTransactions(proposal, usk)
|
// Internally, this logic submits and checks every incoming transaction, and once [Failure] or
|
||||||
|
// [NotAttempted] submission result occurs, it returns [NotAttempted] for the rest of them
|
||||||
return flow {
|
var anySubmissionFailed = false
|
||||||
var submitFailed = false
|
return txManager.createProposedTransactions(proposal, usk)
|
||||||
for (transaction in transactions) {
|
.asFlow()
|
||||||
if (submitFailed) {
|
.map { transaction ->
|
||||||
emit(TransactionSubmitResult.NotAttempted(transaction.txId))
|
if (anySubmissionFailed) {
|
||||||
|
TransactionSubmitResult.NotAttempted(transaction.txId)
|
||||||
} else {
|
} else {
|
||||||
val submitResult = txManager.submit(transaction)
|
val submission = txManager.submit(transaction)
|
||||||
when (submitResult) {
|
when (submission) {
|
||||||
is TransactionSubmitResult.Success -> {}
|
is TransactionSubmitResult.Success -> {
|
||||||
else -> {
|
// Expected state
|
||||||
submitFailed = true
|
}
|
||||||
|
is TransactionSubmitResult.Failure,
|
||||||
|
is TransactionSubmitResult.NotAttempted -> {
|
||||||
|
anySubmissionFailed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit(submitResult)
|
submission
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
|
|
Loading…
Reference in New Issue