Bitcoin parameters that can be reused

Get rid of parameter duplication.
This commit is contained in:
Daniel Karzel 2021-05-11 11:36:44 +10:00
parent a489564857
commit 657ac1e2e4
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
2 changed files with 41 additions and 41 deletions

View File

@ -21,7 +21,7 @@ use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use structopt::StructOpt; use structopt::StructOpt;
use swap::bitcoin::TxLock; use swap::bitcoin::TxLock;
use swap::cli::command::{Arguments, Command, MoneroParams}; use swap::cli::command::{Arguments, BitcoinParams, Command, MoneroParams};
use swap::database::Database; use swap::database::Database;
use swap::env::{Config, GetConfig}; use swap::env::{Config, GetConfig};
use swap::network::quote::BidQuote; use swap::network::quote::BidQuote;
@ -45,14 +45,17 @@ async fn main() -> Result<()> {
Command::BuyXmr { Command::BuyXmr {
alice_peer_id, alice_peer_id,
alice_multiaddr, alice_multiaddr,
bitcoin_params:
BitcoinParams {
electrum_rpc_url,
bitcoin_target_block,
},
monero_params: monero_params:
MoneroParams { MoneroParams {
receive_monero_address, receive_monero_address,
monero_daemon_host, monero_daemon_host,
}, },
electrum_rpc_url,
tor_socks5_port, tor_socks5_port,
bitcoin_target_block,
} => { } => {
let swap_id = Uuid::new_v4(); let swap_id = Uuid::new_v4();
@ -149,14 +152,17 @@ async fn main() -> Result<()> {
Command::Resume { Command::Resume {
swap_id, swap_id,
alice_multiaddr, alice_multiaddr,
bitcoin_params:
BitcoinParams {
electrum_rpc_url,
bitcoin_target_block,
},
monero_params: monero_params:
MoneroParams { MoneroParams {
receive_monero_address, receive_monero_address,
monero_daemon_host, monero_daemon_host,
}, },
electrum_rpc_url,
tor_socks5_port, tor_socks5_port,
bitcoin_target_block,
} => { } => {
let data_dir = data.0; let data_dir = data.0;
cli::tracing::init(debug, data_dir.join("logs"), swap_id)?; cli::tracing::init(debug, data_dir.join("logs"), swap_id)?;
@ -217,8 +223,11 @@ async fn main() -> Result<()> {
Command::Cancel { Command::Cancel {
swap_id, swap_id,
force, force,
bitcoin_params:
BitcoinParams {
electrum_rpc_url, electrum_rpc_url,
bitcoin_target_block, bitcoin_target_block,
},
} => { } => {
let data_dir = data.0; let data_dir = data.0;
cli::tracing::init(debug, data_dir.join("logs"), swap_id)?; cli::tracing::init(debug, data_dir.join("logs"), swap_id)?;
@ -251,8 +260,11 @@ async fn main() -> Result<()> {
Command::Refund { Command::Refund {
swap_id, swap_id,
force, force,
bitcoin_params:
BitcoinParams {
electrum_rpc_url, electrum_rpc_url,
bitcoin_target_block, bitcoin_target_block,
},
} => { } => {
let data_dir = data.0; let data_dir = data.0;
cli::tracing::init(debug, data_dir.join("logs"), swap_id)?; cli::tracing::init(debug, data_dir.join("logs"), swap_id)?;

View File

@ -42,20 +42,14 @@ pub enum Command {
#[structopt(long = "seller-addr", help = "The seller's multiaddress")] #[structopt(long = "seller-addr", help = "The seller's multiaddress")]
alice_multiaddr: Multiaddr, alice_multiaddr: Multiaddr,
#[structopt(long = "electrum-rpc", #[structopt(flatten)]
help = "Provide the Bitcoin Electrum RPC URL", bitcoin_params: BitcoinParams,
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
#[structopt(flatten)] #[structopt(flatten)]
monero_params: MoneroParams, monero_params: MoneroParams,
#[structopt(long = "tor-socks5-port", help = "Your local Tor socks5 proxy port", default_value = DEFAULT_TOR_SOCKS5_PORT)] #[structopt(long = "tor-socks5-port", help = "Your local Tor socks5 proxy port", default_value = DEFAULT_TOR_SOCKS5_PORT)]
tor_socks5_port: u16, tor_socks5_port: u16,
#[structopt(long = "bitcoin-target-block", help = "Within how many blocks should the Bitcoin transactions be confirmed.", default_value = DEFAULT_BITCOIN_CONFIRMATION_TARGET)]
bitcoin_target_block: usize,
}, },
/// Show a list of past ongoing and completed swaps /// Show a list of past ongoing and completed swaps
History, History,
@ -70,20 +64,14 @@ pub enum Command {
#[structopt(long = "seller-addr", help = "The seller's multiaddress")] #[structopt(long = "seller-addr", help = "The seller's multiaddress")]
alice_multiaddr: Multiaddr, alice_multiaddr: Multiaddr,
#[structopt(long = "electrum-rpc", #[structopt(flatten)]
help = "Provide the Bitcoin Electrum RPC URL", bitcoin_params: BitcoinParams,
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
#[structopt(flatten)] #[structopt(flatten)]
monero_params: MoneroParams, monero_params: MoneroParams,
#[structopt(long = "tor-socks5-port", help = "Your local Tor socks5 proxy port", default_value = DEFAULT_TOR_SOCKS5_PORT)] #[structopt(long = "tor-socks5-port", help = "Your local Tor socks5 proxy port", default_value = DEFAULT_TOR_SOCKS5_PORT)]
tor_socks5_port: u16, tor_socks5_port: u16,
#[structopt(long = "bitcoin-target-block", help = "Within how many blocks should the Bitcoin transactions be confirmed.", default_value = DEFAULT_BITCOIN_CONFIRMATION_TARGET)]
bitcoin_target_block: usize,
}, },
/// Try to cancel an ongoing swap (expert users only) /// Try to cancel an ongoing swap (expert users only)
Cancel { Cancel {
@ -96,14 +84,8 @@ pub enum Command {
#[structopt(short, long)] #[structopt(short, long)]
force: bool, force: bool,
#[structopt(long = "electrum-rpc", #[structopt(flatten)]
help = "Provide the Bitcoin Electrum RPC URL", bitcoin_params: BitcoinParams,
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
#[structopt(long = "bitcoin-target-block", help = "Within how many blocks should the Bitcoin transactions be confirmed.", default_value = DEFAULT_BITCOIN_CONFIRMATION_TARGET)]
bitcoin_target_block: usize,
}, },
/// Try to cancel a swap and refund my BTC (expert users only) /// Try to cancel a swap and refund my BTC (expert users only)
Refund { Refund {
@ -116,14 +98,8 @@ pub enum Command {
#[structopt(short, long)] #[structopt(short, long)]
force: bool, force: bool,
#[structopt(long = "electrum-rpc", #[structopt(flatten)]
help = "Provide the Bitcoin Electrum RPC URL", bitcoin_params: BitcoinParams,
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
#[structopt(long = "bitcoin-target-block", help = "Within how many blocks should the Bitcoin transactions be confirmed.", default_value = DEFAULT_BITCOIN_CONFIRMATION_TARGET)]
bitcoin_target_block: usize,
}, },
} }
@ -143,6 +119,18 @@ pub struct MoneroParams {
pub monero_daemon_host: String, pub monero_daemon_host: String,
} }
#[derive(structopt::StructOpt, Debug)]
pub struct BitcoinParams {
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
pub electrum_rpc_url: Url,
#[structopt(long = "bitcoin-target-block", help = "Within how many blocks should the Bitcoin transactions be confirmed.", default_value = DEFAULT_BITCOIN_CONFIRMATION_TARGET)]
pub bitcoin_target_block: usize,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Data(pub PathBuf); pub struct Data(pub PathBuf);