mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Work in review comments
This commit is contained in:
parent
6d03d1bbff
commit
e9681b6e2b
@ -12,7 +12,7 @@
|
|||||||
)]
|
)]
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{Context, Result};
|
||||||
use libp2p::core::Multiaddr;
|
use libp2p::core::Multiaddr;
|
||||||
use prettytable::{row, Table};
|
use prettytable::{row, Table};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
@ -46,7 +46,8 @@ async fn main() -> Result<()> {
|
|||||||
let config = Config::mainnet();
|
let config = Config::mainnet();
|
||||||
|
|
||||||
info!("Database: {}", opt.db_path);
|
info!("Database: {}", opt.db_path);
|
||||||
let db = Database::open(std::path::Path::new(opt.db_path.as_str())).unwrap();
|
let db = Database::open(std::path::Path::new(opt.db_path.as_str()))
|
||||||
|
.context("Could not open database")?;
|
||||||
|
|
||||||
match opt.cmd {
|
match opt.cmd {
|
||||||
Command::SellXmr {
|
Command::SellXmr {
|
||||||
@ -57,8 +58,6 @@ async fn main() -> Result<()> {
|
|||||||
send_monero,
|
send_monero,
|
||||||
receive_bitcoin,
|
receive_bitcoin,
|
||||||
} => {
|
} => {
|
||||||
info!("Running swap node as Alice ...");
|
|
||||||
|
|
||||||
let (bitcoin_wallet, monero_wallet) = setup_wallets(
|
let (bitcoin_wallet, monero_wallet) = setup_wallets(
|
||||||
bitcoind_url,
|
bitcoind_url,
|
||||||
bitcoin_wallet_name.as_str(),
|
bitcoin_wallet_name.as_str(),
|
||||||
@ -77,7 +76,7 @@ async fn main() -> Result<()> {
|
|||||||
let a = bitcoin::SecretKey::new_random(rng);
|
let a = bitcoin::SecretKey::new_random(rng);
|
||||||
let s_a = cross_curve_dleq::Scalar::random(rng);
|
let s_a = cross_curve_dleq::Scalar::random(rng);
|
||||||
let v_a = xmr_btc::monero::PrivateViewKey::new_random(rng);
|
let v_a = xmr_btc::monero::PrivateViewKey::new_random(rng);
|
||||||
let redeem_address = bitcoin_wallet.as_ref().new_address().await.unwrap();
|
let redeem_address = bitcoin_wallet.as_ref().new_address().await?;
|
||||||
let punish_address = redeem_address.clone();
|
let punish_address = redeem_address.clone();
|
||||||
let state0 = State0::new(
|
let state0 = State0::new(
|
||||||
a,
|
a,
|
||||||
@ -119,8 +118,6 @@ async fn main() -> Result<()> {
|
|||||||
send_bitcoin,
|
send_bitcoin,
|
||||||
receive_monero,
|
receive_monero,
|
||||||
} => {
|
} => {
|
||||||
info!("Running swap node as Bob ...");
|
|
||||||
|
|
||||||
let (bitcoin_wallet, monero_wallet) = setup_wallets(
|
let (bitcoin_wallet, monero_wallet) = setup_wallets(
|
||||||
bitcoind_url,
|
bitcoind_url,
|
||||||
bitcoin_wallet_name.as_str(),
|
bitcoin_wallet_name.as_str(),
|
||||||
@ -129,7 +126,7 @@ async fn main() -> Result<()> {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let refund_address = bitcoin_wallet.new_address().await.unwrap();
|
let refund_address = bitcoin_wallet.new_address().await?;
|
||||||
let state0 = xmr_btc::bob::State0::new(
|
let state0 = xmr_btc::bob::State0::new(
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
send_bitcoin,
|
send_bitcoin,
|
||||||
@ -222,9 +219,7 @@ async fn setup_wallets(
|
|||||||
config: Config,
|
config: Config,
|
||||||
) -> Result<(Arc<bitcoin::Wallet>, Arc<monero::Wallet>)> {
|
) -> Result<(Arc<bitcoin::Wallet>, Arc<monero::Wallet>)> {
|
||||||
let bitcoin_wallet =
|
let bitcoin_wallet =
|
||||||
bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network)
|
bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network).await?;
|
||||||
.await
|
|
||||||
.expect("failed to create bitcoin wallet");
|
|
||||||
let bitcoin_balance = bitcoin_wallet.balance().await?;
|
let bitcoin_balance = bitcoin_wallet.balance().await?;
|
||||||
info!(
|
info!(
|
||||||
"Connection to Bitcoin wallet succeeded, balance: {}",
|
"Connection to Bitcoin wallet succeeded, balance: {}",
|
||||||
@ -272,8 +267,8 @@ async fn alice_swap(
|
|||||||
db,
|
db,
|
||||||
);
|
);
|
||||||
|
|
||||||
let _event_loop = tokio::spawn(async move { event_loop.run().await });
|
tokio::spawn(async move { event_loop.run().await });
|
||||||
Ok(swap.await?)
|
swap.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn bob_swap(
|
async fn bob_swap(
|
||||||
@ -286,8 +281,7 @@ async fn bob_swap(
|
|||||||
let bob_behaviour = bob::Behaviour::default();
|
let bob_behaviour = bob::Behaviour::default();
|
||||||
let bob_transport = build(bob_behaviour.identity())?;
|
let bob_transport = build(bob_behaviour.identity())?;
|
||||||
|
|
||||||
let (event_loop, handle) =
|
let (event_loop, handle) = bob::event_loop::EventLoop::new(bob_transport, bob_behaviour)?;
|
||||||
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour).unwrap();
|
|
||||||
|
|
||||||
let swap = bob::swap::swap(
|
let swap = bob::swap::swap(
|
||||||
state,
|
state,
|
||||||
@ -299,6 +293,6 @@ async fn bob_swap(
|
|||||||
swap_id,
|
swap_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let _event_loop = tokio::spawn(async move { event_loop.run().await });
|
tokio::spawn(async move { event_loop.run().await });
|
||||||
Ok(swap.await?)
|
swap.await
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
|
// TODO: Default value should points to proper configuration folder in home folder
|
||||||
#[structopt(short = "db", long = "database", default_value = "./.swap-db/")]
|
#[structopt(short = "db", long = "database", default_value = "./.swap-db/")]
|
||||||
pub db_path: String,
|
pub db_path: String,
|
||||||
|
|
||||||
@ -12,12 +13,12 @@ pub struct Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
#[structopt(name = "xmr-btc-swap", about = "Trustless XMR BTC swaps")]
|
#[structopt(name = "xmr-btc-swap", about = "XMR BTC atomic swap")]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
SellXmr {
|
SellXmr {
|
||||||
#[structopt(
|
#[structopt(
|
||||||
short = "b",
|
short = "b",
|
||||||
long = "bitcoind",
|
long = "bitcoind-rpc",
|
||||||
default_value = "http://127.0.0.1:8332"
|
default_value = "http://127.0.0.1:8332"
|
||||||
)]
|
)]
|
||||||
bitcoind_url: Url,
|
bitcoind_url: Url,
|
||||||
@ -34,7 +35,7 @@ pub enum Command {
|
|||||||
|
|
||||||
#[structopt(
|
#[structopt(
|
||||||
short = "a",
|
short = "a",
|
||||||
long = "listen-addr",
|
long = "p2p-address",
|
||||||
default_value = "/ip4/127.0.0.1/tcp/9876"
|
default_value = "/ip4/127.0.0.1/tcp/9876"
|
||||||
)]
|
)]
|
||||||
listen_addr: Multiaddr,
|
listen_addr: Multiaddr,
|
||||||
@ -51,7 +52,7 @@ pub enum Command {
|
|||||||
|
|
||||||
#[structopt(
|
#[structopt(
|
||||||
short = "b",
|
short = "b",
|
||||||
long = "bitcoind",
|
long = "bitcoind-rpc",
|
||||||
default_value = "http://127.0.0.1:8332"
|
default_value = "http://127.0.0.1:8332"
|
||||||
)]
|
)]
|
||||||
bitcoind_url: Url,
|
bitcoind_url: Url,
|
||||||
@ -79,7 +80,7 @@ pub enum Command {
|
|||||||
|
|
||||||
#[structopt(
|
#[structopt(
|
||||||
short = "b",
|
short = "b",
|
||||||
long = "bitcoind",
|
long = "bitcoind-rpc",
|
||||||
default_value = "http://127.0.0.1:8332"
|
default_value = "http://127.0.0.1:8332"
|
||||||
)]
|
)]
|
||||||
bitcoind_url: Url,
|
bitcoind_url: Url,
|
||||||
@ -98,7 +99,7 @@ pub enum Command {
|
|||||||
// see: https://github.com/comit-network/xmr-btc-swap/issues/77
|
// see: https://github.com/comit-network/xmr-btc-swap/issues/77
|
||||||
#[structopt(
|
#[structopt(
|
||||||
short = "a",
|
short = "a",
|
||||||
long = "listen-addr",
|
long = "p2p-address",
|
||||||
default_value = "/ip4/127.0.0.1/tcp/9876"
|
default_value = "/ip4/127.0.0.1/tcp/9876"
|
||||||
)]
|
)]
|
||||||
listen_addr: Multiaddr,
|
listen_addr: Multiaddr,
|
||||||
|
Loading…
Reference in New Issue
Block a user