Browse Source

Push down signing of refund transaction into `Dlc`

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

44
daemon/src/model/cfd.rs

@ -1057,26 +1057,7 @@ impl Cfd {
bail!("Refund transaction can only be constructed when in state PendingRefund, but we are currently in {}", self.state.clone())
};
let sig_hash = spending_tx_sighash(
&dlc.refund.0,
&dlc.commit.2,
Amount::from_sat(dlc.commit.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.refund.1;
let counterparty_pubkey = dlc.identity_counterparty;
let signed_refund_tx = finalize_spend_transaction(
dlc.refund.0,
&dlc.commit.2,
(our_pubkey, our_sig),
(counterparty_pubkey, counterparty_sig),
)?;
Ok(signed_refund_tx)
dlc.signed_refund_tx()
}
pub fn commit_tx(&self) -> Result<Transaction> {
@ -1585,6 +1566,29 @@ impl Dlc {
Role::Taker => self.taker_address.script_pubkey(),
}
}
pub fn signed_refund_tx(&self) -> Result<Transaction> {
let sig_hash = spending_tx_sighash(
&self.refund.0,
&self.commit.2,
Amount::from_sat(self.commit.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.refund.1;
let counterparty_pubkey = self.identity_counterparty;
let signed_refund_tx = finalize_spend_transaction(
self.refund.0.clone(),
&self.commit.2,
(our_pubkey, our_sig),
(counterparty_pubkey, counterparty_sig),
)?;
Ok(signed_refund_tx)
}
}
/// Information which we need to remember in order to construct a

Loading…
Cancel
Save