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 structopt::StructOpt;
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::env::{Config, GetConfig};
use swap::network::quote::BidQuote;
@ -45,14 +45,17 @@ async fn main() -> Result<()> {
Command::BuyXmr {
alice_peer_id,
alice_multiaddr,
bitcoin_params:
BitcoinParams {
electrum_rpc_url,
bitcoin_target_block,
},
monero_params:
MoneroParams {
receive_monero_address,
monero_daemon_host,
},
electrum_rpc_url,
tor_socks5_port,
bitcoin_target_block,
} => {
let swap_id = Uuid::new_v4();
@ -149,14 +152,17 @@ async fn main() -> Result<()> {
Command::Resume {
swap_id,
alice_multiaddr,
bitcoin_params:
BitcoinParams {
electrum_rpc_url,
bitcoin_target_block,
},
monero_params:
MoneroParams {
receive_monero_address,
monero_daemon_host,
},
electrum_rpc_url,
tor_socks5_port,
bitcoin_target_block,
} => {
let data_dir = data.0;
cli::tracing::init(debug, data_dir.join("logs"), swap_id)?;
@ -217,8 +223,11 @@ async fn main() -> Result<()> {
Command::Cancel {
swap_id,
force,
electrum_rpc_url,
bitcoin_target_block,
bitcoin_params:
BitcoinParams {
electrum_rpc_url,
bitcoin_target_block,
},
} => {
let data_dir = data.0;
cli::tracing::init(debug, data_dir.join("logs"), swap_id)?;
@ -251,8 +260,11 @@ async fn main() -> Result<()> {
Command::Refund {
swap_id,
force,
electrum_rpc_url,
bitcoin_target_block,
bitcoin_params:
BitcoinParams {
electrum_rpc_url,
bitcoin_target_block,
},
} => {
let data_dir = data.0;
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")]
alice_multiaddr: Multiaddr,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
#[structopt(flatten)]
bitcoin_params: BitcoinParams,
#[structopt(flatten)]
monero_params: MoneroParams,
#[structopt(long = "tor-socks5-port", help = "Your local Tor socks5 proxy port", default_value = DEFAULT_TOR_SOCKS5_PORT)]
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
History,
@ -70,20 +64,14 @@ pub enum Command {
#[structopt(long = "seller-addr", help = "The seller's multiaddress")]
alice_multiaddr: Multiaddr,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
default_value = DEFAULT_ELECTRUM_RPC_URL
)]
electrum_rpc_url: Url,
#[structopt(flatten)]
bitcoin_params: BitcoinParams,
#[structopt(flatten)]
monero_params: MoneroParams,
#[structopt(long = "tor-socks5-port", help = "Your local Tor socks5 proxy port", default_value = DEFAULT_TOR_SOCKS5_PORT)]
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)
Cancel {
@ -96,14 +84,8 @@ pub enum Command {
#[structopt(short, long)]
force: bool,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
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,
#[structopt(flatten)]
bitcoin_params: BitcoinParams,
},
/// Try to cancel a swap and refund my BTC (expert users only)
Refund {
@ -116,14 +98,8 @@ pub enum Command {
#[structopt(short, long)]
force: bool,
#[structopt(long = "electrum-rpc",
help = "Provide the Bitcoin Electrum RPC URL",
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,
#[structopt(flatten)]
bitcoin_params: BitcoinParams,
},
}
@ -143,6 +119,18 @@ pub struct MoneroParams {
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)]
pub struct Data(pub PathBuf);