diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index 6bf12e24..d9037e04 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -838,4 +838,14 @@
Couldn't ask the group to send.
Sending needs a share of the group's key, and a wallet of your own on this profile to see the group's coins with.
Nothing leaves the wallet until a quorum of members has seen this spend and signed it.
+ Spends
+ Waiting for signatures
+ Signed, sending it to the network
+ Sent, waiting for a confirmation
+ Confirmed
+ Replaced by a later spend
+ Send again
+ Bump the fee
+ Sent again
+ Couldn't bump the fee: there isn't enough left over to pay it.
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseFrostSigningRepository.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseFrostSigningRepository.kt
index 820e1a9a..4b211f6b 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseFrostSigningRepository.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseFrostSigningRepository.kt
@@ -1,5 +1,6 @@
package com.machankura.bennu.compose.database.repository
+import com.machankura.bennu.compose.database.model.GroupTransaction
import com.machankura.bennu.compose.wallet.GroupSpend
import fr.acinq.bitcoin.Chain
import fr.acinq.bitcoin.OutPoint
@@ -160,6 +161,9 @@ class DatabaseFrostSigningRepository(
emptySet()
}
+ override fun observeGroupTransactions(chatRoomId: String): Flow> =
+ database.groupTransactionDao().observeByChatRoomId(chatRoomId)
+
override suspend fun resend(localChatRoom: LocalChatRoom, sessionId: String): Boolean = try {
FrostSigningManager.resend(
database = database,
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/FrostSigningRepository.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/FrostSigningRepository.kt
index 12fd432b..95b0df2c 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/FrostSigningRepository.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/FrostSigningRepository.kt
@@ -1,5 +1,6 @@
package com.machankura.bennu.compose.repository
+import com.machankura.bennu.compose.database.model.GroupTransaction
import com.machankura.bennu.compose.wallet.GroupSpend
import fr.acinq.bitcoin.Chain
import fr.acinq.bitcoin.OutPoint
@@ -245,6 +246,9 @@ interface FrostSigningRepository {
/** The coins the room's open spends are already spending. */
suspend fun reservedOutPoints(chatRoomId: String): Set
+ /** Every spend the room has proposed, newest first, as it moves from proposed to confirmed. */
+ fun observeGroupTransactions(chatRoomId: String): Flow>
+
companion object {
val NO_OP_FROST_SIGNING_REPOSITORY: FrostSigningRepository = object : FrostSigningRepository {
override fun observeSessionById(sessionId: String): Flow = flowOf(null)
@@ -323,6 +327,8 @@ interface FrostSigningRepository {
override suspend fun reservedOutPoints(chatRoomId: String): Set = emptySet()
+ override fun observeGroupTransactions(chatRoomId: String): Flow> = flowOf(emptyList())
+
override fun signedEvents(items: List): List = emptyList()
}
}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletScreen.kt
index e741e7c3..fcc117bc 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletScreen.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletScreen.kt
@@ -1,5 +1,21 @@
package com.machankura.bennu.compose.ui.composable
+import androidx.compose.foundation.layout.Row
+import com.machankura.bennu.compose.text.ProposedSpend
+import com.machankura.bennu.compose.ui.view.state.SpendRow
+import com.machankura.bennu.compose.ui.view.state.SpendStatus
+import com.machankura.bennu.compose.wallet.GroupTransactionWatcher
+import bennu.composeapp.generated.resources.spends
+import bennu.composeapp.generated.resources.waiting_for_signatures
+import bennu.composeapp.generated.resources.abandoned
+import bennu.composeapp.generated.resources.signed_sending_it_to_the_network
+import bennu.composeapp.generated.resources.sent_waiting_for_a_confirmation
+import bennu.composeapp.generated.resources.confirmed
+import bennu.composeapp.generated.resources.replaced_by_a_later_spend
+import bennu.composeapp.generated.resources.send_again
+import bennu.composeapp.generated.resources.bump_the_fee
+import bennu.composeapp.generated.resources.sent_again
+import bennu.composeapp.generated.resources.couldn_t_bump_the_fee
import androidx.compose.material.icons.filled.Send
import bennu.composeapp.generated.resources.send
import com.machankura.bennu.compose.ui.composable.navigation.routes.GroupSendRoute
@@ -113,6 +129,7 @@ fun GroupWalletScreen(
chatRepository: ChatRepository,
frostSigningRepository: FrostSigningRepository,
wallets: GroupChainWallets?,
+ watcher: GroupTransactionWatcher? = null,
onNavigateToRoute: (Route) -> Unit,
onNavigateBack: () -> Unit,
) {
@@ -125,6 +142,7 @@ fun GroupWalletScreen(
chatRepository = chatRepository,
frostSigningRepository = frostSigningRepository,
wallets = wallets,
+ watcher = watcher,
)
)
@@ -136,6 +154,11 @@ fun GroupWalletScreen(
val notify = rememberNotifier(rememberCoroutineScope())
val couldNotOpen = stringResource(Res.string.couldn_t_ask_the_group_to_open_a_wallet)
+ val sentAgain = stringResource(Res.string.sent_again)
+ val couldNotBump = stringResource(Res.string.couldn_t_bump_the_fee)
+ val toSession = { sessionId: String ->
+ onNavigateToRoute(FrostSigningRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, sessionId = sessionId))
+ }
Scaffold(
snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
@@ -219,6 +242,15 @@ fun GroupWalletScreen(
)
}
} else null,
+ onOpenSpend = toSession,
+ onSendAgain = if (watcher != null) {
+ { sessionId -> groupWalletViewModel.sendAgain(sessionId) { notify(sentAgain) } }
+ } else null,
+ onBump = if (state.canSign) {
+ { sessionId ->
+ groupWalletViewModel.bumpFee(sessionId, onSuccess = toSession, onFailure = { notify(couldNotBump) })
+ }
+ } else null,
)
}
}
@@ -260,6 +292,9 @@ private fun OpenWallet(
state: GroupWalletUIState.Loaded,
notify: (String) -> Unit,
onSend: (() -> Unit)?,
+ onOpenSpend: (sessionId: String) -> Unit,
+ onSendAgain: ((sessionId: String) -> Unit)?,
+ onBump: ((sessionId: String) -> Unit)?,
) {
val clipboardManager = LocalClipboardManager.current
val addressCopied = stringResource(Res.string.address_copied)
@@ -350,6 +385,27 @@ private fun OpenWallet(
}
}
+ // Under the coins and for every member, node or not: a spend is the
+ // group's decision, and a member who cannot see the chain can still see
+ // what the group has asked of it and where each request has got to.
+ if (state.spends.isNotEmpty()) {
+ item {
+ Text(
+ text = stringResource(Res.string.spends),
+ style = MaterialTheme.typography.titleMedium,
+ )
+ }
+ items(state.spends, key = { it.transaction.frostSigningSessionId }) { row ->
+ SpendRowCard(
+ row = row,
+ chain = state.wallet.chain,
+ onOpen = { onOpenSpend(row.transaction.frostSigningSessionId) },
+ onSendAgain = onSendAgain?.takeIf { row.canSendAgain }?.let { { it(row.transaction.frostSigningSessionId) } },
+ onBump = onBump?.takeIf { row.canBump }?.let { { it(row.transaction.frostSigningSessionId) } },
+ )
+ }
+ }
+
item {
Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)) {
TextButton(
@@ -379,6 +435,47 @@ private fun OpenWallet(
}
}
+/** One spend: what it sends, where it has got to, and what can still be done about it. */
+@Composable
+private fun SpendRowCard(
+ row: SpendRow,
+ chain: Chain,
+ onOpen: () -> Unit,
+ onSendAgain: (() -> Unit)?,
+ onBump: (() -> Unit)?,
+) {
+ Card(modifier = Modifier.fillMaxWidth(), onClick = onOpen) {
+ ListItem(
+ headlineContent = {
+ Text(
+ text = (row.spend?.let { ProposedSpend.summarize(it, chain) } ?: ProposedSpend.UNREADABLE).detail,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ )
+ },
+ supportingContent = { Text(stringResource(row.status.label())) },
+ )
+ if (onSendAgain != null || onBump != null) {
+ Row(
+ modifier = Modifier.fillMaxWidth().padding(horizontal = MaterialTheme.spacing.compactPadding),
+ horizontalArrangement = Arrangement.End,
+ ) {
+ onSendAgain?.let { TextButton(onClick = it) { Text(stringResource(Res.string.send_again)) } }
+ onBump?.let { TextButton(onClick = it) { Text(stringResource(Res.string.bump_the_fee)) } }
+ }
+ }
+ }
+}
+
+private fun SpendStatus.label() = when (this) {
+ SpendStatus.WAITING_FOR_SIGNATURES -> Res.string.waiting_for_signatures
+ SpendStatus.ABANDONED -> Res.string.abandoned
+ SpendStatus.SIGNED -> Res.string.signed_sending_it_to_the_network
+ SpendStatus.SENT -> Res.string.sent_waiting_for_a_confirmation
+ SpendStatus.CONFIRMED -> Res.string.confirmed
+ SpendStatus.REPLACED -> Res.string.replaced_by_a_later_spend
+}
+
/** Confirmed and on-the-way said apart: only the first can be spent by a send-all. */
@Composable
private fun BalanceCard(walletState: GroupWalletState?) {
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt
index b0d89054..44c9b8f2 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt
@@ -1253,6 +1253,7 @@ fun BennuNavHost(
chatRepository = databaseChatRepository,
frostSigningRepository = databaseFrostSigningRepository,
wallets = groupChainWallets,
+ watcher = groupTransactionWatcher,
onNavigateToRoute = { actionRoute ->
navController.navigate(route = actionRoute)
},
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModel.kt
index b21c1ec9..38389330 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModel.kt
@@ -1,5 +1,13 @@
package com.machankura.bennu.compose.ui.view.model
+import com.machankura.bennu.compose.database.model.GroupTransaction
+import com.machankura.bennu.compose.ui.view.state.SpendRow
+import com.machankura.bennu.compose.ui.view.state.SpendStatus
+import com.machankura.bennu.compose.wallet.GroupSpend
+import com.machankura.bennu.compose.wallet.GroupSpendBuilder
+import com.machankura.bennu.compose.wallet.GroupTransactionWatcher
+import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.flowOf
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -41,6 +49,7 @@ class GroupWalletViewModel(
val chatRepository: ChatRepository,
val frostSigningRepository: FrostSigningRepository,
private val wallets: GroupChainWallets?,
+ private val watcher: GroupTransactionWatcher? = null,
): ViewModel() {
private val logger = Logger.withTag(TAG)
@@ -80,16 +89,70 @@ class GroupWalletViewModel(
)
groupWalletUIState = loaded
- val chainWallet = wallets?.walletFor(wallet.account) ?: return@launch
+ // The chain and the room's spends, as one state: either changing
+ // redraws the screen, and neither may overwrite the other.
+ val chainState = wallets?.walletFor(wallet.account)?.state ?: flowOf(null)
watching?.cancel()
watching = viewModelScope.launch(Dispatchers.IO) {
- chainWallet.state.collect { state ->
- groupWalletUIState = loaded.copy(walletState = state)
+ combine(chainState, frostSigningRepository.observeGroupTransactions(chatRoomId)) { state, transactions ->
+ state to transactions.map { rowOf(it) }
+ }.collect { (state, rows) ->
+ groupWalletUIState = loaded.copy(walletState = state, spends = rows)
}
}
}
}
+ /** Checked once per session: the PSBT is write-once, so what it says cannot change. */
+ private val checkedSpends = mutableMapOf()
+
+ private suspend fun rowOf(transaction: GroupTransaction): SpendRow {
+ val sessionId = transaction.frostSigningSessionId
+ val spend = checkedSpends.getOrPut(sessionId) { frostSigningRepository.checkedSpend(sessionId) }
+ val stage = frostSigningRepository.getSessionById(sessionId)?.stage
+ return SpendRow(transaction = transaction, status = SpendStatus.of(stage, transaction), spend = spend)
+ }
+
+ /** Sends a signed spend again now. Only worth anything while Electrum has not reported it back. */
+ fun sendAgain(sessionId: String, onSent: () -> Unit) {
+ val watcher = watcher ?: return
+ viewModelScope.launch(Dispatchers.IO) {
+ if (runCatching { watcher.broadcastAgain(sessionId) }.getOrDefault(false)) {
+ withContext(Dispatchers.Main) { onSent() }
+ }
+ }
+ }
+
+ /**
+ * Asks the group to sign [sessionId]'s spend again at twice its feerate: the
+ * same coins, the extra out of the change. A new session with new signatures --
+ * a retry is never the old session again -- and whichever of the two confirms
+ * settles the other.
+ */
+ fun bumpFee(sessionId: String, onSuccess: (sessionId: String) -> Unit, onFailure: () -> Unit) {
+ val state = groupWalletUIState as? GroupWalletUIState.Loaded ?: return
+ val spend = state.spends.firstOrNull { it.transaction.frostSigningSessionId == sessionId }?.spend ?: return
+ if (isActionPending.value) return
+
+ val built = GroupSpendBuilder.bump(spend, spend.feeratePerVbyte * 2) as? GroupSpendBuilder.Result.Built
+ if (built == null) {
+ onFailure()
+ return
+ }
+ isActionPending.value = true
+
+ viewModelScope.launch(Dispatchers.IO) {
+ val session = runCatching {
+ frostSigningRepository.proposeSpend(state.localChatRoom, activeUserPublicKey, built.psbt, chain)
+ }.onFailure { logger.e("Failed to bump $sessionId", it) }.getOrNull()
+
+ withContext(Dispatchers.Main) {
+ if (session != null) onSuccess(session.id) else onFailure()
+ }
+ isActionPending.value = false
+ }
+ }
+
/**
* Asks the group to open its wallet: one signing session over one statement.
*
@@ -139,6 +202,7 @@ class GroupWalletViewModel(
chatRepository: ChatRepository,
frostSigningRepository: FrostSigningRepository,
wallets: GroupChainWallets?,
+ watcher: GroupTransactionWatcher? = null,
): ViewModelProvider.Factory = viewModelFactory {
initializer {
GroupWalletViewModel(
@@ -149,6 +213,7 @@ class GroupWalletViewModel(
chatRepository = chatRepository,
frostSigningRepository = frostSigningRepository,
wallets = wallets,
+ watcher = watcher,
)
}
}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletUIState.kt
index ab31c141..6fa85a52 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletUIState.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletUIState.kt
@@ -4,6 +4,9 @@ import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
import com.machankura.bennu.compose.managers.GroupWalletDerivation
import com.machankura.bennu.compose.nostr.wallet.GroupWallet
import com.machankura.bennu.compose.wallet.GroupWalletState
+import com.machankura.bennu.compose.wallet.GroupSpend
+import com.machankura.bennu.compose.database.model.GroupTransaction
+import com.machankura.bennu.compose.database.model.types.FrostSigningStage
sealed interface GroupWalletUIState {
/**
@@ -33,6 +36,8 @@ sealed interface GroupWalletUIState {
val walletState: GroupWalletState?,
val canWatch: Boolean,
val canSign: Boolean,
+ /** The room's spends, newest first. */
+ val spends: List = emptyList(),
): GroupWalletUIState
data class Error(
@@ -41,3 +46,43 @@ sealed interface GroupWalletUIState {
data object Loading: GroupWalletUIState
}
+
+/** Where one of the room's spends has got to, as one fact a member reads. */
+enum class SpendStatus {
+ WAITING_FOR_SIGNATURES,
+ ABANDONED,
+ SIGNED,
+ SENT,
+ CONFIRMED,
+ REPLACED;
+
+ companion object {
+ /**
+ * The session decides until the group has signed; the chain decides after.
+ * Sent means Electrum has reported it back -- a broadcast reports success
+ * whatever the server said, so sending is not evidence of having been sent.
+ */
+ fun of(stage: FrostSigningStage?, transaction: GroupTransaction): SpendStatus = when {
+ transaction.replacedByTxid != null -> REPLACED
+ transaction.confirmedAt != null -> CONFIRMED
+ transaction.seenAt != null -> SENT
+ transaction.signedTransaction != null -> SIGNED
+ stage == FrostSigningStage.FAILED -> ABANDONED
+ else -> WAITING_FOR_SIGNATURES
+ }
+ }
+}
+
+/** One of the room's spends, as the wallet screen lists it. */
+data class SpendRow(
+ val transaction: GroupTransaction,
+ val status: SpendStatus,
+ /** The spend, checked again; null where this device cannot check it. */
+ val spend: GroupSpend.Checked?,
+) {
+ /** Signed, never reported back: the one moment sending it again is worth anything. */
+ val canSendAgain: Boolean get() = status == SpendStatus.SIGNED
+
+ /** Signed and not yet decided by a block: RBF is still possible. */
+ val canBump: Boolean get() = (status == SpendStatus.SIGNED || status == SpendStatus.SENT) && spend != null
+}
diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModelJvmTest.kt
index 98500b64..cd416648 100644
--- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModelJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModelJvmTest.kt
@@ -10,6 +10,8 @@ import com.machankura.bennu.compose.nostr.wallet.GroupWalletStatementEvent
import com.machankura.bennu.compose.repository.ChatRepository
import com.machankura.bennu.compose.repository.FrostSigningRepository
import com.machankura.bennu.compose.ui.view.state.GroupWalletUIState
+import com.machankura.bennu.compose.ui.view.state.SpendStatus
+import com.machankura.bennu.compose.database.model.types.FrostSigningStage
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.Kind
import fr.acinq.bitcoin.ByteVector32
@@ -166,4 +168,76 @@ class GroupWalletViewModelJvmTest {
))
runBlocking { withTimeout(5_000) { while (!failed) delay(10) } }
}
+
+ // ---- spends ------------------------------------------------------------
+
+ private val coinTx = fr.acinq.bitcoin.Transaction(
+ 2, listOf(fr.acinq.bitcoin.TxIn(fr.acinq.bitcoin.OutPoint(fr.acinq.bitcoin.TxId(ByteVector32(ByteArray(32) { 1 })), 0), fr.acinq.bitcoin.ByteVector.empty, 0xffffffffL)),
+ listOf(fr.acinq.bitcoin.TxOut(fr.acinq.bitcoin.Satoshi(60_000), GroupWalletDerivation.derive(account, 0, 0).pubkeyScript)), 0,
+ )
+
+ private val spend: com.machankura.bennu.compose.wallet.GroupSpend.Checked = run {
+ val first = GroupWalletDerivation.derive(account, 0, 0)
+ val change = GroupWalletDerivation.derive(account, 1, 0)
+ val tx = fr.acinq.bitcoin.Transaction(
+ 2, listOf(fr.acinq.bitcoin.TxIn(fr.acinq.bitcoin.OutPoint(coinTx, 0), fr.acinq.bitcoin.ByteVector.empty, 0xfffffffdL)),
+ listOf(
+ fr.acinq.bitcoin.TxOut(fr.acinq.bitcoin.Satoshi(30_000), fr.acinq.bitcoin.ByteVector("0014" + "00".repeat(20))),
+ fr.acinq.bitcoin.TxOut(fr.acinq.bitcoin.Satoshi(29_000), change.pubkeyScript),
+ ), 0,
+ )
+ val psbt = com.machankura.bennu.compose.wallet.GroupSpend.psbtOf(tx, listOf(coinTx.txOut[0] to first), mapOf(1 to change), account)
+ (com.machankura.bennu.compose.wallet.GroupSpend.check(psbt, account) as com.machankura.bennu.compose.wallet.GroupSpend.Result.Ok).checked
+ }
+
+ private val signedRow = com.machankura.bennu.compose.database.model.GroupTransaction(
+ frostSigningSessionId = "spend-1", chatRoomId = chatRoomId, chain = "mainnet", account = 0,
+ psbt = com.machankura.bennu.compose.wallet.GroupSpend.encode(spend.psbt), txid = spend.tx.txid.toString(), signedTransaction = "00",
+ )
+
+ private inner class SpendingRepository : FrostSigningRepository by FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY {
+ var proposed: fr.acinq.bitcoin.psbt.Psbt? = null
+ override fun observeGroupTransactions(chatRoomId: String) = kotlinx.coroutines.flow.flowOf(listOf(signedRow))
+ override suspend fun checkedSpend(sessionId: String) = spend
+ override suspend fun getSessionById(sessionId: String): FrostSigningSession? = null
+ override suspend fun proposeSpend(localChatRoom: LocalChatRoom, userPublicKey: HexKey, psbt: fr.acinq.bitcoin.psbt.Psbt, chain: Chain): FrostSigningSession? {
+ proposed = psbt
+ return null
+ }
+ }
+
+ @Test
+ fun `the room's spends are listed, and a bump asks for twice the feerate on the same coins`() {
+ val signing = SpendingRepository()
+ val model = viewModel(repository(opened = wallet), signing).apply { initiate() }
+
+ val loaded = runBlocking {
+ withTimeout(5_000) {
+ while ((model.groupWalletUIState as? GroupWalletUIState.Loaded)?.spends.isNullOrEmpty()) delay(10)
+ model.groupWalletUIState as GroupWalletUIState.Loaded
+ }
+ }
+ val row = loaded.spends.single()
+ assertEquals(com.machankura.bennu.compose.ui.view.state.SpendStatus.SIGNED, row.status)
+ assertEquals(true, row.canBump)
+
+ model.bumpFee("spend-1", onSuccess = {}, onFailure = {})
+ runBlocking { withTimeout(5_000) { while (signing.proposed == null) delay(10) } }
+
+ val bumped = (com.machankura.bennu.compose.wallet.GroupSpend.check(signing.proposed!!, account) as com.machankura.bennu.compose.wallet.GroupSpend.Result.Ok).checked
+ assertEquals(spend.tx.txIn.map { it.outPoint }, bumped.tx.txIn.map { it.outPoint })
+ assertEquals(spend.feeratePerVbyte * 2, bumped.feeratePerVbyte)
+ }
+
+ @Test
+ fun `a spend's status is the session's until it is signed, and the chain's after`() {
+ val unsigned = signedRow.copy(signedTransaction = null)
+
+ assertEquals(SpendStatus.WAITING_FOR_SIGNATURES, SpendStatus.of(FrostSigningStage.COLLECTING_NONCES, unsigned))
+ assertEquals(SpendStatus.ABANDONED, SpendStatus.of(FrostSigningStage.FAILED, unsigned))
+ assertEquals(SpendStatus.SIGNED, SpendStatus.of(FrostSigningStage.COMPLETE, signedRow))
+ assertEquals(SpendStatus.SENT, SpendStatus.of(FrostSigningStage.COMPLETE, signedRow.copy(seenAt = Instant.fromEpochSeconds(1))))
+ assertEquals(SpendStatus.CONFIRMED, SpendStatus.of(FrostSigningStage.COMPLETE, signedRow.copy(seenAt = Instant.fromEpochSeconds(1), confirmedAt = Instant.fromEpochSeconds(2))))
+ assertEquals(SpendStatus.REPLACED, SpendStatus.of(FrostSigningStage.COMPLETE, signedRow.copy(replacedByTxid = "ab".repeat(32))))
+ }
}
diff --git a/docs/group-chain-wallet.md b/docs/group-chain-wallet.md
index fb20f7f7..b9e056d4 100644
--- a/docs/group-chain-wallet.md
+++ b/docs/group-chain-wallet.md
@@ -43,6 +43,10 @@ kept as written; where the build chose differently the table below says so.
| the feerate comes from `FeerateManager`'s `halfHour` | from Electrum's six-block estimate, through `GroupChainWallets` — the wallet already holds the identity's Electrum client, and the business's fee manager would be a second way in to the same node. Prefilled, never used unseen |
| the inputs behind a disclosure on the approval screen | a line saying how many of the group's coins it spends. Each was checked against the wallet before the screen was drawn, so there is nothing about them a member could check by opening one |
| the composer marks coins reserved | `FrostSigningManager.reservedOutPoints`: every coin an open spend holds, released when its session fails, held by a finished one until Electrum stops reporting the coin |
+| transcript lines for broadcast and for confirmed | confirmed only, `TYPE_GROUP_TRANSACTION_CONFIRMED`, written by `recordConfirmed` once. A broadcast is this device's own act and says nothing the group did; the wallet screen shows each spend's status instead |
+| a conflicting spend is noticed when a reserved coin is spent by a different transaction | when one of the group's spends *confirms*: only the group can spend its coins, so the only other transaction that can take one is another of its own spends, and the confirmation is the moment the question is settled. Settled by the confirmed spend's own row, so every device decides the same way |
+| a fee bump is proposed at a feerate the member chooses | at twice the spend's feerate, from a *Bump the fee* button on the spend's row — comfortably over BIP125's increment, and one decision rather than a form |
+| `GroupTransaction` rows are kept by the screen that shows them | `GroupTransactionWatcher`, one per identity beside the wallets, started with the identity's node whether or not anybody opens the wallet. It found a real bug before it shipped: following each spend from the list a pass began with wrote a settled row back from its stale copy |
The headline: **the best path is BIP86's own unhardened tail, `//`,
hung under an account key the group's threshold key is tweaked to, with the