Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,19 +461,25 @@ cover the requested feerate.

#### Request

| Field | Type | Description |
| ---------- | ---------------------- | ----------------------------------------------------------------------------------------- |
| `address` | str | The Bitcoin address to sweep the coins to. |
| `feerate` | integer | Target feerate for the transaction, in satoshis per virtual byte. |
| `timelock` | int (optional) | Recovery path to be used, identified by the number of blocks after which it is available. |
| `outpoints`| list of str (optional) | List of the coins to be recovered, as `txid:vout`. |
| Field | Type | Description |
| ------------------- | ---------------------- | ----------------------------------------------------------------------------------------- |
| `address` | str | The Bitcoin address to sweep the coins to. |
| `feerate` | integer | Target feerate for the transaction, in satoshis per virtual byte. |
| `timelock` | int (optional) | Recovery path to be used, identified by the number of blocks after which it is available. |
| `outpoints` | list of str (optional) | List of the coins to be recovered, as `txid:vout`. |
| `allow_own_address` | bool (optional) | Allow an address that belongs to this same wallet as recovery (default: `false`). |


#### Response

| Field | Type | Description |
| -------------- | --------- | ---------------------------------------------------- |
| `psbt` | string | PSBT of the recovery transaction, encoded as base64. |
| Field | Type | Description |
| -------------- | ----------- | ----------------------------------------------------- |
| `psbt` | string | PSBT of the recovery transaction, encoded as base64. |
| `warnings` | list of str | Warnings, if any, generated during recovery creation. |

An error (code 1001) will be returned if the sweep address is known to belong to this wallet,
since recovered funds would be locked under the same descriptor again. Set `allow_own_address`
to proceed anyway; a warning will then be included in the `warnings` response field instead.

### `updatelabels`

Expand Down
9 changes: 8 additions & 1 deletion liana-gui/src/app/state/spend/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,13 @@ impl DefineSpend {
// If recovery timelock is set, create a recovery transaction. Otherwise, a regular spend.
if let Some(reco_tl) = recovery_timelock {
daemon
.create_recovery(max_address.clone(), &outpoints, feerate_vb, Some(reco_tl))
.create_recovery(
max_address.clone(),
&outpoints,
feerate_vb,
Some(reco_tl),
Some(true), // TODO(#1654)
)
.await
// Map the PSBT to `CreateSpendResult` result. We only need the PSBT below.
.map(|psbt| CreateSpendResult::Success {
Expand Down Expand Up @@ -735,6 +741,7 @@ impl Step for DefineSpend {
&inputs,
feerate_vb,
Some(reco_tl),
Some(true), // TODO(#1654)
)
.await
.map_err(|e| e.into())
Expand Down
4 changes: 4 additions & 0 deletions liana-gui/src/daemon/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl<C: Client + Send + Sync + Debug> Daemon for Lianad<C> {
coins_outpoints: &[OutPoint],
feerate_vb: u64,
sequence: Option<u16>,
allow_own_address: Option<bool>,
) -> Result<Psbt, DaemonError> {
let mut params = serde_json::Map::new();
params.insert("address".to_string(), json!(address));
Expand All @@ -217,6 +218,9 @@ impl<C: Client + Send + Sync + Debug> Daemon for Lianad<C> {
if let Some(sequence) = sequence {
params.insert("timelock".to_string(), json!(sequence));
}
if let Some(allow_own_address) = allow_own_address {
params.insert("allow_own_address".to_string(), json!(allow_own_address));
}
let res: CreateRecoveryResult = self.call("createrecovery", Some(params))?;
Ok(res.psbt)
}
Expand Down
9 changes: 8 additions & 1 deletion liana-gui/src/daemon/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,17 @@ impl Daemon for EmbeddedDaemon {
coins_outpoints: &[OutPoint],
feerate_vb: u64,
sequence: Option<u16>,
allow_own_address: Option<bool>,
) -> Result<Psbt, DaemonError> {
self.command(|daemon| {
daemon
.create_recovery(address, coins_outpoints, feerate_vb, sequence)
.create_recovery(
address,
coins_outpoints,
feerate_vb,
sequence,
allow_own_address,
)
.map(|res| res.psbt)
.map_err(|e| DaemonError::Unexpected(e.to_string()))
})
Expand Down
1 change: 1 addition & 0 deletions liana-gui/src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub trait Daemon: Debug {
coins_outpoints: &[OutPoint],
feerate_vb: u64,
sequence: Option<u16>,
allow_own_address: Option<bool>,
) -> Result<Psbt, DaemonError>;
async fn list_txs(&self, txid: &[Txid]) -> Result<model::ListTransactionsResult, DaemonError>;
async fn get_labels(
Expand Down
3 changes: 3 additions & 0 deletions liana-gui/src/services/connect/client/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,12 +930,15 @@ impl Daemon for BackendWalletClient {
Err(DaemonError::NoAnswer)
}

// TODO(#1654): the own-address check is not enforced here (need to check how
// the backend API could use allow_own_address param)
async fn create_recovery(
&self,
address: Address<address::NetworkUnchecked>,
coins_outpoints: &[OutPoint],
feerate_vb: u64,
sequence: Option<u16>,
_allow_own_address: Option<bool>,
) -> Result<Psbt, DaemonError> {
let timelock = sequence.ok_or(DaemonError::Unexpected("Missing sequence".to_string()))?;
let res: api::DraftPsbt = self
Expand Down
Loading
Loading