mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Add monerod to config
Fixed rebase issues
This commit is contained in:
parent
7afd316210
commit
a44303f839
@ -44,8 +44,6 @@ pub async fn swap(
|
|||||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
listen: Multiaddr,
|
listen: Multiaddr,
|
||||||
redeem_address: ::bitcoin::Address,
|
|
||||||
punish_address: ::bitcoin::Address,
|
|
||||||
transport: SwapTransport,
|
transport: SwapTransport,
|
||||||
behaviour: Alice,
|
behaviour: Alice,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@ -71,7 +69,6 @@ pub async fn swap(
|
|||||||
|
|
||||||
// TODO: For retry, use `backoff::ExponentialBackoff` in production as opposed
|
// TODO: For retry, use `backoff::ExponentialBackoff` in production as opposed
|
||||||
// to `ConstantBackoff`.
|
// to `ConstantBackoff`.
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ReceiveBitcoinRedeemEncsig for Network {
|
impl ReceiveBitcoinRedeemEncsig for Network {
|
||||||
async fn receive_bitcoin_redeem_encsig(&mut self) -> xmr_btc::bitcoin::EncryptedSignature {
|
async fn receive_bitcoin_redeem_encsig(&mut self) -> xmr_btc::bitcoin::EncryptedSignature {
|
||||||
|
@ -4,7 +4,7 @@ use anyhow::Result;
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
|
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
|
||||||
use bitcoin::{util::psbt::PartiallySignedTransaction, Address, Transaction};
|
use bitcoin::{util::psbt::PartiallySignedTransaction, Address, Transaction};
|
||||||
use bitcoin_harness::{bitcoind_rpc::PsbtBase64, Bitcoind};
|
use bitcoin_harness::bitcoind_rpc::PsbtBase64;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
use xmr_btc::bitcoin::{
|
use xmr_btc::bitcoin::{
|
||||||
@ -20,8 +20,8 @@ pub const TX_LOCK_MINE_TIMEOUT: u64 = 3600;
|
|||||||
pub struct Wallet(pub bitcoin_harness::Wallet);
|
pub struct Wallet(pub bitcoin_harness::Wallet);
|
||||||
|
|
||||||
impl Wallet {
|
impl Wallet {
|
||||||
pub async fn new(name: &str, url: &Url) -> Result<Self> {
|
pub async fn new(name: &str, url: Url) -> Result<Self> {
|
||||||
let wallet = bitcoin_harness::Wallet::new(name, url.clone()).await?;
|
let wallet = bitcoin_harness::Wallet::new(name, url).await?;
|
||||||
|
|
||||||
Ok(Self(wallet))
|
Ok(Self(wallet))
|
||||||
}
|
}
|
||||||
@ -46,22 +46,6 @@ impl Wallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn make_wallet(
|
|
||||||
name: &str,
|
|
||||||
bitcoind: &Bitcoind<'_>,
|
|
||||||
fund_amount: Amount,
|
|
||||||
) -> Result<Wallet> {
|
|
||||||
let wallet = Wallet::new(name, &bitcoind.node_url).await?;
|
|
||||||
let buffer = Amount::from_btc(1.0).unwrap();
|
|
||||||
let amount = fund_amount + buffer;
|
|
||||||
|
|
||||||
let address = wallet.0.new_address().await.unwrap();
|
|
||||||
|
|
||||||
bitcoind.mint(address, amount).await.unwrap();
|
|
||||||
|
|
||||||
Ok(wallet)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl BuildTxLockPsbt for Wallet {
|
impl BuildTxLockPsbt for Wallet {
|
||||||
async fn build_tx_lock_psbt(
|
async fn build_tx_lock_psbt(
|
||||||
|
@ -39,6 +39,7 @@ use xmr_btc::{
|
|||||||
monero::CreateWalletForOutput,
|
monero::CreateWalletForOutput,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn swap(
|
pub async fn swap(
|
||||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
|
@ -8,6 +8,9 @@ pub enum Options {
|
|||||||
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
|
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
|
||||||
bitcoind_url: Url,
|
bitcoind_url: Url,
|
||||||
|
|
||||||
|
#[structopt(default_value = "http://127.0.0.1:18083", long = "monerod")]
|
||||||
|
monerod_url: Url,
|
||||||
|
|
||||||
#[structopt(default_value = "/ip4/127.0.0.1/tcp/9876", long = "listen-addr")]
|
#[structopt(default_value = "/ip4/127.0.0.1/tcp/9876", long = "listen-addr")]
|
||||||
listen_addr: Multiaddr,
|
listen_addr: Multiaddr,
|
||||||
|
|
||||||
@ -24,6 +27,9 @@ pub enum Options {
|
|||||||
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
|
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
|
||||||
bitcoind_url: Url,
|
bitcoind_url: Url,
|
||||||
|
|
||||||
|
#[structopt(default_value = "http://127.0.0.1:18083", long = "monerod")]
|
||||||
|
monerod_url: Url,
|
||||||
|
|
||||||
#[structopt(long = "tor")]
|
#[structopt(long = "tor")]
|
||||||
tor: bool,
|
tor: bool,
|
||||||
},
|
},
|
||||||
|
@ -21,21 +21,18 @@ use structopt::StructOpt;
|
|||||||
use swap::{
|
use swap::{
|
||||||
alice,
|
alice,
|
||||||
alice::Alice,
|
alice::Alice,
|
||||||
bitcoin::Wallet,
|
bitcoin, bob,
|
||||||
bob,
|
|
||||||
bob::Bob,
|
bob::Bob,
|
||||||
|
monero,
|
||||||
network::transport::{build, build_tor, SwapTransport},
|
network::transport::{build, build_tor, SwapTransport},
|
||||||
Cmd, Rsp, SwapAmounts,
|
Cmd, Rsp, SwapAmounts,
|
||||||
};
|
};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use url::Url;
|
|
||||||
use xmr_btc::bitcoin::{BroadcastSignedTransaction, BuildTxLockPsbt, SignTxLock};
|
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod trace;
|
mod trace;
|
||||||
|
|
||||||
use cli::Options;
|
use cli::Options;
|
||||||
use swap::{alice, bitcoin, bob, monero, Cmd, Rsp, SwapAmounts};
|
|
||||||
|
|
||||||
// TODO: Add root seed file instead of generating new seed each run.
|
// TODO: Add root seed file instead of generating new seed each run.
|
||||||
|
|
||||||
@ -47,7 +44,8 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
match opt {
|
match opt {
|
||||||
Options::Alice {
|
Options::Alice {
|
||||||
bitcoind_url: url,
|
bitcoind_url,
|
||||||
|
monerod_url,
|
||||||
listen_addr,
|
listen_addr,
|
||||||
tor_port,
|
tor_port,
|
||||||
} => {
|
} => {
|
||||||
@ -75,19 +73,27 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let bitcoin_wallet = bitcoin::Wallet::new("alice", &url)
|
let bitcoin_wallet = bitcoin::Wallet::new("alice", bitcoind_url)
|
||||||
.await
|
.await
|
||||||
.expect("failed to create bitcoin wallet");
|
.expect("failed to create bitcoin wallet");
|
||||||
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
|
|
||||||
let monero_wallet = Arc::new(monero::Wallet::localhost(MONERO_WALLET_RPC_PORT));
|
let monero_wallet = Arc::new(monero::Wallet::new(monerod_url));
|
||||||
|
|
||||||
swap_as_alice(listen_addr, redeem, punish, transport, behaviour).await?;
|
swap_as_alice(
|
||||||
|
bitcoin_wallet,
|
||||||
|
monero_wallet,
|
||||||
|
listen_addr,
|
||||||
|
transport,
|
||||||
|
behaviour,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
Options::Bob {
|
Options::Bob {
|
||||||
alice_addr,
|
alice_addr,
|
||||||
satoshis,
|
satoshis,
|
||||||
bitcoind_url: url,
|
bitcoind_url,
|
||||||
|
monerod_url,
|
||||||
tor,
|
tor,
|
||||||
} => {
|
} => {
|
||||||
info!("running swap node as Bob ...");
|
info!("running swap node as Bob ...");
|
||||||
@ -100,17 +106,18 @@ async fn main() -> Result<()> {
|
|||||||
false => build(local_key_pair)?,
|
false => build(local_key_pair)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
let bitcoin_wallet = Wallet::new("bob", &url)
|
let bitcoin_wallet = bitcoin::Wallet::new("bob", bitcoind_url)
|
||||||
.await
|
.await
|
||||||
.expect("failed to create bitcoin wallet");
|
.expect("failed to create bitcoin wallet");
|
||||||
|
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
|
|
||||||
let monero_wallet = Arc::new(monero::Wallet::localhost(MONERO_WALLET_RPC_PORT));
|
let monero_wallet = Arc::new(monero::Wallet::new(monerod_url));
|
||||||
|
|
||||||
swap_as_bob(
|
swap_as_bob(
|
||||||
|
bitcoin_wallet,
|
||||||
|
monero_wallet,
|
||||||
satoshis,
|
satoshis,
|
||||||
alice_addr,
|
alice_addr,
|
||||||
refund,
|
|
||||||
bitcoin_wallet,
|
|
||||||
transport,
|
transport,
|
||||||
behaviour,
|
behaviour,
|
||||||
)
|
)
|
||||||
@ -143,12 +150,10 @@ async fn swap_as_alice(
|
|||||||
bitcoin_wallet: Arc<swap::bitcoin::Wallet>,
|
bitcoin_wallet: Arc<swap::bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<swap::monero::Wallet>,
|
monero_wallet: Arc<swap::monero::Wallet>,
|
||||||
addr: Multiaddr,
|
addr: Multiaddr,
|
||||||
redeem: bitcoin::Address,
|
|
||||||
punish: bitcoin::Address,
|
|
||||||
transport: SwapTransport,
|
transport: SwapTransport,
|
||||||
behaviour: Alice,
|
behaviour: Alice,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
alice::swap(addr, redeem, punish, transport, behaviour).await
|
alice::swap(bitcoin_wallet, monero_wallet, addr, transport, behaviour).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn swap_as_bob(
|
async fn swap_as_bob(
|
||||||
@ -156,18 +161,20 @@ async fn swap_as_bob(
|
|||||||
monero_wallet: Arc<swap::monero::Wallet>,
|
monero_wallet: Arc<swap::monero::Wallet>,
|
||||||
sats: u64,
|
sats: u64,
|
||||||
alice: Multiaddr,
|
alice: Multiaddr,
|
||||||
refund: bitcoin::Address,
|
|
||||||
wallet: W,
|
|
||||||
transport: SwapTransport,
|
transport: SwapTransport,
|
||||||
behaviour: Bob,
|
behaviour: Bob,
|
||||||
) -> Result<()>
|
) -> Result<()> {
|
||||||
where
|
|
||||||
W: BuildTxLockPsbt + SignTxLock + BroadcastSignedTransaction + Send + Sync + 'static,
|
|
||||||
{
|
|
||||||
let (cmd_tx, mut cmd_rx) = mpsc::channel(1);
|
let (cmd_tx, mut cmd_rx) = mpsc::channel(1);
|
||||||
let (mut rsp_tx, rsp_rx) = mpsc::channel(1);
|
let (mut rsp_tx, rsp_rx) = mpsc::channel(1);
|
||||||
tokio::spawn(bob::swap(
|
tokio::spawn(bob::swap(
|
||||||
sats, alice, cmd_tx, rsp_rx, refund, wallet, transport, behaviour,
|
bitcoin_wallet,
|
||||||
|
monero_wallet,
|
||||||
|
sats,
|
||||||
|
alice,
|
||||||
|
cmd_tx,
|
||||||
|
rsp_rx,
|
||||||
|
transport,
|
||||||
|
behaviour,
|
||||||
));
|
));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -5,6 +5,7 @@ use monero::{Address, Network, PrivateKey};
|
|||||||
use monero_harness::rpc::wallet;
|
use monero_harness::rpc::wallet;
|
||||||
use std::{str::FromStr, time::Duration};
|
use std::{str::FromStr, time::Duration};
|
||||||
|
|
||||||
|
use url::Url;
|
||||||
pub use xmr_btc::monero::{
|
pub use xmr_btc::monero::{
|
||||||
Amount, CreateWalletForOutput, InsufficientFunds, PrivateViewKey, PublicKey, PublicViewKey,
|
Amount, CreateWalletForOutput, InsufficientFunds, PrivateViewKey, PublicKey, PublicViewKey,
|
||||||
Transfer, TransferProof, TxHash, WatchForTransfer, *,
|
Transfer, TransferProof, TxHash, WatchForTransfer, *,
|
||||||
@ -13,8 +14,8 @@ pub use xmr_btc::monero::{
|
|||||||
pub struct Wallet(pub wallet::Client);
|
pub struct Wallet(pub wallet::Client);
|
||||||
|
|
||||||
impl Wallet {
|
impl Wallet {
|
||||||
pub fn localhost(port: u16) -> Self {
|
pub fn new(url: Url) -> Self {
|
||||||
Self(wallet::Client::localhost(port))
|
Self(wallet::Client::new(url))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the balance of the primary account.
|
/// Get the balance of the primary account.
|
||||||
|
@ -5,7 +5,7 @@ mod e2e_test {
|
|||||||
use libp2p::Multiaddr;
|
use libp2p::Multiaddr;
|
||||||
use monero_harness::Monero;
|
use monero_harness::Monero;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use swap::{alice, bob};
|
use swap::{alice, bob, network::transport::build};
|
||||||
use testcontainers::clients::Cli;
|
use testcontainers::clients::Cli;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
|
||||||
@ -37,12 +37,12 @@ mod e2e_test {
|
|||||||
let xmr_bob = 0;
|
let xmr_bob = 0;
|
||||||
|
|
||||||
let alice_btc_wallet = Arc::new(
|
let alice_btc_wallet = Arc::new(
|
||||||
swap::bitcoin::Wallet::new("alice", &bitcoind.node_url)
|
swap::bitcoin::Wallet::new("alice", bitcoind.node_url.clone())
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
let bob_btc_wallet = Arc::new(
|
let bob_btc_wallet = Arc::new(
|
||||||
swap::bitcoin::Wallet::new("bob", &bitcoind.node_url)
|
swap::bitcoin::Wallet::new("bob", bitcoind.node_url.clone())
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
@ -57,15 +57,20 @@ mod e2e_test {
|
|||||||
let alice_xmr_wallet = Arc::new(swap::monero::Wallet(monero.alice_wallet_rpc_client()));
|
let alice_xmr_wallet = Arc::new(swap::monero::Wallet(monero.alice_wallet_rpc_client()));
|
||||||
let bob_xmr_wallet = Arc::new(swap::monero::Wallet(monero.bob_wallet_rpc_client()));
|
let bob_xmr_wallet = Arc::new(swap::monero::Wallet(monero.bob_wallet_rpc_client()));
|
||||||
|
|
||||||
|
let alice_behaviour = alice::Alice::default();
|
||||||
|
let alice_transport = build(alice_behaviour.identity()).unwrap();
|
||||||
let alice_swap = alice::swap(
|
let alice_swap = alice::swap(
|
||||||
alice_btc_wallet.clone(),
|
alice_btc_wallet.clone(),
|
||||||
alice_xmr_wallet.clone(),
|
alice_xmr_wallet.clone(),
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
None,
|
alice_transport,
|
||||||
|
alice_behaviour,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (cmd_tx, mut _cmd_rx) = mpsc::channel(1);
|
let (cmd_tx, mut _cmd_rx) = mpsc::channel(1);
|
||||||
let (mut rsp_tx, rsp_rx) = mpsc::channel(1);
|
let (mut rsp_tx, rsp_rx) = mpsc::channel(1);
|
||||||
|
let bob_behaviour = bob::Bob::default();
|
||||||
|
let bob_transport = build(bob_behaviour.identity()).unwrap();
|
||||||
let bob_swap = bob::swap(
|
let bob_swap = bob::swap(
|
||||||
bob_btc_wallet.clone(),
|
bob_btc_wallet.clone(),
|
||||||
bob_xmr_wallet.clone(),
|
bob_xmr_wallet.clone(),
|
||||||
@ -73,6 +78,8 @@ mod e2e_test {
|
|||||||
alice_multiaddr,
|
alice_multiaddr,
|
||||||
cmd_tx,
|
cmd_tx,
|
||||||
rsp_rx,
|
rsp_rx,
|
||||||
|
bob_transport,
|
||||||
|
bob_behaviour,
|
||||||
);
|
);
|
||||||
|
|
||||||
// automate the verification step by accepting any amounts sent over by Alice
|
// automate the verification step by accepting any amounts sent over by Alice
|
||||||
|
Loading…
Reference in New Issue
Block a user