Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ internal class GiveBillTransactor(
* @return the confirmed [TransactionMetadata.SendPublicPayment] on success.
*/
suspend fun start(): Result<TransactionMetadata.SendPublicPayment> {
if (!scope.isActive) {
return logAndFail(GiveTransactorError.Other(message = "Transactor was disposed"))
}

val ownerKey = owner
?: return logAndFail(GiveTransactorError.Other(message = "No owner key. Did you call with() first?"))
val desiredToken = token
Expand Down Expand Up @@ -212,13 +216,13 @@ internal class GiveBillTransactor(

/** Cancels the coroutine scope and clears all held state. */
fun dispose() {
scope.cancel()
owner = null
presentationData = BillPresentationData(emptyList(), emptyList())
rendezvousKey = null
receivingAccount = null
token = null
providedVerifiedState = null
scope.cancel()
}

sealed class GiveTransactorError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch
import java.util.Timer
import java.util.TimerTask
Expand Down Expand Up @@ -113,6 +114,10 @@ class BillTransactionManager @Inject constructor(
present(transactor.presentationData)
presentBillForGive(onTimeout)

// If cancelAwaitForGrab() fired between present() and here,
// bail out before start() reads fields that dispose() may have nulled.
ensureActive()

transactor.start()
.onSuccess {
childScope.cancel()
Expand Down
Loading