mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-04-20 07:56:05 -04:00
Fix tx_cancel building and signing
In an earlier commit we moved the signing and building of tx_cancel into a reusable function. This was a mistake as the signing logic is different for Alice and Bob.
This commit is contained in:
parent
cedc56a160
commit
9014cb9a13
@ -720,15 +720,19 @@ impl State3 {
|
||||
where
|
||||
W: BroadcastSignedTransaction,
|
||||
{
|
||||
crate::bitcoin::publish_cancel_transaction(
|
||||
self.tx_lock.clone(),
|
||||
self.a.clone(),
|
||||
self.B,
|
||||
self.refund_timelock,
|
||||
self.tx_punish_sig_bob.clone(),
|
||||
bitcoin_wallet,
|
||||
)
|
||||
.await
|
||||
let tx_cancel = self.tx_cancel();
|
||||
|
||||
let sig_a = self.a.sign(tx_cancel.digest());
|
||||
let sig_b = self.tx_cancel_sig_bob.clone();
|
||||
|
||||
let signed_tx_cancel = tx_cancel
|
||||
.clone()
|
||||
.add_signatures(&self.tx_lock, (self.a.public(), sig_a), (self.B, sig_b))
|
||||
.expect("sig_{a,b} to be valid signatures for tx_cancel");
|
||||
|
||||
bitcoin_wallet
|
||||
.broadcast_signed_transaction(signed_tx_cancel)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,37 +243,3 @@ where
|
||||
tokio::time::delay_for(std::time::Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn publish_cancel_transaction<W>(
|
||||
tx_lock: TxLock,
|
||||
secret_key: crate::bitcoin::SecretKey,
|
||||
public_key: crate::bitcoin::PublicKey,
|
||||
refund_timelock: u32,
|
||||
tx_cancel_sig: crate::bitcoin::Signature,
|
||||
bitcoin_wallet: &W,
|
||||
) -> Result<Txid>
|
||||
where
|
||||
W: BroadcastSignedTransaction,
|
||||
{
|
||||
let tx_cancel =
|
||||
crate::bitcoin::TxCancel::new(&tx_lock, refund_timelock, public_key, secret_key.public());
|
||||
|
||||
let sig_theirs = tx_cancel_sig.clone();
|
||||
let sig_ours = secret_key.sign(tx_cancel.digest());
|
||||
|
||||
let tx_cancel_txn = tx_cancel
|
||||
.clone()
|
||||
.add_signatures(
|
||||
&tx_lock,
|
||||
(public_key, sig_theirs),
|
||||
(secret_key.public(), sig_ours),
|
||||
)
|
||||
.expect(
|
||||
"sig_{a,b} to be valid signatures for
|
||||
tx_cancel",
|
||||
);
|
||||
|
||||
bitcoin_wallet
|
||||
.broadcast_signed_transaction(tx_cancel_txn)
|
||||
.await
|
||||
}
|
||||
|
@ -660,19 +660,28 @@ impl State4 {
|
||||
self.b.encsign(self.S_a_bitcoin, tx_redeem.digest())
|
||||
}
|
||||
|
||||
pub fn tx_cancel(&self) -> TxCancel {
|
||||
crate::bitcoin::TxCancel::new(&self.tx_lock, self.refund_timelock, self.A, self.b.public())
|
||||
}
|
||||
|
||||
pub async fn submit_tx_cancel<W>(&self, bitcoin_wallet: &W) -> Result<Txid>
|
||||
where
|
||||
W: BroadcastSignedTransaction,
|
||||
{
|
||||
crate::bitcoin::publish_cancel_transaction(
|
||||
self.tx_lock.clone(),
|
||||
self.b.clone(),
|
||||
self.A,
|
||||
self.refund_timelock,
|
||||
self.tx_cancel_sig_a.clone(),
|
||||
bitcoin_wallet,
|
||||
)
|
||||
.await
|
||||
let tx_cancel = self.tx_cancel();
|
||||
|
||||
let sig_b = self.b.sign(tx_cancel.digest());
|
||||
let sig_a = self.tx_cancel_sig_a.clone();
|
||||
|
||||
let signed_tx_cancel = tx_cancel.clone().add_signatures(
|
||||
&self.tx_lock,
|
||||
(self.A, sig_a),
|
||||
(self.b.public(), sig_b),
|
||||
)?;
|
||||
|
||||
bitcoin_wallet
|
||||
.broadcast_signed_transaction(signed_tx_cancel)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn watch_for_redeem_btc<W>(&self, bitcoin_wallet: &W) -> Result<State5>
|
||||
|
Loading…
x
Reference in New Issue
Block a user