feat(wallet): ship behind the rollout gates (Phase 10)
GroupWalletRollout holds the three gates, each with what lifts it. The flag is on, its condition met. Send-an-amount is off, so the form sends everything confirmed to one address and says so. A spend proposed from this device on mainnet may send at most 100,000 sats; test networks have no cap. The gates are on the composer and nothing else: a device behind them still accepts, shows and signs what another member proposes, through every check GroupSpend makes. The plan is marked built, with its table of where the build chose differently. Full JVM suite: 1474 tests, none failing; the Android target compiles; every M3 budget is met. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0db1fe8fc8
commit
f83fe35a45
10 files changed
+108
-18
No files matched your search
@@ -848,4 +848,6 @@
|
||||
<string name="bump_the_fee">Bump the fee</string>
|
||||
<string name="sent_again">Sent again</string>
|
||||
<string name="couldn_t_bump_the_fee">Couldn't bump the fee: there isn't enough left over to pay it.</string>
|
||||
<string name="for_now_a_spend_sends_everything">For now, a spend sends everything the group has confirmed to one address, less the fee.</string>
|
||||
<string name="while_the_wallet_is_new_at_most_s_sats">While the wallet is new, a spend on mainnet can send at most %1$s sats.</string>
|
||||
</resources>
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package com.machankura.bennu.compose.ui.composable
|
||||
|
||||
import com.machankura.bennu.compose.wallet.GroupWalletRollout
|
||||
import com.machankura.bennu.compose.ui.composable.navigation.routes.GroupWalletRoute
|
||||
import com.machankura.bennu.compose.nostr.wallet.GroupWalletStatementEvent
|
||||
import bennu.composeapp.generated.resources.open_on_s
|
||||
@@ -528,7 +529,7 @@ fun ChatRoomDetailScreen(
|
||||
// leaves the group. Shown to every member, open or
|
||||
// not -- the screen behind it is where a member who
|
||||
// can sign asks the group to open one.
|
||||
item {
|
||||
if (GroupWalletRollout.ENABLED) item {
|
||||
SignedWorkRow(
|
||||
icon = Icons.Default.AccountBalanceWallet,
|
||||
headline = stringResource(Res.string.group_wallet),
|
||||
|
||||
+24
-10
@@ -1,5 +1,8 @@
|
||||
package com.machankura.bennu.compose.ui.composable
|
||||
|
||||
import com.machankura.bennu.compose.wallet.GroupWalletRollout
|
||||
import bennu.composeapp.generated.resources.for_now_a_spend_sends_everything
|
||||
import bennu.composeapp.generated.resources.while_the_wallet_is_new_at_most_s_sats
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -159,19 +162,29 @@ fun GroupSendScreen(
|
||||
label = { Text(stringResource(Res.string.address)) },
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(stringResource(Res.string.send_everything))
|
||||
Switch(
|
||||
checked = groupSendViewModel.sendEverything.value,
|
||||
onCheckedChange = { groupSendViewModel.sendEverything.value = it },
|
||||
// Send-all only while the wallet is new: no switch, no amount,
|
||||
// and a sentence saying everything confirmed is what goes.
|
||||
if (GroupWalletRollout.SEND_AN_AMOUNT) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(stringResource(Res.string.send_everything))
|
||||
Switch(
|
||||
checked = groupSendViewModel.sendEverything.value,
|
||||
onCheckedChange = { groupSendViewModel.sendEverything.value = it },
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Text(
|
||||
text = stringResource(Res.string.for_now_a_spend_sends_everything),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
|
||||
if (!groupSendViewModel.sendEverything.value) {
|
||||
if (GroupWalletRollout.SEND_AN_AMOUNT && !groupSendViewModel.sendEverything.value) {
|
||||
OutlinedTextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
state = groupSendViewModel.amountField,
|
||||
@@ -255,6 +268,7 @@ private fun SendPreview(result: GroupSpendBuilder.Result, chain: Chain) {
|
||||
stringResource(Res.string.that_isn_t_an_address_on_s, GroupWalletStatementEvent.chainName(chain))
|
||||
GroupSpendBuilder.Result.NothingToSpend -> stringResource(Res.string.the_group_has_nothing_confirmed_to_spend)
|
||||
GroupSpendBuilder.Result.NotEnough -> stringResource(Res.string.the_group_doesn_t_have_that_much_confirmed)
|
||||
is GroupSpendBuilder.Result.OverCap -> stringResource(Res.string.while_the_wallet_is_new_at_most_s_sats, result.cap.grouped())
|
||||
else -> stringResource(Res.string.that_is_too_little_to_send)
|
||||
},
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
|
||||
+3
-1
@@ -1,5 +1,6 @@
|
||||
package com.machankura.bennu.compose.ui.view.model
|
||||
|
||||
import com.machankura.bennu.compose.wallet.GroupWalletRollout
|
||||
import androidx.compose.foundation.text.input.TextFieldState
|
||||
import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
|
||||
import androidx.compose.runtime.MutableState
|
||||
@@ -103,12 +104,13 @@ class GroupSendViewModel(
|
||||
val feerate = feerateField.text.toString().trim().toLongOrNull()?.takeIf { it > 0 } ?: return null
|
||||
val address = addressField.text.toString().trim().takeIf { it.isNotEmpty() } ?: return null
|
||||
|
||||
return if (sendEverything.value) {
|
||||
val built = if (sendEverything.value || !GroupWalletRollout.SEND_AN_AMOUNT) {
|
||||
GroupSpendBuilder.sendAll(walletState, address, feerate, state.reserved)
|
||||
} else {
|
||||
val amount = amountField.text.toString().filter { it.isDigit() }.toLongOrNull() ?: return null
|
||||
GroupSpendBuilder.send(walletState, address, Satoshi(amount), feerate, state.reserved)
|
||||
}
|
||||
return GroupSpendBuilder.capped(built, GroupWalletRollout.capFor(chain))
|
||||
}
|
||||
|
||||
fun propose(onSuccess: (sessionId: String) -> Unit, onFailure: () -> Unit) {
|
||||
|
||||
+10
@@ -34,8 +34,18 @@ object GroupSpendBuilder {
|
||||
data object BelowDust : Result
|
||||
/** A bump has to pay more than the spend it replaces. */
|
||||
data object NotHigher : Result
|
||||
/** More than [GroupWalletRollout.capFor] lets one spend send. */
|
||||
data class OverCap(val cap: Satoshi) : Result
|
||||
}
|
||||
|
||||
/**
|
||||
* [result] held to [cap]: the composer's gate while the wallet is new. A
|
||||
* built spend sending more than the cap is refused here, before a quorum is
|
||||
* asked; nothing at acceptance refuses one another build proposes.
|
||||
*/
|
||||
fun capped(result: Result, cap: Satoshi?): Result =
|
||||
if (cap != null && result is Result.Built && result.amount > cap) Result.OverCap(cap) else result
|
||||
|
||||
/** Every confirmed, unreserved coin, to [address], less the fee. */
|
||||
fun sendAll(state: GroupWalletState, address: String, feeratePerVbyte: Long, reserved: Set<OutPoint>): Result {
|
||||
val script = scriptOf(state, address) ?: return Result.NotAnAddress
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.machankura.bennu.compose.wallet
|
||||
|
||||
import fr.acinq.bitcoin.Chain
|
||||
import fr.acinq.bitcoin.Satoshi
|
||||
|
||||
/**
|
||||
* The gates the group wallet ships behind -- `docs/group-chain-wallet.md`, Phase
|
||||
* 10 -- in one place, each with the condition that lifts it.
|
||||
*
|
||||
* Entry points only. A device with a gate closed still accepts, shows and signs
|
||||
* a spend another member proposes, through every check `GroupSpend` makes: a
|
||||
* gate decides what this device offers, never what a quorum may decide.
|
||||
*/
|
||||
object GroupWalletRollout {
|
||||
/**
|
||||
* Whether the group's screen offers a wallet at all. Lifted when Phases 1-9
|
||||
* were in and the JVM suite passed, which they are and it did.
|
||||
*/
|
||||
const val ENABLED: Boolean = true
|
||||
|
||||
/**
|
||||
* Whether a member can send a chosen amount, with change, or only everything
|
||||
* to one address. Send-all only until send-an-amount has had a release with
|
||||
* nobody reporting a mislabelled change output.
|
||||
*/
|
||||
const val SEND_AN_AMOUNT: Boolean = false
|
||||
|
||||
/**
|
||||
* The most one spend proposed from this device may send on mainnet. Lifts
|
||||
* when a release has run real spends end to end with no session that failed
|
||||
* to aggregate and no transaction that failed to confirm. Test networks have
|
||||
* no cap: nothing on them is worth one.
|
||||
*/
|
||||
val MAINNET_CAP: Satoshi = Satoshi(100_000)
|
||||
|
||||
fun capFor(chain: Chain): Satoshi? = MAINNET_CAP.takeIf { chain.isMainnet() }
|
||||
}
|
||||
Reference in new issue
Block a user