Skip to content

cli: send to several receivers in one command (#364) - #2163

Open
vsnation wants to merge 1 commit into
BeamMW:masterfrom
vsnation:fix/364-sendmany
Open

vsnation wants to merge 1 commit into
BeamMW:masterfrom
vsnation:fix/364-sendmany

Conversation

@vsnation

Copy link
Copy Markdown

Fix: beam-wallet send can pay several receivers in one command (#364).

beam-wallet send --receivers "ADDR1:1.5,ADDR2:0.25" [--fee N] [--asset_id N] [--offline]
beam-wallet send --receivers_file payees.txt          # one "ADDR:AMOUNT" per line, '#' comments

Why / design: a Mimblewimble tx has one receiver, so there's no bitcoin-style single tx with many outputs. The command starts one tx per receiver in the same wallet session and waits until all of them finish (the CLI used to wait for exactly one). In the core, coin selection (CompleteBalance) and coin tagging (SaveCoins) run in the same synchronous step per tx, so two txs never take the same coins.

Checked before anything starts: entry format, amounts, duplicate receivers, address validity, options that can't be combined (--amount, -r, --utxo, --slatepack), and total amount + fees against the available balance.

How to see it (no node needed for the checks)

beam-wallet restore --pass=p --wallet_path=a.db --seed_phrase="abandon;abandon;abandon;abandon;abandon;abandon;abandon;abandon;abandon;abandon;abandon;about;"
beam-wallet send --pass=p --wallet_path=a.db -n 127.0.0.1:1 --receivers "<addr1>:1,<addr2>:2"
# master: unrecognised option '--receivers'

Improvement

input master this PR
--receivers A1:1,A2:2 (empty wallet) unrecognised option '--receivers' Not enough funds: 2 transactions need 3 BEAM plus 0.000002 BEAM in fees
--receivers_file payees.txt unrecognised option same check, 1.75 BEAM
--receivers A1:1,A1:2 – duplicate receiver 'A1'
--receivers A1 / A1:0 – invalid receiver entry …, expected <address>:<amount> / … Unable to send zero coins
--receivers A1:1 --amount 1 – --receivers and --receivers_file can't be combined with --receiver_addr, --amount, --utxo or --slatepack
funded wallet – Transaction <txid> started: sending <amt> to <addr> per receiver; exits when all are done

Single send is unchanged. Two small side effects of sharing the amount parser (ParseAmount): amounts under 1 groth and nan are rejected (they used to become a 0-amount tx), and an invalid --amount error is now one line: the amount ('abc') is invalid. ….

Limits: with few big coins, change from the first tx isn't spendable until it confirms, so later txs can fail with "no inputs" even though the total balance is enough. Run split first in that case. Every SBBS receiver must come online, as with send. The txs aren't queued one after another, as suggested in the issue's comment; they start together.

Testing: new wallet_cli_test (list and amount parsing: file format, comments, malformed entries, zero, negative, 1,5, duplicates, sub-groth, nan, inf) passes; with the duplicate check disabled it fails 2 checks. New TestSendToManyReceivers (wallet_test, in-process test node) passes: one sender starts two txs back to back, both complete, each receiver gets its amount, and no coin is spent by both txs. The CLI rows above compare master and this branch. Fork CI (running): https://github.com/vsnation/beam/actions/runs/

Fixes #364

`send --receivers "<addr>:<amount>,..."` or `--receivers_file <path>`
(one "addr:amount" per line, '#' comments) starts one transaction per
receiver in the same wallet session and waits until all of them finish.
Mimblewimble txs have a single receiver, so a bitcoin-style sendmany
output list isn't possible; coin selection and SaveCoins run in the
same synchronous step per tx, so the txs never pick the same coins.

Everything is checked before any tx starts: entry format, amounts,
duplicate receivers, address validity, conflicting options (--amount,
-r, --utxo, --slatepack), and total amount + fees vs the available
balance. --fee, --asset_id and --offline apply to every tx.

ReadAmount's parsing moved to ParseAmount (shared); it now also rejects
nan and amounts under 1 groth (they became a 0-amount tx).

Tests: wallet_cli_test (new; list and amount parsing) and
TestSendToManyReceivers (two txs from one session on the test node).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sendmany command

1 participant