Skip to content

Commit

Permalink
commands: adapt the result of 'listpresignedtxs' to multiple Cancel txs
Browse files Browse the repository at this point in the history
  • Loading branch information
darosior committed May 2, 2022
1 parent 1e100db commit 07c233e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
14 changes: 7 additions & 7 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ vault's state).

#### Presigned txs

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


### `listonchaintransactions`
Expand Down
2 changes: 1 addition & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ pub struct RevocationTransactions {
pub struct ListPresignedTxEntry {
pub vault_outpoint: OutPoint,
pub unvault: UnvaultTransaction,
pub cancel: CancelTransaction,
pub cancel: [CancelTransaction; 5],
/// Always None if not stakeholder
pub emergency: Option<EmergencyTransaction>,
/// Always None if not stakeholder
Expand Down
29 changes: 21 additions & 8 deletions src/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::{
},
database::{
interface::{
db_cancel_transaction, db_emer_transaction, db_signed_emer_txs, db_signed_unemer_txs,
db_unvault_emer_transaction, db_unvault_transaction, db_vault_by_deposit, db_vaults,
db_vaults_with_txids_in_period,
db_cancel_transaction_by_txid, db_emer_transaction, db_signed_emer_txs,
db_signed_unemer_txs, db_unvault_emer_transaction, db_unvault_transaction,
db_vault_by_deposit, db_vaults, db_vaults_with_txids_in_period,
},
schema::DbVault,
DatabaseError,
Expand All @@ -25,7 +25,7 @@ use revault_tx::{
Transaction as BitcoinTransaction, Txid,
},
miniscript::DescriptorTrait,
transactions::RevaultTransaction,
transactions::{transaction_chain_manager, RevaultTransaction},
};

use std::{
Expand Down Expand Up @@ -161,10 +161,23 @@ pub fn presigned_txs(
.expect("Database must be available")?
.psbt
.assert_unvault();
let cancel = db_cancel_transaction(db_path, db_vault.id)
.expect("Database must be available")?
.psbt
.assert_cancel();
let (_, cancel_batch) = transaction_chain_manager(
db_vault.deposit_outpoint,
db_vault.amount,
&revaultd.deposit_descriptor,
&revaultd.unvault_descriptor,
&revaultd.cpfp_descriptor,
db_vault.derivation_index,
&revaultd.secp_ctx,
)
.expect("We wouldn't have put a vault with an invalid chain in DB");
let mut cancel = cancel_batch.all_feerates();
for cancel_tx in cancel.iter_mut() {
*cancel_tx = db_cancel_transaction_by_txid(db_path, &cancel_tx.txid())
.expect("Database must always be available")?
.psbt
.assert_cancel();
}

let mut emergency = None;
let mut unvault_emergency = None;
Expand Down
3 changes: 2 additions & 1 deletion tests/test_framework/revault_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,12 @@ def signed_unvault_psbt(self, deposit, derivation_index):
def signed_cancel_psbt(self, deposit, derivation_index):
"""Get the fully-signed Cancel transaction for this deposit.
This picks the lowest feerate version.
This will raise if we don't have all the signatures.
"""
psbt_str = self.stks()[0].rpc.listpresignedtransactions([deposit])[
"presigned_transactions"
][0]["cancel"]
][0]["cancel"][0]
psbt = serializations.PSBT()
psbt.deserialize(psbt_str)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,13 +1080,13 @@ def test_revault_command(revault_network, bitcoind, executor):
== len(stks[0].rpc.listvaults(["funded"])["vaults"])
)

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

cancel_psbt.tx.calc_sha256()
Expand Down

0 comments on commit 07c233e

Please sign in to comment.