|
|
|
@ -100,6 +100,36 @@ async fn main() -> Result<()> {
|
|
|
|
|
let seed =
|
|
|
|
|
Seed::from_file_or_generate(&config.data.dir).expect("Could not retrieve/initialize seed");
|
|
|
|
|
|
|
|
|
|
let tor_client =
|
|
|
|
|
tor::Client::new(config.tor.socks5_port).with_control_port(config.tor.control_port);
|
|
|
|
|
let _ac = match tor_client.assert_tor_running().await {
|
|
|
|
|
Ok(_) => {
|
|
|
|
|
tracing::info!("Setting up Tor hidden service");
|
|
|
|
|
let ac =
|
|
|
|
|
register_tor_services(config.network.clone().listen, tor_client, &seed).await?;
|
|
|
|
|
Some(ac)
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
|
|
|
|
tracing::warn!("Tor not found. Running on clear net");
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let tor_port = if _ac.is_some() {
|
|
|
|
|
config.tor.socks5_port
|
|
|
|
|
} else {
|
|
|
|
|
0u16
|
|
|
|
|
};
|
|
|
|
|
let proxy_string = if tor_port != 0u16 {
|
|
|
|
|
format!("127.0.0.1:{}", tor_port)
|
|
|
|
|
} else {
|
|
|
|
|
"".to_string()
|
|
|
|
|
};
|
|
|
|
|
if proxy_string.is_empty() {
|
|
|
|
|
tracing::info!(%proxy_string, "Not using SOCKS5 proxy");
|
|
|
|
|
} else {
|
|
|
|
|
tracing::info!(%proxy_string, "Using SOCKS5 proxy at");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
match cmd {
|
|
|
|
|
Command::Start { resume_only } => {
|
|
|
|
|
// check and warn for duplicate rendezvous points
|
|
|
|
@ -140,29 +170,13 @@ async fn main() -> Result<()> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
|
|
|
|
let bitcoin_wallet =
|
|
|
|
|
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?;
|
|
|
|
|
let bitcoin_balance = bitcoin_wallet.balance().await?;
|
|
|
|
|
tracing::info!(%bitcoin_balance, "Bitcoin wallet balance");
|
|
|
|
|
|
|
|
|
|
let kraken_price_updates = kraken::connect(config.maker.price_ticker_ws_url.clone())?;
|
|
|
|
|
|
|
|
|
|
// setup Tor hidden services
|
|
|
|
|
let tor_client =
|
|
|
|
|
tor::Client::new(config.tor.socks5_port).with_control_port(config.tor.control_port);
|
|
|
|
|
let _ac = match tor_client.assert_tor_running().await {
|
|
|
|
|
Ok(_) => {
|
|
|
|
|
tracing::info!("Setting up Tor hidden service");
|
|
|
|
|
let ac =
|
|
|
|
|
register_tor_services(config.network.clone().listen, tor_client, &seed)
|
|
|
|
|
.await?;
|
|
|
|
|
Some(ac)
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
|
|
|
|
tracing::warn!("Tor not found. Running on clear net");
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let kraken_rate = KrakenRate::new(config.maker.ask_spread, kraken_price_updates);
|
|
|
|
|
let namespace = XmrBtcNamespace::from_is_testnet(testnet);
|
|
|
|
|
|
|
|
|
@ -175,7 +189,9 @@ async fn main() -> Result<()> {
|
|
|
|
|
env_config,
|
|
|
|
|
namespace,
|
|
|
|
|
&rendezvous_addrs,
|
|
|
|
|
)?;
|
|
|
|
|
tor_port,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
for listen in config.network.listen.clone() {
|
|
|
|
|
Swarm::listen_on(&mut swarm, listen.clone())
|
|
|
|
@ -241,7 +257,8 @@ async fn main() -> Result<()> {
|
|
|
|
|
println!("{}", config_json);
|
|
|
|
|
}
|
|
|
|
|
Command::WithdrawBtc { amount, address } => {
|
|
|
|
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
|
|
|
|
let bitcoin_wallet =
|
|
|
|
|
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?;
|
|
|
|
|
|
|
|
|
|
let amount = match amount {
|
|
|
|
|
Some(amount) => amount,
|
|
|
|
@ -264,20 +281,23 @@ async fn main() -> Result<()> {
|
|
|
|
|
let monero_balance = monero_wallet.get_balance().await?;
|
|
|
|
|
tracing::info!(%monero_balance);
|
|
|
|
|
|
|
|
|
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
|
|
|
|
let bitcoin_wallet =
|
|
|
|
|
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?;
|
|
|
|
|
let bitcoin_balance = bitcoin_wallet.balance().await?;
|
|
|
|
|
tracing::info!(%bitcoin_balance);
|
|
|
|
|
tracing::info!(%bitcoin_balance, %monero_balance, "Current balance");
|
|
|
|
|
}
|
|
|
|
|
Command::Cancel { swap_id } => {
|
|
|
|
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
|
|
|
|
let bitcoin_wallet =
|
|
|
|
|
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?;
|
|
|
|
|
|
|
|
|
|
let (txid, _) = cancel(swap_id, Arc::new(bitcoin_wallet), db).await?;
|
|
|
|
|
|
|
|
|
|
tracing::info!("Cancel transaction successfully published with id {}", txid);
|
|
|
|
|
}
|
|
|
|
|
Command::Refund { swap_id } => {
|
|
|
|
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
|
|
|
|
let bitcoin_wallet =
|
|
|
|
|
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?;
|
|
|
|
|
let monero_wallet = init_monero_wallet(&config, env_config).await?;
|
|
|
|
|
|
|
|
|
|
refund(
|
|
|
|
@ -291,7 +311,8 @@ async fn main() -> Result<()> {
|
|
|
|
|
tracing::info!("Monero successfully refunded");
|
|
|
|
|
}
|
|
|
|
|
Command::Punish { swap_id } => {
|
|
|
|
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
|
|
|
|
let bitcoin_wallet =
|
|
|
|
|
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?;
|
|
|
|
|
|
|
|
|
|
let (txid, _) = punish(swap_id, Arc::new(bitcoin_wallet), db).await?;
|
|
|
|
|
|
|
|
|
@ -306,7 +327,8 @@ async fn main() -> Result<()> {
|
|
|
|
|
swap_id,
|
|
|
|
|
do_not_await_finality,
|
|
|
|
|
} => {
|
|
|
|
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
|
|
|
|
let bitcoin_wallet =
|
|
|
|
|
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?;
|
|
|
|
|
|
|
|
|
|
let (txid, _) = redeem(
|
|
|
|
|
swap_id,
|
|
|
|
@ -319,7 +341,8 @@ async fn main() -> Result<()> {
|
|
|
|
|
tracing::info!("Redeem transaction successfully published with id {}", txid);
|
|
|
|
|
}
|
|
|
|
|
Command::ExportBitcoinWallet => {
|
|
|
|
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
|
|
|
|
let bitcoin_wallet =
|
|
|
|
|
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?;
|
|
|
|
|
let wallet_export = bitcoin_wallet.wallet_export("asb").await?;
|
|
|
|
|
println!("{}", wallet_export.to_string())
|
|
|
|
|
}
|
|
|
|
@ -332,11 +355,13 @@ async fn init_bitcoin_wallet(
|
|
|
|
|
config: &Config,
|
|
|
|
|
seed: &Seed,
|
|
|
|
|
env_config: swap::env::Config,
|
|
|
|
|
proxy_string: String,
|
|
|
|
|
) -> Result<bitcoin::Wallet> {
|
|
|
|
|
tracing::debug!("Opening Bitcoin wallet");
|
|
|
|
|
let data_dir = &config.data.dir;
|
|
|
|
|
let wallet = bitcoin::Wallet::new(
|
|
|
|
|
config.bitcoin.electrum_rpc_url.clone(),
|
|
|
|
|
proxy_string.as_str(),
|
|
|
|
|
data_dir,
|
|
|
|
|
seed.derive_extended_private_key(env_config.bitcoin_network)?,
|
|
|
|
|
env_config,
|
|
|
|
|