mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-23 05:41:07 -05:00
Remove Tx
arguments from add_signatures
functions
The only reason we need this argument is because we need to access the output descriptor. We can save that one ahead of time at when we construct the type.
This commit is contained in:
parent
0f8fbd087f
commit
6c38d66864
@ -58,6 +58,7 @@ pub struct TxCancel {
|
||||
inner: Transaction,
|
||||
digest: SigHash,
|
||||
pub(in crate::bitcoin) output_descriptor: Descriptor<::bitcoin::PublicKey>,
|
||||
lock_output_descriptor: Descriptor<::bitcoin::PublicKey>,
|
||||
}
|
||||
|
||||
impl TxCancel {
|
||||
@ -99,6 +100,7 @@ impl TxCancel {
|
||||
inner: transaction,
|
||||
digest,
|
||||
output_descriptor: cancel_output_descriptor,
|
||||
lock_output_descriptor: tx_lock.output_descriptor.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +122,6 @@ impl TxCancel {
|
||||
|
||||
pub fn add_signatures(
|
||||
self,
|
||||
tx_lock: &TxLock,
|
||||
(A, sig_a): (PublicKey, Signature),
|
||||
(B, sig_b): (PublicKey, Signature),
|
||||
) -> Result<Transaction> {
|
||||
@ -144,8 +145,7 @@ impl TxCancel {
|
||||
};
|
||||
|
||||
let mut tx_cancel = self.inner;
|
||||
tx_lock
|
||||
.output_descriptor
|
||||
self.lock_output_descriptor
|
||||
.satisfy(&mut tx_cancel.input[0], satisfier)?;
|
||||
|
||||
Ok(tx_cancel)
|
||||
|
@ -2,13 +2,14 @@ use crate::bitcoin::{Address, PublicKey, PunishTimelock, Transaction, TxCancel};
|
||||
use ::bitcoin::{util::bip143::SigHashCache, SigHash, SigHashType};
|
||||
use anyhow::Result;
|
||||
use ecdsa_fun::Signature;
|
||||
use miniscript::DescriptorTrait;
|
||||
use miniscript::{Descriptor, DescriptorTrait};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TxPunish {
|
||||
inner: Transaction,
|
||||
digest: SigHash,
|
||||
cancel_output_descriptor: Descriptor<::bitcoin::PublicKey>,
|
||||
}
|
||||
|
||||
impl TxPunish {
|
||||
@ -29,6 +30,7 @@ impl TxPunish {
|
||||
Self {
|
||||
inner: tx_punish,
|
||||
digest,
|
||||
cancel_output_descriptor: tx_cancel.output_descriptor.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +40,6 @@ impl TxPunish {
|
||||
|
||||
pub fn add_signatures(
|
||||
self,
|
||||
tx_cancel: &TxCancel,
|
||||
(A, sig_a): (PublicKey, Signature),
|
||||
(B, sig_b): (PublicKey, Signature),
|
||||
) -> Result<Transaction> {
|
||||
@ -62,8 +63,7 @@ impl TxPunish {
|
||||
};
|
||||
|
||||
let mut tx_punish = self.inner;
|
||||
tx_cancel
|
||||
.output_descriptor
|
||||
self.cancel_output_descriptor
|
||||
.satisfy(&mut tx_punish.input[0], satisfier)?;
|
||||
|
||||
Ok(tx_punish)
|
||||
|
@ -5,13 +5,14 @@ use crate::bitcoin::{
|
||||
use ::bitcoin::{util::bip143::SigHashCache, SigHash, SigHashType, Txid};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use ecdsa_fun::Signature;
|
||||
use miniscript::DescriptorTrait;
|
||||
use miniscript::{Descriptor, DescriptorTrait};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TxRedeem {
|
||||
inner: Transaction,
|
||||
digest: SigHash,
|
||||
lock_output_descriptor: Descriptor<::bitcoin::PublicKey>,
|
||||
}
|
||||
|
||||
impl TxRedeem {
|
||||
@ -30,6 +31,7 @@ impl TxRedeem {
|
||||
Self {
|
||||
inner: tx_redeem,
|
||||
digest,
|
||||
lock_output_descriptor: tx_lock.output_descriptor.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +45,6 @@ impl TxRedeem {
|
||||
|
||||
pub fn add_signatures(
|
||||
self,
|
||||
tx_lock: &TxLock,
|
||||
(A, sig_a): (PublicKey, Signature),
|
||||
(B, sig_b): (PublicKey, Signature),
|
||||
) -> Result<Transaction> {
|
||||
@ -67,8 +68,7 @@ impl TxRedeem {
|
||||
};
|
||||
|
||||
let mut tx_redeem = self.inner;
|
||||
tx_lock
|
||||
.output_descriptor
|
||||
self.lock_output_descriptor
|
||||
.satisfy(&mut tx_redeem.input[0], satisfier)?;
|
||||
|
||||
Ok(tx_redeem)
|
||||
|
@ -5,13 +5,14 @@ use crate::bitcoin::{
|
||||
use ::bitcoin::{util::bip143::SigHashCache, SigHash, SigHashType, Txid};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use ecdsa_fun::Signature;
|
||||
use miniscript::DescriptorTrait;
|
||||
use miniscript::{Descriptor, DescriptorTrait};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TxRefund {
|
||||
inner: Transaction,
|
||||
digest: SigHash,
|
||||
cancel_output_descriptor: Descriptor<::bitcoin::PublicKey>,
|
||||
}
|
||||
|
||||
impl TxRefund {
|
||||
@ -28,6 +29,7 @@ impl TxRefund {
|
||||
Self {
|
||||
inner: tx_punish,
|
||||
digest,
|
||||
cancel_output_descriptor: tx_cancel.output_descriptor.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +43,6 @@ impl TxRefund {
|
||||
|
||||
pub fn add_signatures(
|
||||
self,
|
||||
tx_cancel: &TxCancel,
|
||||
(A, sig_a): (PublicKey, Signature),
|
||||
(B, sig_b): (PublicKey, Signature),
|
||||
) -> Result<Transaction> {
|
||||
@ -65,8 +66,7 @@ impl TxRefund {
|
||||
};
|
||||
|
||||
let mut tx_refund = self.inner;
|
||||
tx_cancel
|
||||
.output_descriptor
|
||||
self.cancel_output_descriptor
|
||||
.satisfy(&mut tx_refund.input[0], satisfier)?;
|
||||
|
||||
Ok(tx_refund)
|
||||
|
@ -205,7 +205,7 @@ impl From<Alice> for AliceState {
|
||||
let tx_refund = TxRefund::new(&tx_cancel, &state3.refund_address);
|
||||
AliceState::BtcPunishable {
|
||||
monero_wallet_restore_blockheight,
|
||||
tx_refund,
|
||||
tx_refund: Box::new(tx_refund),
|
||||
state3: Box::new(state3),
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ pub enum AliceState {
|
||||
},
|
||||
BtcPunishable {
|
||||
monero_wallet_restore_blockheight: BlockHeight,
|
||||
tx_refund: TxRefund,
|
||||
tx_refund: Box<TxRefund>,
|
||||
state3: Box<State3>,
|
||||
},
|
||||
XmrRefunded,
|
||||
|
@ -124,7 +124,7 @@ pub fn build_bitcoin_redeem_transaction(
|
||||
let sig_b = adaptor.decrypt_signature(&s_a, encrypted_signature);
|
||||
|
||||
let tx = tx_redeem
|
||||
.add_signatures(&tx_lock, (a.public(), sig_a), (B, sig_b))
|
||||
.add_signatures((a.public(), sig_a), (B, sig_b))
|
||||
.context("sig_{a,b} are invalid for tx_redeem")?;
|
||||
|
||||
Ok(tx)
|
||||
@ -179,7 +179,7 @@ where
|
||||
|
||||
let tx_cancel = tx_cancel
|
||||
.clone()
|
||||
.add_signatures(&tx_lock, (a.public(), sig_a), (B, sig_b))
|
||||
.add_signatures((a.public(), sig_a), (B, sig_b))
|
||||
.expect("sig_{a,b} to be valid signatures for tx_cancel");
|
||||
|
||||
// TODO(Franck): Error handling is delicate, why can't we broadcast?
|
||||
@ -224,7 +224,7 @@ where
|
||||
|
||||
pub fn extract_monero_private_key(
|
||||
published_refund_tx: bitcoin::Transaction,
|
||||
tx_refund: TxRefund,
|
||||
tx_refund: &TxRefund,
|
||||
s_a: monero::Scalar,
|
||||
a: bitcoin::SecretKey,
|
||||
S_b_bitcoin: bitcoin::PublicKey,
|
||||
@ -261,7 +261,7 @@ pub fn build_bitcoin_punish_transaction(
|
||||
let sig_b = tx_punish_sig_bob;
|
||||
|
||||
let signed_tx_punish = tx_punish
|
||||
.add_signatures(&tx_cancel, (a.public(), sig_a), (B, sig_b))
|
||||
.add_signatures((a.public(), sig_a), (B, sig_b))
|
||||
.expect("sig_{a,b} to be valid signatures for tx_cancel");
|
||||
|
||||
Ok(signed_tx_punish)
|
||||
|
@ -343,7 +343,7 @@ async fn run_until_internal(
|
||||
match published_refund_tx {
|
||||
None => {
|
||||
let state = AliceState::BtcPunishable {
|
||||
tx_refund,
|
||||
tx_refund: Box::new(tx_refund),
|
||||
state3,
|
||||
monero_wallet_restore_blockheight,
|
||||
};
|
||||
@ -366,7 +366,7 @@ async fn run_until_internal(
|
||||
Some(published_refund_tx) => {
|
||||
let spend_key = extract_monero_private_key(
|
||||
published_refund_tx,
|
||||
tx_refund,
|
||||
&tx_refund,
|
||||
state3.s_a,
|
||||
state3.a.clone(),
|
||||
state3.S_b_bitcoin,
|
||||
@ -445,7 +445,7 @@ async fn run_until_internal(
|
||||
Either::Left((published_refund_tx, _)) => {
|
||||
let spend_key = extract_monero_private_key(
|
||||
published_refund_tx?,
|
||||
tx_refund,
|
||||
&tx_refund,
|
||||
state3.s_a,
|
||||
state3.a.clone(),
|
||||
state3.S_b_bitcoin,
|
||||
|
@ -459,7 +459,7 @@ impl State4 {
|
||||
|
||||
let tx_cancel = tx_cancel
|
||||
.clone()
|
||||
.add_signatures(&self.tx_lock, (self.A, sig_a), (self.b.public(), sig_b))
|
||||
.add_signatures((self.A, sig_a), (self.b.public(), sig_b))
|
||||
.expect(
|
||||
"sig_{a,b} to be valid signatures for
|
||||
tx_cancel",
|
||||
@ -482,7 +482,7 @@ impl State4 {
|
||||
|
||||
let tx_cancel = tx_cancel
|
||||
.clone()
|
||||
.add_signatures(&self.tx_lock, (self.A, sig_a), (self.b.public(), sig_b))
|
||||
.add_signatures((self.A, sig_a), (self.b.public(), sig_b))
|
||||
.expect(
|
||||
"sig_{a,b} to be valid signatures for
|
||||
tx_cancel",
|
||||
@ -562,11 +562,8 @@ impl State4 {
|
||||
let sig_a =
|
||||
adaptor.decrypt_signature(&self.s_b.to_secpfun_scalar(), self.tx_refund_encsig.clone());
|
||||
|
||||
let signed_tx_refund = tx_refund.add_signatures(
|
||||
&tx_cancel.clone(),
|
||||
(self.A, sig_a),
|
||||
(self.b.public(), sig_b),
|
||||
)?;
|
||||
let signed_tx_refund =
|
||||
tx_refund.add_signatures((self.A, sig_a), (self.b.public(), sig_b))?;
|
||||
|
||||
let txid = bitcoin_wallet
|
||||
.broadcast_signed_transaction(signed_tx_refund)
|
||||
|
Loading…
Reference in New Issue
Block a user