mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-07 05:52:31 -04:00
Correctly re-export types from bitcoin and monero modules
This commit is contained in:
parent
f5ff50157e
commit
483c819e17
10 changed files with 67 additions and 77 deletions
|
@ -75,7 +75,7 @@ pub async fn swap(
|
|||
// to `ConstantBackoff`.
|
||||
#[async_trait]
|
||||
impl ReceiveBitcoinRedeemEncsig for Network {
|
||||
async fn receive_bitcoin_redeem_encsig(&mut self) -> xmr_btc::bitcoin::EncryptedSignature {
|
||||
async fn receive_bitcoin_redeem_encsig(&mut self) -> bitcoin::EncryptedSignature {
|
||||
#[derive(Debug)]
|
||||
struct UnexpectedMessage;
|
||||
|
||||
|
|
|
@ -8,13 +8,13 @@ use bitcoin_harness::bitcoind_rpc::PsbtBase64;
|
|||
use reqwest::Url;
|
||||
use tokio::time;
|
||||
use xmr_btc::bitcoin::{
|
||||
Amount, BlockHeight, BroadcastSignedTransaction, BuildTxLockPsbt, SignTxLock,
|
||||
TransactionBlockHeight, TxLock, Txid, WatchForRawTransaction,
|
||||
BlockHeight, BroadcastSignedTransaction, BuildTxLockPsbt, SignTxLock, TransactionBlockHeight,
|
||||
WatchForRawTransaction,
|
||||
};
|
||||
|
||||
pub const TX_LOCK_MINE_TIMEOUT: u64 = 3600;
|
||||
pub use xmr_btc::bitcoin::*;
|
||||
|
||||
// This is cut'n'paste from xmr_btc/tests/harness/wallet/bitcoin.rs
|
||||
pub const TX_LOCK_MINE_TIMEOUT: u64 = 3600;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Wallet(pub bitcoin_harness::Wallet);
|
||||
|
|
|
@ -34,10 +34,10 @@ pub enum Rsp {
|
|||
pub struct SwapAmounts {
|
||||
/// Amount of BTC to swap.
|
||||
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
|
||||
pub btc: ::bitcoin::Amount,
|
||||
pub btc: bitcoin::Amount,
|
||||
/// Amount of XMR to swap.
|
||||
#[serde(with = "xmr_btc::serde::monero_amount")]
|
||||
pub xmr: xmr_btc::monero::Amount,
|
||||
pub xmr: monero::Amount,
|
||||
}
|
||||
|
||||
// TODO: Display in XMR and BTC (not picos and sats).
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
|
||||
use monero::{Address, Network, PrivateKey};
|
||||
use monero_harness::rpc::wallet;
|
||||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
use url::Url;
|
||||
pub use xmr_btc::monero::{
|
||||
Amount, CreateWalletForOutput, InsufficientFunds, PrivateViewKey, PublicKey, PublicViewKey,
|
||||
Transfer, TransferProof, TxHash, WatchForTransfer, *,
|
||||
};
|
||||
|
||||
pub use xmr_btc::monero::*;
|
||||
|
||||
pub struct Wallet(pub wallet::Client);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
//! was deemed too complicated for the time being.
|
||||
|
||||
use crate::{
|
||||
bitcoin, monero,
|
||||
monero::CreateWalletForOutput,
|
||||
state::{Alice, Bob, Swap},
|
||||
};
|
||||
|
@ -23,13 +24,13 @@ use futures::{
|
|||
use sha2::Sha256;
|
||||
use tracing::info;
|
||||
use xmr_btc::bitcoin::{
|
||||
poll_until_block_height_is_gte, BroadcastSignedTransaction, TransactionBlockHeight, TxCancel,
|
||||
TxPunish, TxRedeem, TxRefund, WatchForRawTransaction,
|
||||
poll_until_block_height_is_gte, BroadcastSignedTransaction, TransactionBlockHeight,
|
||||
WatchForRawTransaction,
|
||||
};
|
||||
|
||||
pub async fn recover(
|
||||
bitcoin_wallet: crate::bitcoin::Wallet,
|
||||
monero_wallet: crate::monero::Wallet,
|
||||
bitcoin_wallet: bitcoin::Wallet,
|
||||
monero_wallet: monero::Wallet,
|
||||
state: Swap,
|
||||
) -> Result<()> {
|
||||
match state {
|
||||
|
@ -39,8 +40,8 @@ pub async fn recover(
|
|||
}
|
||||
|
||||
pub async fn alice_recover(
|
||||
bitcoin_wallet: crate::bitcoin::Wallet,
|
||||
monero_wallet: crate::monero::Wallet,
|
||||
bitcoin_wallet: bitcoin::Wallet,
|
||||
monero_wallet: monero::Wallet,
|
||||
state: Alice,
|
||||
) -> Result<()> {
|
||||
match state {
|
||||
|
@ -50,7 +51,7 @@ pub async fn alice_recover(
|
|||
Alice::XmrLocked(state) => {
|
||||
info!("Monero still locked up");
|
||||
|
||||
let tx_cancel = TxCancel::new(
|
||||
let tx_cancel = bitcoin::TxCancel::new(
|
||||
&state.tx_lock,
|
||||
state.refund_timelock,
|
||||
state.a.public(),
|
||||
|
@ -104,7 +105,7 @@ pub async fn alice_recover(
|
|||
);
|
||||
pin_mut!(poll_until_bob_can_be_punished);
|
||||
|
||||
let tx_refund = TxRefund::new(&tx_cancel, &state.refund_address);
|
||||
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &state.refund_address);
|
||||
|
||||
info!("Waiting for either Bitcoin refund or punish timelock");
|
||||
match select(
|
||||
|
@ -126,13 +127,9 @@ pub async fn alice_recover(
|
|||
.a
|
||||
.encsign(state.S_b_bitcoin.clone(), tx_refund.digest());
|
||||
|
||||
let s_b = xmr_btc::bitcoin::recover(
|
||||
state.S_b_bitcoin,
|
||||
tx_refund_sig,
|
||||
tx_refund_encsig,
|
||||
)?;
|
||||
let s_b = bitcoin::recover(state.S_b_bitcoin, tx_refund_sig, tx_refund_encsig)?;
|
||||
let s_b = monero::PrivateKey::from_scalar(
|
||||
xmr_btc::monero::Scalar::from_bytes_mod_order(s_b.to_bytes()),
|
||||
monero::Scalar::from_bytes_mod_order(s_b.to_bytes()),
|
||||
);
|
||||
|
||||
monero_wallet
|
||||
|
@ -143,8 +140,11 @@ pub async fn alice_recover(
|
|||
Either::Right(_) => {
|
||||
info!("Punish timelock reached, attempting to punish Bob");
|
||||
|
||||
let tx_punish =
|
||||
TxPunish::new(&tx_cancel, &state.punish_address, state.punish_timelock);
|
||||
let tx_punish = bitcoin::TxPunish::new(
|
||||
&tx_cancel,
|
||||
&state.punish_address,
|
||||
state.punish_timelock,
|
||||
);
|
||||
|
||||
let sig_a = state.a.sign(tx_punish.digest());
|
||||
let sig_b = state.tx_punish_sig_bob.clone();
|
||||
|
@ -183,7 +183,7 @@ pub async fn alice_recover(
|
|||
} else {
|
||||
info!("Refund timelock reached");
|
||||
|
||||
let tx_cancel = TxCancel::new(
|
||||
let tx_cancel = bitcoin::TxCancel::new(
|
||||
&state.tx_lock,
|
||||
state.refund_timelock,
|
||||
state.a.public(),
|
||||
|
@ -226,7 +226,7 @@ pub async fn alice_recover(
|
|||
);
|
||||
pin_mut!(poll_until_bob_can_be_punished);
|
||||
|
||||
let tx_refund = TxRefund::new(&tx_cancel, &state.refund_address);
|
||||
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &state.refund_address);
|
||||
|
||||
info!("Waiting for either Bitcoin refund or punish timelock");
|
||||
match select(
|
||||
|
@ -248,13 +248,10 @@ pub async fn alice_recover(
|
|||
.a
|
||||
.encsign(state.S_b_bitcoin.clone(), tx_refund.digest());
|
||||
|
||||
let s_b = xmr_btc::bitcoin::recover(
|
||||
state.S_b_bitcoin,
|
||||
tx_refund_sig,
|
||||
tx_refund_encsig,
|
||||
)?;
|
||||
let s_b =
|
||||
bitcoin::recover(state.S_b_bitcoin, tx_refund_sig, tx_refund_encsig)?;
|
||||
let s_b = monero::PrivateKey::from_scalar(
|
||||
xmr_btc::monero::Scalar::from_bytes_mod_order(s_b.to_bytes()),
|
||||
monero::Scalar::from_bytes_mod_order(s_b.to_bytes()),
|
||||
);
|
||||
|
||||
monero_wallet
|
||||
|
@ -265,8 +262,11 @@ pub async fn alice_recover(
|
|||
Either::Right(_) => {
|
||||
info!("Punish timelock reached, attempting to punish Bob");
|
||||
|
||||
let tx_punish =
|
||||
TxPunish::new(&tx_cancel, &state.punish_address, state.punish_timelock);
|
||||
let tx_punish = bitcoin::TxPunish::new(
|
||||
&tx_cancel,
|
||||
&state.punish_address,
|
||||
state.punish_timelock,
|
||||
);
|
||||
|
||||
let sig_a = state.a.sign(tx_punish.digest());
|
||||
let sig_b = state.tx_punish_sig_bob.clone();
|
||||
|
@ -288,13 +288,13 @@ pub async fn alice_recover(
|
|||
Alice::BtcPunishable(state) => {
|
||||
info!("Punish timelock reached, attempting to punish Bob");
|
||||
|
||||
let tx_cancel = TxCancel::new(
|
||||
let tx_cancel = bitcoin::TxCancel::new(
|
||||
&state.tx_lock,
|
||||
state.refund_timelock,
|
||||
state.a.public(),
|
||||
state.B.clone(),
|
||||
);
|
||||
let tx_refund = TxRefund::new(&tx_cancel, &state.refund_address);
|
||||
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &state.refund_address);
|
||||
|
||||
info!("Checking if Bitcoin has already been refunded");
|
||||
|
||||
|
@ -314,13 +314,9 @@ pub async fn alice_recover(
|
|||
.a
|
||||
.encsign(state.S_b_bitcoin.clone(), tx_refund.digest());
|
||||
|
||||
let s_b = xmr_btc::bitcoin::recover(
|
||||
state.S_b_bitcoin,
|
||||
tx_refund_sig,
|
||||
tx_refund_encsig,
|
||||
)?;
|
||||
let s_b = bitcoin::recover(state.S_b_bitcoin, tx_refund_sig, tx_refund_encsig)?;
|
||||
let s_b = monero::PrivateKey::from_scalar(
|
||||
xmr_btc::monero::Scalar::from_bytes_mod_order(s_b.to_bytes()),
|
||||
monero::Scalar::from_bytes_mod_order(s_b.to_bytes()),
|
||||
);
|
||||
|
||||
monero_wallet
|
||||
|
@ -331,8 +327,11 @@ pub async fn alice_recover(
|
|||
Err(_) => {
|
||||
info!("Bitcoin not yet refunded");
|
||||
|
||||
let tx_punish =
|
||||
TxPunish::new(&tx_cancel, &state.punish_address, state.punish_timelock);
|
||||
let tx_punish = bitcoin::TxPunish::new(
|
||||
&tx_cancel,
|
||||
&state.punish_address,
|
||||
state.punish_timelock,
|
||||
);
|
||||
|
||||
let sig_a = state.a.sign(tx_punish.digest());
|
||||
let sig_b = state.tx_punish_sig_bob.clone();
|
||||
|
@ -379,7 +378,7 @@ pub async fn bob_recover(
|
|||
Bob::BtcLocked(state) | Bob::XmrLocked(state) | Bob::BtcRefundable(state) => {
|
||||
info!("Bitcoin may still be locked up, attempting to refund");
|
||||
|
||||
let tx_cancel = TxCancel::new(
|
||||
let tx_cancel = bitcoin::TxCancel::new(
|
||||
&state.tx_lock,
|
||||
state.refund_timelock,
|
||||
state.A.clone(),
|
||||
|
@ -420,10 +419,11 @@ pub async fn bob_recover(
|
|||
bitcoin_wallet
|
||||
.broadcast_signed_transaction(tx_cancel)
|
||||
.await?;
|
||||
info!("Successfully published Bitcoin cancel transaction");
|
||||
}
|
||||
|
||||
let tx_refund = TxRefund::new(&tx_cancel, &state.refund_address);
|
||||
info!("Confirmed that Bitcoin cancel transaction is on the blockchain");
|
||||
|
||||
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &state.refund_address);
|
||||
let signed_tx_refund = {
|
||||
let adaptor = Adaptor::<Sha256, Deterministic<Sha256>>::default();
|
||||
let sig_a = adaptor
|
||||
|
@ -449,7 +449,7 @@ pub async fn bob_recover(
|
|||
Bob::BtcRedeemed(state) => {
|
||||
info!("Bitcoin was redeemed, attempting to redeem monero");
|
||||
|
||||
let tx_redeem = TxRedeem::new(&state.tx_lock, &state.redeem_address);
|
||||
let tx_redeem = bitcoin::TxRedeem::new(&state.tx_lock, &state.redeem_address);
|
||||
let tx_redeem_published = bitcoin_wallet
|
||||
.0
|
||||
.get_raw_transaction(tx_redeem.txid())
|
||||
|
@ -461,11 +461,10 @@ pub async fn bob_recover(
|
|||
let tx_redeem_sig =
|
||||
tx_redeem.extract_signature_by_key(tx_redeem_published, state.b.public())?;
|
||||
|
||||
let s_a =
|
||||
xmr_btc::bitcoin::recover(state.S_a_bitcoin, tx_redeem_sig, tx_redeem_encsig)?;
|
||||
let s_a = monero::PrivateKey::from_scalar(
|
||||
xmr_btc::monero::Scalar::from_bytes_mod_order(s_a.to_bytes()),
|
||||
);
|
||||
let s_a = bitcoin::recover(state.S_a_bitcoin, tx_redeem_sig, tx_redeem_encsig)?;
|
||||
let s_a = monero::PrivateKey::from_scalar(monero::Scalar::from_bytes_mod_order(
|
||||
s_a.to_bytes(),
|
||||
));
|
||||
|
||||
let s_b = monero::PrivateKey {
|
||||
scalar: state.s_b.into_ed25519(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue