mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-12 16:09:29 -05:00
Add config/argument to swap/asb to configure bitcoin tx fees.
This commit is contained in:
parent
9e8b788aa9
commit
46e0449b8e
@ -16,6 +16,7 @@ const DEFAULT_LISTEN_ADDRESS_TCP: &str = "/ip4/0.0.0.0/tcp/9939";
|
|||||||
const DEFAULT_LISTEN_ADDRESS_WS: &str = "/ip4/0.0.0.0/tcp/9940/ws";
|
const DEFAULT_LISTEN_ADDRESS_WS: &str = "/ip4/0.0.0.0/tcp/9940/ws";
|
||||||
const DEFAULT_ELECTRUM_RPC_URL: &str = "ssl://electrum.blockstream.info:60002";
|
const DEFAULT_ELECTRUM_RPC_URL: &str = "ssl://electrum.blockstream.info:60002";
|
||||||
const DEFAULT_MONERO_WALLET_RPC_TESTNET_URL: &str = "http://127.0.0.1:38083/json_rpc";
|
const DEFAULT_MONERO_WALLET_RPC_TESTNET_URL: &str = "http://127.0.0.1:38083/json_rpc";
|
||||||
|
const DEFAULT_BITCOIN_CONFIRMATION_TARGET: usize = 3;
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
@ -55,6 +56,7 @@ pub struct Network {
|
|||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Bitcoin {
|
pub struct Bitcoin {
|
||||||
pub electrum_rpc_url: Url,
|
pub electrum_rpc_url: Url,
|
||||||
|
pub target_block: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
@ -148,6 +150,10 @@ pub fn query_user_for_initial_testnet_config() -> Result<Config> {
|
|||||||
.interact_text()?;
|
.interact_text()?;
|
||||||
let data_dir = data_dir.as_str().parse()?;
|
let data_dir = data_dir.as_str().parse()?;
|
||||||
|
|
||||||
|
let target_block = Input::with_theme(&ColorfulTheme::default())
|
||||||
|
.with_prompt("How fast should your Bitcoin transactions be confirmed? Your transaction fee will be calculated based on this target. Hit return to use default")
|
||||||
|
.default(DEFAULT_BITCOIN_CONFIRMATION_TARGET)
|
||||||
|
.interact_text()?;
|
||||||
let listen_addresses = Input::with_theme(&ColorfulTheme::default())
|
let listen_addresses = Input::with_theme(&ColorfulTheme::default())
|
||||||
.with_prompt("Enter multiaddresses (comma separated) on which asb should list for peer-to-peer communications or hit return to use default")
|
.with_prompt("Enter multiaddresses (comma separated) on which asb should list for peer-to-peer communications or hit return to use default")
|
||||||
.default( format!("{},{}", DEFAULT_LISTEN_ADDRESS_TCP, DEFAULT_LISTEN_ADDRESS_WS))
|
.default( format!("{},{}", DEFAULT_LISTEN_ADDRESS_TCP, DEFAULT_LISTEN_ADDRESS_WS))
|
||||||
@ -186,7 +192,10 @@ pub fn query_user_for_initial_testnet_config() -> Result<Config> {
|
|||||||
network: Network {
|
network: Network {
|
||||||
listen: listen_addresses,
|
listen: listen_addresses,
|
||||||
},
|
},
|
||||||
bitcoin: Bitcoin { electrum_rpc_url },
|
bitcoin: Bitcoin {
|
||||||
|
electrum_rpc_url,
|
||||||
|
target_block,
|
||||||
|
},
|
||||||
monero: Monero {
|
monero: Monero {
|
||||||
wallet_rpc_url: monero_wallet_rpc_url,
|
wallet_rpc_url: monero_wallet_rpc_url,
|
||||||
},
|
},
|
||||||
@ -214,6 +223,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
bitcoin: Bitcoin {
|
bitcoin: Bitcoin {
|
||||||
electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL).unwrap(),
|
electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL).unwrap(),
|
||||||
|
target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET,
|
||||||
},
|
},
|
||||||
network: Network {
|
network: Network {
|
||||||
listen: vec![
|
listen: vec![
|
||||||
|
@ -211,7 +211,7 @@ async fn init_bitcoin_wallet(
|
|||||||
&wallet_dir,
|
&wallet_dir,
|
||||||
seed.derive_extended_private_key(env_config.bitcoin_network)?,
|
seed.derive_extended_private_key(env_config.bitcoin_network)?,
|
||||||
env_config,
|
env_config,
|
||||||
6, // TODO move this into config
|
config.bitcoin.target_block,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("Failed to initialize Bitcoin wallet")?;
|
.context("Failed to initialize Bitcoin wallet")?;
|
||||||
|
@ -52,6 +52,7 @@ async fn main() -> Result<()> {
|
|||||||
},
|
},
|
||||||
electrum_rpc_url,
|
electrum_rpc_url,
|
||||||
tor_socks5_port,
|
tor_socks5_port,
|
||||||
|
bitcoin_target_block,
|
||||||
} => {
|
} => {
|
||||||
let swap_id = Uuid::new_v4();
|
let swap_id = Uuid::new_v4();
|
||||||
|
|
||||||
@ -71,8 +72,14 @@ async fn main() -> Result<()> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let bitcoin_wallet =
|
let bitcoin_wallet = init_bitcoin_wallet(
|
||||||
init_bitcoin_wallet(electrum_rpc_url, &seed, data_dir.clone(), env_config).await?;
|
electrum_rpc_url,
|
||||||
|
&seed,
|
||||||
|
data_dir.clone(),
|
||||||
|
env_config,
|
||||||
|
bitcoin_target_block,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
let (monero_wallet, _process) =
|
let (monero_wallet, _process) =
|
||||||
init_monero_wallet(data_dir, monero_daemon_host, env_config).await?;
|
init_monero_wallet(data_dir, monero_daemon_host, env_config).await?;
|
||||||
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
@ -154,6 +161,7 @@ async fn main() -> Result<()> {
|
|||||||
},
|
},
|
||||||
electrum_rpc_url,
|
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)?;
|
||||||
@ -167,8 +175,14 @@ async fn main() -> Result<()> {
|
|||||||
bail!("The given monero address is on network {:?}, expected address of network {:?}.", receive_monero_address.network, env_config.monero_network)
|
bail!("The given monero address is on network {:?}, expected address of network {:?}.", receive_monero_address.network, env_config.monero_network)
|
||||||
}
|
}
|
||||||
|
|
||||||
let bitcoin_wallet =
|
let bitcoin_wallet = init_bitcoin_wallet(
|
||||||
init_bitcoin_wallet(electrum_rpc_url, &seed, data_dir.clone(), env_config).await?;
|
electrum_rpc_url,
|
||||||
|
&seed,
|
||||||
|
data_dir.clone(),
|
||||||
|
env_config,
|
||||||
|
bitcoin_target_block,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
let (monero_wallet, _process) =
|
let (monero_wallet, _process) =
|
||||||
init_monero_wallet(data_dir, monero_daemon_host, env_config).await?;
|
init_monero_wallet(data_dir, monero_daemon_host, env_config).await?;
|
||||||
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
@ -209,6 +223,7 @@ async fn main() -> Result<()> {
|
|||||||
swap_id,
|
swap_id,
|
||||||
force,
|
force,
|
||||||
electrum_rpc_url,
|
electrum_rpc_url,
|
||||||
|
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)?;
|
||||||
@ -218,8 +233,14 @@ async fn main() -> Result<()> {
|
|||||||
.context("Failed to read in seed file")?;
|
.context("Failed to read in seed file")?;
|
||||||
let env_config = env::Testnet::get_config();
|
let env_config = env::Testnet::get_config();
|
||||||
|
|
||||||
let bitcoin_wallet =
|
let bitcoin_wallet = init_bitcoin_wallet(
|
||||||
init_bitcoin_wallet(electrum_rpc_url, &seed, data_dir, env_config).await?;
|
electrum_rpc_url,
|
||||||
|
&seed,
|
||||||
|
data_dir,
|
||||||
|
env_config,
|
||||||
|
bitcoin_target_block,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let resume_state = db.get_state(swap_id)?.try_into_bob()?.into();
|
let resume_state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||||
let cancel =
|
let cancel =
|
||||||
@ -239,6 +260,7 @@ async fn main() -> Result<()> {
|
|||||||
swap_id,
|
swap_id,
|
||||||
force,
|
force,
|
||||||
electrum_rpc_url,
|
electrum_rpc_url,
|
||||||
|
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)?;
|
||||||
@ -248,8 +270,14 @@ async fn main() -> Result<()> {
|
|||||||
.context("Failed to read in seed file")?;
|
.context("Failed to read in seed file")?;
|
||||||
let env_config = env::Testnet::get_config();
|
let env_config = env::Testnet::get_config();
|
||||||
|
|
||||||
let bitcoin_wallet =
|
let bitcoin_wallet = init_bitcoin_wallet(
|
||||||
init_bitcoin_wallet(electrum_rpc_url, &seed, data_dir, env_config).await?;
|
electrum_rpc_url,
|
||||||
|
&seed,
|
||||||
|
data_dir,
|
||||||
|
env_config,
|
||||||
|
bitcoin_target_block,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let resume_state = db.get_state(swap_id)?.try_into_bob()?.into();
|
let resume_state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||||
|
|
||||||
@ -264,6 +292,7 @@ async fn init_bitcoin_wallet(
|
|||||||
seed: &Seed,
|
seed: &Seed,
|
||||||
data_dir: PathBuf,
|
data_dir: PathBuf,
|
||||||
env_config: Config,
|
env_config: Config,
|
||||||
|
bitcoin_target_block: usize,
|
||||||
) -> Result<bitcoin::Wallet> {
|
) -> Result<bitcoin::Wallet> {
|
||||||
let wallet_dir = data_dir.join("wallet");
|
let wallet_dir = data_dir.join("wallet");
|
||||||
|
|
||||||
@ -272,7 +301,7 @@ async fn init_bitcoin_wallet(
|
|||||||
&wallet_dir,
|
&wallet_dir,
|
||||||
seed.derive_extended_private_key(env_config.bitcoin_network)?,
|
seed.derive_extended_private_key(env_config.bitcoin_network)?,
|
||||||
env_config,
|
env_config,
|
||||||
6, // TODO move this into config
|
bitcoin_target_block,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("Failed to initialize Bitcoin wallet")?;
|
.context("Failed to initialize Bitcoin wallet")?;
|
||||||
|
@ -15,6 +15,9 @@ const DEFAULT_ELECTRUM_RPC_URL: &str = "ssl://electrum.blockstream.info:60002";
|
|||||||
|
|
||||||
const DEFAULT_TOR_SOCKS5_PORT: &str = "9050";
|
const DEFAULT_TOR_SOCKS5_PORT: &str = "9050";
|
||||||
|
|
||||||
|
// Bitcoin transactions should be confirmed within X blocks
|
||||||
|
const DEFAUL_BITCOIN_CONFIRMATION_TARGET: &str = "3";
|
||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
#[structopt(name = "swap", about = "CLI for swapping BTC for XMR", author)]
|
#[structopt(name = "swap", about = "CLI for swapping BTC for XMR", author)]
|
||||||
pub struct Arguments {
|
pub struct Arguments {
|
||||||
@ -53,6 +56,9 @@ pub enum Command {
|
|||||||
|
|
||||||
#[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 = DEFAUL_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,
|
||||||
@ -78,6 +84,9 @@ pub enum Command {
|
|||||||
|
|
||||||
#[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 = DEFAUL_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 {
|
||||||
@ -95,6 +104,9 @@ pub enum Command {
|
|||||||
default_value = DEFAULT_ELECTRUM_RPC_URL
|
default_value = DEFAULT_ELECTRUM_RPC_URL
|
||||||
)]
|
)]
|
||||||
electrum_rpc_url: Url,
|
electrum_rpc_url: Url,
|
||||||
|
|
||||||
|
#[structopt(long = "bitcoin-target-block", help = "Within how many blocks should the Bitcoin transactions be confirmed.", default_value = DEFAUL_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 {
|
||||||
@ -112,6 +124,9 @@ pub enum Command {
|
|||||||
default_value = DEFAULT_ELECTRUM_RPC_URL
|
default_value = DEFAULT_ELECTRUM_RPC_URL
|
||||||
)]
|
)]
|
||||||
electrum_rpc_url: Url,
|
electrum_rpc_url: Url,
|
||||||
|
|
||||||
|
#[structopt(long = "bitcoin-target-block", help = "Within how many blocks should the Bitcoin transactions be confirmed.", default_value = DEFAUL_BITCOIN_CONFIRMATION_TARGET)]
|
||||||
|
bitcoin_target_block: usize,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user