Most of this feature has been built and switched off. The plan is mostly about
why it is off and what has to be true before it can be switched on, not about a
new screen.
| piece | where | state |
|---|---|---|
| an amount, largest coin first, change to the next unused change address, dust change goes to the fee | `GroupSpendBuilder.send` | built, tested in `GroupSpendBuilderTest` |
| change counts as change only if its claimed derivation reproduces its script | `GroupSpend.check`, check 5 | built, runs on every member's device before signing |
| the approval screen shows every output, with change labelled as change | `FrostSigningScreen.WhatIsBeingSpent` | built |
| *Send everything* switch, *Amount in sats* field | `GroupSendScreen`, `GroupSendViewModel.amountField` / `sendEverything` | built, behind the gate |
| the gate | `GroupWalletRollout.SEND_AN_AMOUNT = false` | closed |
| the preview says how much change comes back | `SendPreview` | built |
The gate's own kdoc gives the lift condition: *"send-an-amount has had a release
with nobody reporting a mislabelled change output."* While the gate is a single
`const` that is false on every network, nobody can send an amount, so nobody can
report anything. **The condition cannot be met as the gate is written.** Phase 0
settles it by opening the gate on every network at once, and Phase 2 removes it.
Reading the gated code turned up five things to fix before the field is shown
to anyone:
1.**A decimal is silently multiplied.**`preview()` reads the amount with
`filter { it.isDigit() }`. Someone who types `21000.5` gets 210,005 sats, and
someone who types a bitcoin amount, `0.0005`, gets 5 sats. The first is a
tenfold overpayment that the preview shows only as a number.
2.**An amount too long for a `Long` disappears.**`toLongOrNull()` returns null,
`preview()` returns null, and the button stays disabled with no reason given.
3.**Two open spends with change pick the same change address.**
`nextChangeIndex` is the first change address Electrum has not seen used, and
a proposal waiting for signatures has not used it yet. Both proposals pay
change to `…/1/0`. Nothing is lost, but the address is reused, and change is
exactly the output whose job is to not be linked to anything.
4.**"Nothing to spend" is shown when the change branch has not loaded.**
`send` returns `NothingToSpend` when `nextChangeIndex` is null. That happens
before Electrum has answered for the change branch, while the group may hold
plenty.
5.**Dust change becomes fee without a word.** Phase 8 of the wallet note said
*"the remainder goes to fee, and the screen says so"*. The builder does it
and the screen does not: the preview shows a fee a few hundred sats higher
than the fee rate implies, and no reason.
---
## Phase 0: three decisions, before any code
**Half a day.** They change what Phases 2 and 4 build, so they come first.
1.**Where the gate opens first.** **Decided: on every network at once, relying
on the mainnet cap.** `MAINNET_CAP` already holds any one spend proposed from
this device to 100,000 sats, and that limit does not depend on the gate, so
the most a mislabelled change output can put at risk on mainnet is one capped
spend. Three things stand where the gate stood. The cap bounds the amount.
Check 5 runs on every signer's device. And Phase 3's end-to-end test is the
lab version of the report the gate was waiting for. The other option was
test networks first and mainnet after a release, the way `capFor` treats
networks. It was turned down because it delays mainnet by a release and buys
less than it looks, since the cap already makes the first mainnet spends
small.
2.**Whole sats only.** No bitcoin unit, no fiat, no decimal point. `Sats.kt`
already gives the reason for the wallet: comparing two integers is easier
than reading a decimal point eight places in. An input that contains a
decimal separator is refused with a message, never rounded or stripped.
3.**"Send everything" stays a switch, not a *Max* button.** A *Max* button
would fill the amount with `total − fee`. That value changes when the fee rate
changes, and it gives the group change it does not want when a coin confirms
between typing and pressing. The switch builds `sendAll`, which has no
change at all. That is the one difference between the two paths, and it should
stay visible in the form.
---
## Phase 1: the amount is sats, or says why not
**One day. Built.**
A parser and an output transformation in `text/Sats.kt`, next to `grouped()`,
so that reading and writing an amount are in one file:
```kotlin
sealedinterfaceSatsInput{
dataobjectEmpty:SatsInput
dataclassSats(valamount:Satoshi):SatsInput
dataobjectNotWhole:SatsInput// a decimal separator
dataobjectTooLarge:SatsInput// more than 21,000,000 bitcoin
dataobjectUnreadable:SatsInput// letters, or grouping that groups nothing
}
funparseSats(text:CharSequence):SatsInput
valGroupedSats:OutputTransformation
```
- **Grouping separators are allowed and dropped:** `,`, space, no-break space,
narrow no-break space, `'`, `_`. People paste `40,000` and `40 000`, and the
second is how a South African locale groups thousands.
- **`.` is refused, and so is `,` followed by one or two final digits**
(`40,5`, `40,50`), because in that locale those are decimals. `40,000` is
grouping.
- **Grouping has to group.** The first group has one to three digits and every
later group exactly three, or the input is `Unreadable`: `40,0000`, `4 0`,
`1234,567`. Guessing is how the bug above got in, and a reason that is not
about decimals deserved its own case rather than being filed under
`NotWhole`.
- **ASCII digits only.** Kotlin's `isDigit` accepts the digits of every script,
and so does the JVM's `toLong`.
- **At most `MAX_SATS`**, 2,100,000,000,000,000. Significant digits are counted
before `toLong()`, so a forty-digit paste is `TooLarge`, not an overflow.
**On the field, display only.** The plan said an `inputTransformation` would
store only digits. Built that way, a pasted `40,5` would have its comma
stripped and become 405, which is the same bug moved to the keyboard. So the
field holds exactly what was typed, `parseSats` is the only thing that reads
it, and `GroupedSats`, an `outputTransformation`, shows the text grouped as
`grouped()` writes it, but only when the text is plain digits. Anything else
is shown as it was typed, because regrouping `40,5` would show a number it is
not.
`GroupSendViewModel.amount()` is `parseSats(amountField.text)`, and `preview()`
returns `GroupSpendBuilder.Result.InvalidAmount(input)` for anything that is
neither `Sats` nor `Empty`. It does this before it checks for an address or a
fee rate, because a wrong amount is not an incomplete form. Until Phase 4
moves amount errors onto the field, `SendPreview` shows the three reasons in
the preview line.
**Tests**: `commonTest/…/text/SatsTest.kt` covers every separator, the decimal
cases, the unreadable ones, empty versus zero, `MAX_SATS` and its overflow,
and what `GroupedSats` shows. In `GroupSendViewModelJvmTest`, typing
`21000.5` reads as `NotWhole` and never builds a spend of 210,005.
**Half a day, mostly reading. Built: tests only, nothing needed fixing.** The
approval side has been built since the wallet note's Phase 8. This phase
checked that every place a spend is described reports the payment, not the
payment plus change.
| place | reads | with change, it says | tested by |
|---|---|---|---|
| `FrostSigningScreen.WhatIsBeingSpent` | every output and its `isChange` | a payment row, a change row labelled *back to the group as change*, the fee | `GroupSpendSigningJvmTest`: the other device's `checkedSpend` labels exactly the change output |
| `ProposedSpend.summarize`, which the proposal list and the wallet screen's spend rows both use | the single payment's amount | *Send 30,000 sats to bcrt1…* | `ProposedSpendTest`, new |
| `GroupWalletScreen`'s spend rows | `ProposedSpend.summarize(row.spend)` | the same as the row above | the same test: the plan had not read this row, and it turned out to reuse the summary, not compute its own amount |
| the *signed* line (`TYPE_FROST_COMPLETE`) and the *confirmed* line (`TYPE_GROUP_TRANSACTION_CONFIRMED`) | `amountSent`, which excludes change | *sending 30000 sats* and *30000 sats sent* | `GroupSpendSigningJvmTest`'s end-to-end case, which now runs `recordConfirmed` and reads both lines off the other device's transcript |
Both ran after every phase, and every phase was committed only once they
passed. At the end: 1,348 JVM tests passing, the Android compile clean, and
every audit budget and floor met.
**Still to do, by hand, on regtest**, with two devices in a group with an
opened wallet. This needs two devices with nodes, so it was not done while
building. Each step, and the automated test that comes closest:
| step | closest automated cover | what it cannot show |
|---|---|---|
| 1. fund it with two coins | — | |
| 2. send an amount that needs one coin, and check the preview's change matches the approval screen's on the other device | `GroupSpendSigningJvmTest`'s end-to-end case: the builder's `change` equals the other device's checked change output | the two screens drawn side by side |
| 3. with the first spend open, send a second, and check it picks the other coin and a different change address | the same test, with an open spend holding index 0 and the second paying index 1 | reservations read through the real repository after a real round of messages |
| 4. sign both, confirm both, and check that both change coins are in the confirmed balance | the same test's `confirmedBalance`, and `GroupOnchainWalletJvmTest`'s change coin over a fake Electrum | a real Electrum server reporting the change address |
| 5. send an amount that leaves dust change, and check the *go to the fee* line | `GroupSpendBuilderTest`'s dust case for `absorbed` | the line itself on screen: no screen test produces dust change |
The wallet note's tables were updated in Phase 2, and this note was added to