Skip to content

Commit

Permalink
db: remove the db_cancel_transaction routine
Browse files Browse the repository at this point in the history
It was specific to single-Cancel logic
  • Loading branch information
darosior committed May 3, 2022
1 parent 2e2a02b commit c2f5d24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 39 deletions.
22 changes: 14 additions & 8 deletions src/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ mod tests {
},
bitcointx::RevaultTx,
interface::{
db_cancel_transaction, db_emer_transaction, db_exec, db_unvault_emer_transaction,
db_unvault_transaction, db_vault_by_deposit,
db_emer_transaction, db_exec, db_unvault_emer_transaction, db_unvault_transaction,
db_vault_by_deposit,
},
schema::{DbTransaction, DbVault},
},
Expand Down Expand Up @@ -641,9 +641,12 @@ mod tests {
.map(|o| db_vault_by_deposit(&db_file, &o).unwrap().unwrap())
.collect();

let tx_db = db_cancel_transaction(&db_file, vaults[2].id)
.unwrap()
.unwrap();
let tx_db = db_cancel_transaction_by_txid(
&db_file,
&transactions[2].as_ref().unwrap().initial_cancel.txid(),
)
.unwrap()
.unwrap();
update_presigned_tx(
&db_file,
&vaults[2],
Expand Down Expand Up @@ -722,9 +725,12 @@ mod tests {
)
.unwrap();

let tx_db = db_cancel_transaction(&db_file, vaults[3].id)
.unwrap()
.unwrap();
let tx_db = db_cancel_transaction_by_txid(
&db_file,
&transactions[3].as_ref().unwrap().initial_cancel.txid(),
)
.unwrap()
.unwrap();
update_presigned_tx(
&db_file,
&vaults[3],
Expand Down
24 changes: 11 additions & 13 deletions src/database/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ mod test {
assert!(db_signed_unemer_txs(&db_path).unwrap().is_empty());

// Sanity check we can add sigs to them now
let stored_cancel_tx = db_cancel_transaction(&db_path, db_vault.id)
let stored_cancel_tx = db_cancel_transaction_by_txid(&db_path, &fresh_cancel_tx.txid())
.unwrap()
.unwrap();
assert_eq!(
Expand All @@ -1301,7 +1301,7 @@ mod test {
&cancel_tx.psbt().inputs[0].partial_sigs,
&revaultd.secp_ctx,
);
let stored_cancel_tx = db_cancel_transaction(&db_path, db_vault.id)
let stored_cancel_tx = db_cancel_transaction_by_txid(&db_path, &fresh_cancel_tx.txid())
.unwrap()
.unwrap();
assert_eq!(
Expand Down Expand Up @@ -1402,16 +1402,12 @@ mod test {
);
assert_eq!(
cancel_tx,
db_cancel_transaction(&db_path, db_vault.id)
db_cancel_transaction_by_txid(&db_path, &fresh_cancel_tx.txid())
.unwrap()
.unwrap()
.psbt
.assert_cancel()
);
assert_eq!(
db_cancel_transaction(&db_path, db_vault.id).unwrap(),
db_cancel_transaction_by_txid(&db_path, &cancel_tx.txid()).unwrap()
);
assert_eq!(
unemer_tx,
db_unvault_emer_transaction(&db_path, db_vault.id)
Expand Down Expand Up @@ -1447,9 +1443,11 @@ mod test {
assert!(db_emer_transaction(&db_path, db_vault.id)
.unwrap()
.is_none());
assert!(db_cancel_transaction(&db_path, db_vault.id)
.unwrap()
.is_none());
assert!(
db_cancel_transaction_by_txid(&db_path, &fresh_cancel_tx.txid())
.unwrap()
.is_none()
);
assert!(db_unvault_emer_transaction(&db_path, db_vault.id)
.unwrap()
.is_none());
Expand Down Expand Up @@ -1640,7 +1638,7 @@ mod test {
)
.unwrap();

let stored_cancel_tx = db_cancel_transaction(&db_path, db_vault.id)
let stored_cancel_tx = db_cancel_transaction_by_txid(&db_path, &fresh_cancel_tx.txid())
.unwrap()
.unwrap();
let mut cancel_tx = fresh_cancel_tx.clone();
Expand Down Expand Up @@ -1983,13 +1981,13 @@ mod test {
9,
9,
&fresh_unvault_tx,
&[fresh_cancel_tx],
&[fresh_cancel_tx.clone()],
Some(&fresh_emergency_tx),
Some(&fresh_unvaultemergency_tx),
)
.unwrap();

let stored_cancel_tx = db_cancel_transaction(&db_path, db_vault.id)
let stored_cancel_tx = db_cancel_transaction_by_txid(&db_path, &fresh_cancel_tx.txid())
.unwrap()
.unwrap();
update_presigned_tx(
Expand Down
18 changes: 0 additions & 18 deletions src/database/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ pub fn db_unvault_from_deposit(
Ok(db_unvault.map(|db_tx| db_tx.psbt.assert_unvault()))
}

// NOTE: don't forget you can't assume the Vec isn't empty because threads!
/// Get a Cancel transaction by its transaction id.
pub fn db_cancel_transaction_by_txid(
db_path: &Path,
Expand All @@ -573,23 +572,6 @@ pub fn db_cancel_transaction_by_txid(
.map(|mut rows| rows.pop())
}

/// Get the Cancel transaction corresponding to this vault
///
/// NOTE: the transaction *might* not be here even if you polled the vault status
/// beforehand, because it is a new database transaction.
pub fn db_cancel_transaction(
db_path: &Path,
vault_id: u32,
) -> Result<Option<DbTransaction>, DatabaseError> {
db_query(
db_path,
"SELECT * FROM presigned_transactions WHERE vault_id = (?1) AND type = (?2)",
params![vault_id, TransactionType::Cancel as u32],
|row| row.try_into(),
)
.map(|mut rows| rows.pop())
}

/// Get the Emergency transaction corresponding to this vault.
///
/// NOTE: the transaction *might* not be here even if you polled the vault status
Expand Down

0 comments on commit c2f5d24

Please sign in to comment.