Browse Source

Push down signing of commit transaction into `Dlc`

See https://github.com/itchysats/itchysats/issues/646.
debug-collab-settlement
Thomas Eizinger 3 years ago
parent
commit
e01d84f578
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 48
      daemon/src/model/cfd.rs

48
daemon/src/model/cfd.rs

@ -1073,28 +1073,7 @@ impl Cfd {
)
};
let sig_hash = spending_tx_sighash(
&dlc.commit.0,
&dlc.lock.1,
Amount::from_sat(dlc.lock.0.output[0].value),
);
let our_sig = SECP256K1.sign(&sig_hash, &dlc.identity);
let our_pubkey = PublicKey::new(bdk::bitcoin::secp256k1::PublicKey::from_secret_key(
SECP256K1,
&dlc.identity,
));
let counterparty_sig = dlc.commit.1.decrypt(&dlc.publish)?;
let counterparty_pubkey = dlc.identity_counterparty;
let signed_commit_tx = finalize_spend_transaction(
dlc.commit.0,
&dlc.lock.1,
(our_pubkey, our_sig),
(counterparty_pubkey, counterparty_sig),
)?;
Ok(signed_commit_tx)
dlc.signed_commit_tx()
}
pub fn cet(&self) -> Result<Result<Transaction, NotReadyYet>> {
@ -1589,6 +1568,31 @@ impl Dlc {
Ok(signed_refund_tx)
}
pub fn signed_commit_tx(&self) -> Result<Transaction> {
let sig_hash = spending_tx_sighash(
&self.commit.0,
&self.lock.1,
Amount::from_sat(self.lock.0.output[0].value),
);
let our_sig = SECP256K1.sign(&sig_hash, &self.identity);
let our_pubkey = PublicKey::new(bdk::bitcoin::secp256k1::PublicKey::from_secret_key(
SECP256K1,
&self.identity,
));
let counterparty_sig = self.commit.1.decrypt(&self.publish)?;
let counterparty_pubkey = self.identity_counterparty;
let signed_commit_tx = finalize_spend_transaction(
self.commit.0.clone(),
&self.lock.1,
(our_pubkey, our_sig),
(counterparty_pubkey, counterparty_sig),
)?;
Ok(signed_commit_tx)
}
}
/// Information which we need to remember in order to construct a

Loading…
Cancel
Save