Skip to content

Commit 4ff63e0

Browse files
doc: sendall
1 parent 0d7137e commit 4ff63e0

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

docs/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* [Burn](burn.md)
2020
* [Manual Coin Selection]() #(manual.md) ❌
2121
* [Add External Inputs]() #(external.md) ❌
22-
* [Send All Funds]() #(sendall.md)
22+
* [Send All Funds](sendall.md)
2323
* [Explicit Input and Outputs]() #(explicit.md) ❌
2424
* [AMP0](amp0.md)
2525
* [AMP2]() #(amp2.md) ❌

docs/src/sendall.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,45 @@
11
# Send All Funds
2+
Sending all funds (also called "draining" the wallet) allows you to send all LBTC (policy asset) from your wallet to a specified address in a single transaction. This is useful when you want to empty your wallet, consolidate UTXOs, or transfer all funds to another address.
3+
4+
When you drain a wallet, all available LBTC UTXOs are selected as inputs, and after deducting transaction fees, the remaining amount is sent to the destination address. Note that draining only affects LBTC (the policy asset).
5+
6+
"Drain" is only available for the asset used to pay fees (LBTC) with. For LBTC it's hard to guess the right amount to send all funds: it's the sum of all LBTC inputs minus the fee, but you don't know the actual fee until you created the transaction. So we need a way specify the TxBuilder to send all LBTC.
7+
8+
For assets that are not LBTC, the caller can easily compute the sum of all asset in input and set the satoshi value explicitly.
9+
10+
To send all LBTC, use `TxBuilder::drain_lbtc_wallet()`. By default LBTC are sent to a wallet address, if you want specify the destination address use `TxBuilder::drain_lbtc_to()`.
11+
12+
The methods take the following arguments:
13+
14+
1. **`drain_lbtc_wallet()`**: No arguments. Selects all available LBTC UTXOs from the wallet to be spent.
15+
2. **`drain_lbtc_to(address)`**: Takes an `Address` parameter specifying where to send all the LBTC after fees are deducted.
16+
17+
<custom-tabs category="lang">
18+
<div slot="title">Rust</div>
19+
<section>
20+
21+
```rust,ignore
22+
{{#include ../../lwk_wollet/tests/e2e.rs:drain_lbtc_wallet}}
23+
```
24+
25+
</section>
26+
27+
<div slot="title">Python</div>
28+
<section>
29+
30+
```python
31+
{{#include ../../lwk_bindings/tests/bindings/external_utxos.py:drain_lbtc_wallet}}
32+
```
33+
34+
</section>
35+
</custom-tabs>
36+
37+
## Next Steps
38+
39+
After sending all funds, you can:
40+
* Send other assets using regular [transaction creation](tx.md)
41+
* Receive new funds at any address in your wallet
42+
43+
----
44+
45+
Previous: [Burn](burn.md)

lwk_bindings/tests/bindings/external_utxos.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
w2.is_segwit()
3333
)
3434

35+
# ANCHOR: drain_lbtc_wallet
3536
node_addr = node.get_new_address()
36-
# Create speding tx sending all to the node
37+
# Create speding tx sending all to the node # ANCHOR: ignore
3738
builder = network.tx_builder()
38-
builder.add_external_utxos([utxo_w2])
39+
builder.add_external_utxos([utxo_w2]) # ANCHOR: ignore
3940
builder.drain_lbtc_wallet()
4041
builder.drain_lbtc_to(node_addr)
4142
pset = builder.finish(w1)
43+
# ANCHOR_END: drain_lbtc_wallet
4244

4345
pset = s1.sign(pset)
4446

lwk_wollet/tests/e2e.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ fn wait_esplora_tx_update(client: &mut blocking::EsploraClient, wollet: &Wollet)
20112011

20122012
#[cfg(feature = "esplora")]
20132013
#[test]
2014-
fn test_waterfalls_esplora() {
2014+
fn test_waterfalls_esplora() -> Result<(), Box<dyn std::error::Error>> {
20152015
// TODO: use TestWollet also for EsploraClient
20162016
let env = TestEnvBuilder::from_env().with_waterfalls().build();
20172017

@@ -2039,13 +2039,14 @@ fn test_waterfalls_esplora() {
20392039
let balance = wollet.balance().unwrap();
20402040
assert_eq!(sats, *balance.get(&network.policy_asset()).unwrap());
20412041

2042+
// ANCHOR: drain_lbtc_wallet
20422043
let address = env.elementsd_getnewaddress();
20432044
let mut pset = wollet
20442045
.tx_builder()
20452046
.drain_lbtc_wallet()
20462047
.drain_lbtc_to(address.clone())
2047-
.finish()
2048-
.unwrap();
2048+
.finish()?;
2049+
// ANCHOR_END: drain_lbtc_wallet
20492050

20502051
let sigs = signer.sign(&mut pset).unwrap();
20512052
assert!(sigs > 0);
@@ -2071,6 +2072,8 @@ fn test_waterfalls_esplora() {
20712072
assert_eq!(history.len(), 1);
20722073
assert_eq!(history[0].len(), 1);
20732074
assert_eq!(history[0][0].txid, txid);
2075+
2076+
Ok(())
20742077
}
20752078

20762079
#[cfg(feature = "esplora")]

0 commit comments

Comments
 (0)