Add monerod to config

Fixed rebase issues
pull/34/head
rishflab 4 years ago
parent 7afd316210
commit a44303f839

@ -44,8 +44,6 @@ pub async fn swap(
bitcoin_wallet: Arc<bitcoin::Wallet>,
monero_wallet: Arc<monero::Wallet>,
listen: Multiaddr,
redeem_address: ::bitcoin::Address,
punish_address: ::bitcoin::Address,
transport: SwapTransport,
behaviour: Alice,
) -> Result<()> {
@ -71,7 +69,6 @@ pub async fn swap(
// TODO: For retry, use `backoff::ExponentialBackoff` in production as opposed
// to `ConstantBackoff`.
#[async_trait]
impl ReceiveBitcoinRedeemEncsig for Network {
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 backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
use bitcoin::{util::psbt::PartiallySignedTransaction, Address, Transaction};
use bitcoin_harness::{bitcoind_rpc::PsbtBase64, Bitcoind};
use bitcoin_harness::bitcoind_rpc::PsbtBase64;
use reqwest::Url;
use tokio::time;
use xmr_btc::bitcoin::{
@ -20,8 +20,8 @@ pub const TX_LOCK_MINE_TIMEOUT: u64 = 3600;
pub struct Wallet(pub bitcoin_harness::Wallet);
impl Wallet {
pub async fn new(name: &str, url: &Url) -> Result<Self> {
let wallet = bitcoin_harness::Wallet::new(name, url.clone()).await?;
pub async fn new(name: &str, url: Url) -> Result<Self> {
let wallet = bitcoin_harness::Wallet::new(name, url).await?;
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]
impl BuildTxLockPsbt for Wallet {
async fn build_tx_lock_psbt(

@ -39,6 +39,7 @@ use xmr_btc::{
monero::CreateWalletForOutput,
};
#[allow(clippy::too_many_arguments)]
pub async fn swap(
bitcoin_wallet: Arc<bitcoin::Wallet>,
monero_wallet: Arc<monero::Wallet>,

@ -8,6 +8,9 @@ pub enum Options {
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
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")]
listen_addr: Multiaddr,
@ -24,6 +27,9 @@ pub enum Options {
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
bitcoind_url: Url,
#[structopt(default_value = "http://127.0.0.1:18083", long = "monerod")]
monerod_url: Url,
#[structopt(long = "tor")]
tor: bool,
},

@ -21,21 +21,18 @@ use structopt::StructOpt;
use swap::{
alice,
alice::Alice,
bitcoin::Wallet,
bob,
bitcoin, bob,
bob::Bob,
monero,
network::transport::{build, build_tor, SwapTransport},
Cmd, Rsp, SwapAmounts,
};
use tracing::info;
use url::Url;
use xmr_btc::bitcoin::{BroadcastSignedTransaction, BuildTxLockPsbt, SignTxLock};
mod cli;
mod trace;
use cli::Options;
use swap::{alice, bitcoin, bob, monero, Cmd, Rsp, SwapAmounts};
// TODO: Add root seed file instead of generating new seed each run.
@ -47,7 +44,8 @@ async fn main() -> Result<()> {
match opt {
Options::Alice {
bitcoind_url: url,
bitcoind_url,
monerod_url,
listen_addr,
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
.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_alice(listen_addr, redeem, punish, transport, behaviour).await?;
swap_as_alice(
bitcoin_wallet,
monero_wallet,
listen_addr,
transport,
behaviour,
)
.await?;
}
Options::Bob {
alice_addr,
satoshis,
bitcoind_url: url,
bitcoind_url,
monerod_url,
tor,
} => {
info!("running swap node as Bob ...");
@ -100,17 +106,18 @@ async fn main() -> Result<()> {
false => build(local_key_pair)?,
};
let bitcoin_wallet = Wallet::new("bob", &url)
let bitcoin_wallet = bitcoin::Wallet::new("bob", bitcoind_url)
.await
.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(
bitcoin_wallet,
monero_wallet,
satoshis,
alice_addr,
refund,
bitcoin_wallet,
transport,
behaviour,
)
@ -143,12 +150,10 @@ async fn swap_as_alice(
bitcoin_wallet: Arc<swap::bitcoin::Wallet>,
monero_wallet: Arc<swap::monero::Wallet>,
addr: Multiaddr,
redeem: bitcoin::Address,
punish: bitcoin::Address,
transport: SwapTransport,
behaviour: Alice,
) -> Result<()> {
alice::swap(addr, redeem, punish, transport, behaviour).await
alice::swap(bitcoin_wallet, monero_wallet, addr, transport, behaviour).await
}
async fn swap_as_bob(
@ -156,18 +161,20 @@ async fn swap_as_bob(
monero_wallet: Arc<swap::monero::Wallet>,
sats: u64,
alice: Multiaddr,
refund: bitcoin::Address,
wallet: W,
transport: SwapTransport,
behaviour: Bob,
) -> Result<()>
where
W: BuildTxLockPsbt + SignTxLock + BroadcastSignedTransaction + Send + Sync + 'static,
{
) -> Result<()> {
let (cmd_tx, mut cmd_rx) = mpsc::channel(1);
let (mut rsp_tx, rsp_rx) = mpsc::channel(1);
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 {

@ -5,6 +5,7 @@ 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, *,
@ -13,8 +14,8 @@ pub use xmr_btc::monero::{
pub struct Wallet(pub wallet::Client);
impl Wallet {
pub fn localhost(port: u16) -> Self {
Self(wallet::Client::localhost(port))
pub fn new(url: Url) -> Self {
Self(wallet::Client::new(url))
}
/// Get the balance of the primary account.

@ -5,7 +5,7 @@ mod e2e_test {
use libp2p::Multiaddr;
use monero_harness::Monero;
use std::sync::Arc;
use swap::{alice, bob};
use swap::{alice, bob, network::transport::build};
use testcontainers::clients::Cli;
use tracing_subscriber::util::SubscriberInitExt;
@ -37,12 +37,12 @@ mod e2e_test {
let xmr_bob = 0;
let alice_btc_wallet = Arc::new(
swap::bitcoin::Wallet::new("alice", &bitcoind.node_url)
swap::bitcoin::Wallet::new("alice", bitcoind.node_url.clone())
.await
.unwrap(),
);
let bob_btc_wallet = Arc::new(
swap::bitcoin::Wallet::new("bob", &bitcoind.node_url)
swap::bitcoin::Wallet::new("bob", bitcoind.node_url.clone())
.await
.unwrap(),
);
@ -57,15 +57,20 @@ mod e2e_test {
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 alice_behaviour = alice::Alice::default();
let alice_transport = build(alice_behaviour.identity()).unwrap();
let alice_swap = alice::swap(
alice_btc_wallet.clone(),
alice_xmr_wallet.clone(),
alice_multiaddr.clone(),
None,
alice_transport,
alice_behaviour,
);
let (cmd_tx, mut _cmd_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(
bob_btc_wallet.clone(),
bob_xmr_wallet.clone(),
@ -73,6 +78,8 @@ mod e2e_test {
alice_multiaddr,
cmd_tx,
rsp_rx,
bob_transport,
bob_behaviour,
);
// automate the verification step by accepting any amounts sent over by Alice

Loading…
Cancel
Save