mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-20 15:40:48 -04:00
Move completing of Bitcoin redeem tx onto RedeemTx
This allows us to have access to RedeemTx from within the scope of the state transition which we are going to need for more efficient watching of what happens to this TX on the blockchain.
This commit is contained in:
parent
21429f24b2
commit
dd6c66a594
3 changed files with 34 additions and 50 deletions
|
@ -7,12 +7,9 @@ use crate::protocol::alice::event_loop::EventLoopHandle;
|
|||
use crate::protocol::alice::TransferProof;
|
||||
use crate::{bitcoin, monero};
|
||||
use anyhow::{Context, Result};
|
||||
use ecdsa_fun::adaptor::{Adaptor, HashTranscript};
|
||||
use ecdsa_fun::nonce::Deterministic;
|
||||
use futures::future::{select, Either};
|
||||
use futures::pin_mut;
|
||||
use libp2p::PeerId;
|
||||
use sha2::Sha256;
|
||||
|
||||
pub async fn lock_xmr(
|
||||
bob_peer_id: PeerId,
|
||||
|
@ -56,36 +53,6 @@ pub async fn wait_for_bitcoin_encrypted_signature(
|
|||
Ok(msg3.tx_redeem_encsig)
|
||||
}
|
||||
|
||||
pub fn build_bitcoin_redeem_transaction(
|
||||
encrypted_signature: EncryptedSignature,
|
||||
tx_lock: &TxLock,
|
||||
a: bitcoin::SecretKey,
|
||||
s_a: ecdsa_fun::fun::Scalar,
|
||||
B: bitcoin::PublicKey,
|
||||
redeem_address: &bitcoin::Address,
|
||||
) -> Result<bitcoin::Transaction> {
|
||||
let adaptor = Adaptor::<HashTranscript<Sha256>, Deterministic<Sha256>>::default();
|
||||
|
||||
let tx_redeem = bitcoin::TxRedeem::new(tx_lock, redeem_address);
|
||||
|
||||
bitcoin::verify_encsig(
|
||||
B,
|
||||
bitcoin::PublicKey::from(s_a.clone()),
|
||||
&tx_redeem.digest(),
|
||||
&encrypted_signature,
|
||||
)
|
||||
.context("Invalid encrypted signature received")?;
|
||||
|
||||
let sig_a = a.sign(tx_redeem.digest());
|
||||
let sig_b = adaptor.decrypt_signature(&s_a, encrypted_signature);
|
||||
|
||||
let tx = tx_redeem
|
||||
.add_signatures((a.public(), sig_a), (B, sig_b))
|
||||
.context("Failed to sign Bitcoin redeem transaction")?;
|
||||
|
||||
Ok(tx)
|
||||
}
|
||||
|
||||
pub async fn publish_cancel_transaction(
|
||||
tx_lock: TxLock,
|
||||
a: bitcoin::SecretKey,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue