mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-08 14:32:24 -04:00
Check error to determine if tx_cancel has already been published
If the error code suggests that the tx_cancel is already on the blockchain, continue with the protocol. This change removed the need to check for tx_cancel before attemting to publish it. Removed the tx_cancel field from the Cancelled state as it can be computed from state3. Co-authored-by: rishflab <rishflab@hotmail.com>
This commit is contained in:
parent
672377b216
commit
4903169f4c
9 changed files with 105 additions and 133 deletions
|
@ -243,3 +243,37 @@ 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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue