Skip to content

Commit 2e2a02b

Browse files
committed
commands: adapt the result of 'listpresignedtxs' to multiple Cancel txs
1 parent 28a9461 commit 2e2a02b

5 files changed

Lines changed: 33 additions & 19 deletions

File tree

doc/API.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ vault's state).
188188

189189
#### Presigned txs
190190

191-
| Field | Type | Description |
192-
| ------------------- | -------- | ---------------------------------------------------------------------------------------------- |
193-
| `vault_outpoint` | string | The vault deposit transaction outpoint. |
194-
| `unvault` | string | The Unvaulting transaction PSBT (base64 encoded) |
195-
| `cancel` | string | The Cancel transaction PSBT (base64 encoded) |
196-
| `emergency` | string | The Emergency transaction PSBT (base64 encoded), or `null` if we are not a stakeholder |
197-
| `unvault_emergency` | string | The Unvault Emergency transaction PSBT (base64 encoded), or `null` if we are not a stakeholder |
191+
| Field | Type | Description |
192+
| ------------------- | -------- | ---------------------------------------------------------------------------------------------- |
193+
| `vault_outpoint` | string | The vault deposit transaction outpoint. |
194+
| `unvault` | string | The Unvaulting transaction PSBT (base64 encoded) |
195+
| `cancel` | string array | List of base64-encoded Cancel transactions PSBT |
196+
| `emergency` | string | The Emergency transaction PSBT (base64 encoded), or `null` if we are not a stakeholder |
197+
| `unvault_emergency` | string | The Unvault Emergency transaction PSBT (base64 encoded), or `null` if we are not a stakeholder |
198198

199199

200200
### `listonchaintransactions`

src/commands/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ pub struct RevocationTransactions {
15051505
pub struct ListPresignedTxEntry {
15061506
pub vault_outpoint: OutPoint,
15071507
pub unvault: UnvaultTransaction,
1508-
pub cancel: CancelTransaction,
1508+
pub cancel: [CancelTransaction; 5],
15091509
/// Always None if not stakeholder
15101510
pub emergency: Option<EmergencyTransaction>,
15111511
/// Always None if not stakeholder

src/commands/utils.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::{
88
},
99
database::{
1010
interface::{
11-
db_cancel_transaction, db_emer_transaction, db_signed_emer_txs, db_signed_unemer_txs,
12-
db_unvault_emer_transaction, db_unvault_transaction, db_vault_by_deposit, db_vaults,
13-
db_vaults_with_txids_in_period,
11+
db_cancel_transaction_by_txid, db_emer_transaction, db_signed_emer_txs,
12+
db_signed_unemer_txs, db_unvault_emer_transaction, db_unvault_transaction,
13+
db_vault_by_deposit, db_vaults, db_vaults_with_txids_in_period,
1414
},
1515
schema::DbVault,
1616
DatabaseError,
@@ -25,7 +25,7 @@ use revault_tx::{
2525
Transaction as BitcoinTransaction, Txid,
2626
},
2727
miniscript::DescriptorTrait,
28-
transactions::RevaultTransaction,
28+
transactions::{transaction_chain_manager, RevaultTransaction},
2929
};
3030

3131
use std::{
@@ -161,10 +161,23 @@ pub fn presigned_txs(
161161
.expect("Database must be available")?
162162
.psbt
163163
.assert_unvault();
164-
let cancel = db_cancel_transaction(db_path, db_vault.id)
165-
.expect("Database must be available")?
166-
.psbt
167-
.assert_cancel();
164+
let (_, cancel_batch) = transaction_chain_manager(
165+
db_vault.deposit_outpoint,
166+
db_vault.amount,
167+
&revaultd.deposit_descriptor,
168+
&revaultd.unvault_descriptor,
169+
&revaultd.cpfp_descriptor,
170+
db_vault.derivation_index,
171+
&revaultd.secp_ctx,
172+
)
173+
.expect("We wouldn't have put a vault with an invalid chain in DB");
174+
let mut cancel = cancel_batch.all_feerates();
175+
for cancel_tx in cancel.iter_mut() {
176+
*cancel_tx = db_cancel_transaction_by_txid(db_path, &cancel_tx.txid())
177+
.expect("Database must always be available")?
178+
.psbt
179+
.assert_cancel();
180+
}
168181

169182
let mut emergency = None;
170183
let mut unvault_emergency = None;

tests/test_framework/revault_network.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,12 @@ def signed_unvault_psbt(self, deposit, derivation_index):
454454
def signed_cancel_psbt(self, deposit, derivation_index):
455455
"""Get the fully-signed Cancel transaction for this deposit.
456456
457+
This picks the lowest feerate version.
457458
This will raise if we don't have all the signatures.
458459
"""
459460
psbt_str = self.stks()[0].rpc.listpresignedtransactions([deposit])[
460461
"presigned_transactions"
461-
][0]["cancel"]
462+
][0]["cancel"][0]
462463
psbt = serializations.PSBT()
463464
psbt.deserialize(psbt_str)
464465

tests/test_rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,13 +1080,13 @@ def test_revault_command(revault_network, bitcoind, executor):
10801080
== len(stks[0].rpc.listvaults(["funded"])["vaults"])
10811081
)
10821082

1083-
# And the deposit txid is the Cancel txid
1083+
# And the deposit txid is the lowest-feerate Cancel's txid
10841084
for v in stks[0].rpc.listvaults(["canceled"])["vaults"]:
10851085
deposit = f"{v['txid']}:{v['vout']}"
10861086
cancel_psbt = serializations.PSBT()
10871087
cancel_b64 = stks[0].rpc.listpresignedtransactions([deposit])[
10881088
"presigned_transactions"
1089-
][0]["cancel"]
1089+
][0]["cancel"][0]
10901090
cancel_psbt.deserialize(cancel_b64)
10911091

10921092
cancel_psbt.tx.calc_sha256()

0 commit comments

Comments
 (0)