mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Pass execution params directly into wallet for initialization
This reduces the amount of parameters that we need to pass in.
This commit is contained in:
parent
7213907a79
commit
bc43ed6ebd
@ -38,8 +38,6 @@ use tracing_subscriber::filter::LevelFilter;
|
|||||||
extern crate prettytable;
|
extern crate prettytable;
|
||||||
|
|
||||||
const DEFAULT_WALLET_NAME: &str = "asb-wallet";
|
const DEFAULT_WALLET_NAME: &str = "asb-wallet";
|
||||||
const BITCOIN_NETWORK: bitcoin::Network = bitcoin::Network::Testnet;
|
|
||||||
const MONERO_NETWORK: monero::Network = monero::Network::Stagenet;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@ -78,13 +76,13 @@ async fn main() -> Result<()> {
|
|||||||
let seed = Seed::from_file_or_generate(&config.data.dir)
|
let seed = Seed::from_file_or_generate(&config.data.dir)
|
||||||
.expect("Could not retrieve/initialize seed");
|
.expect("Could not retrieve/initialize seed");
|
||||||
|
|
||||||
let execution_params = execution_params::Testnet::get_execution_params();
|
let exec_params = execution_params::Testnet::get_execution_params();
|
||||||
|
|
||||||
let (bitcoin_wallet, monero_wallet) = init_wallets(
|
let (bitcoin_wallet, monero_wallet) = init_wallets(
|
||||||
config.clone(),
|
config.clone(),
|
||||||
&wallet_data_dir,
|
&wallet_data_dir,
|
||||||
seed.derive_extended_private_key(BITCOIN_NETWORK)?,
|
seed.derive_extended_private_key(exec_params.bitcoin_network)?,
|
||||||
execution_params,
|
exec_params,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -98,7 +96,7 @@ async fn main() -> Result<()> {
|
|||||||
let (event_loop, mut swap_receiver) = EventLoop::new(
|
let (event_loop, mut swap_receiver) = EventLoop::new(
|
||||||
config.network.listen,
|
config.network.listen,
|
||||||
seed,
|
seed,
|
||||||
execution_params,
|
exec_params,
|
||||||
Arc::new(bitcoin_wallet),
|
Arc::new(bitcoin_wallet),
|
||||||
Arc::new(monero_wallet),
|
Arc::new(monero_wallet),
|
||||||
Arc::new(db),
|
Arc::new(db),
|
||||||
@ -148,14 +146,13 @@ async fn init_wallets(
|
|||||||
config: Config,
|
config: Config,
|
||||||
bitcoin_wallet_data_dir: &Path,
|
bitcoin_wallet_data_dir: &Path,
|
||||||
key: impl DerivableKey<Segwitv0> + Clone,
|
key: impl DerivableKey<Segwitv0> + Clone,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
) -> Result<(bitcoin::Wallet, monero::Wallet)> {
|
) -> Result<(bitcoin::Wallet, monero::Wallet)> {
|
||||||
let bitcoin_wallet = bitcoin::Wallet::new(
|
let bitcoin_wallet = bitcoin::Wallet::new(
|
||||||
config.bitcoin.electrum_rpc_url,
|
config.bitcoin.electrum_rpc_url,
|
||||||
BITCOIN_NETWORK,
|
|
||||||
execution_params.bitcoin_finality_confirmations,
|
|
||||||
bitcoin_wallet_data_dir,
|
bitcoin_wallet_data_dir,
|
||||||
key,
|
key,
|
||||||
|
exec_params,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -169,9 +166,8 @@ async fn init_wallets(
|
|||||||
|
|
||||||
let monero_wallet = monero::Wallet::new(
|
let monero_wallet = monero::Wallet::new(
|
||||||
config.monero.wallet_rpc_url.clone(),
|
config.monero.wallet_rpc_url.clone(),
|
||||||
MONERO_NETWORK,
|
|
||||||
DEFAULT_WALLET_NAME.to_string(),
|
DEFAULT_WALLET_NAME.to_string(),
|
||||||
execution_params.monero_avg_block_time,
|
exec_params,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Setup the Monero wallet
|
// Setup the Monero wallet
|
||||||
|
@ -76,10 +76,7 @@ async fn main() -> Result<()> {
|
|||||||
let seed =
|
let seed =
|
||||||
Seed::from_file_or_generate(data_dir.as_path()).context("Failed to read in seed file")?;
|
Seed::from_file_or_generate(data_dir.as_path()).context("Failed to read in seed file")?;
|
||||||
|
|
||||||
// hardcode to testnet/stagenet
|
let exec_params = execution_params::Testnet::get_execution_params();
|
||||||
let bitcoin_network = bitcoin::Network::Testnet;
|
|
||||||
let monero_network = monero::Network::Stagenet;
|
|
||||||
let execution_params = execution_params::Testnet::get_execution_params();
|
|
||||||
|
|
||||||
match args.cmd {
|
match args.cmd {
|
||||||
Command::BuyXmr {
|
Command::BuyXmr {
|
||||||
@ -95,29 +92,18 @@ async fn main() -> Result<()> {
|
|||||||
},
|
},
|
||||||
electrum_rpc_url,
|
electrum_rpc_url,
|
||||||
} => {
|
} => {
|
||||||
if receive_monero_address.network != monero_network {
|
if receive_monero_address.network != exec_params.monero_network {
|
||||||
bail!(
|
bail!(
|
||||||
"Given monero address is on network {:?}, expected address on network {:?}",
|
"Given monero address is on network {:?}, expected address on network {:?}",
|
||||||
receive_monero_address.network,
|
receive_monero_address.network,
|
||||||
monero_network
|
exec_params.monero_network
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let bitcoin_wallet = init_bitcoin_wallet(
|
let bitcoin_wallet =
|
||||||
bitcoin_network,
|
init_bitcoin_wallet(electrum_rpc_url, seed, data_dir.clone(), exec_params).await?;
|
||||||
electrum_rpc_url,
|
let (monero_wallet, _process) =
|
||||||
seed,
|
init_monero_wallet(data_dir, monero_daemon_host, exec_params).await?;
|
||||||
data_dir.clone(),
|
|
||||||
execution_params,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let (monero_wallet, _process) = init_monero_wallet(
|
|
||||||
monero_network,
|
|
||||||
data_dir,
|
|
||||||
monero_daemon_host,
|
|
||||||
execution_params,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
let (event_loop, mut event_loop_handle) = EventLoop::new(
|
let (event_loop, mut event_loop_handle) = EventLoop::new(
|
||||||
&seed.derive_libp2p_identity(),
|
&seed.derive_libp2p_identity(),
|
||||||
@ -149,7 +135,7 @@ async fn main() -> Result<()> {
|
|||||||
Uuid::new_v4(),
|
Uuid::new_v4(),
|
||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
Arc::new(monero_wallet),
|
Arc::new(monero_wallet),
|
||||||
execution_params,
|
exec_params,
|
||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
@ -192,25 +178,14 @@ async fn main() -> Result<()> {
|
|||||||
},
|
},
|
||||||
electrum_rpc_url,
|
electrum_rpc_url,
|
||||||
} => {
|
} => {
|
||||||
if receive_monero_address.network != monero_network {
|
if receive_monero_address.network != exec_params.monero_network {
|
||||||
bail!("The given monero address is on network {:?}, expected address of network {:?}.", receive_monero_address.network, monero_network)
|
bail!("The given monero address is on network {:?}, expected address of network {:?}.", receive_monero_address.network, exec_params.monero_network)
|
||||||
}
|
}
|
||||||
|
|
||||||
let bitcoin_wallet = init_bitcoin_wallet(
|
let bitcoin_wallet =
|
||||||
bitcoin_network,
|
init_bitcoin_wallet(electrum_rpc_url, seed, data_dir.clone(), exec_params).await?;
|
||||||
electrum_rpc_url,
|
let (monero_wallet, _process) =
|
||||||
seed,
|
init_monero_wallet(data_dir, monero_daemon_host, exec_params).await?;
|
||||||
data_dir.clone(),
|
|
||||||
execution_params,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let (monero_wallet, _process) = init_monero_wallet(
|
|
||||||
monero_network,
|
|
||||||
data_dir,
|
|
||||||
monero_daemon_host,
|
|
||||||
execution_params,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
|
|
||||||
let (event_loop, event_loop_handle) = EventLoop::new(
|
let (event_loop, event_loop_handle) = EventLoop::new(
|
||||||
@ -226,7 +201,7 @@ async fn main() -> Result<()> {
|
|||||||
swap_id,
|
swap_id,
|
||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
Arc::new(monero_wallet),
|
Arc::new(monero_wallet),
|
||||||
execution_params,
|
exec_params,
|
||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
@ -247,14 +222,8 @@ async fn main() -> Result<()> {
|
|||||||
force,
|
force,
|
||||||
electrum_rpc_url,
|
electrum_rpc_url,
|
||||||
} => {
|
} => {
|
||||||
let bitcoin_wallet = init_bitcoin_wallet(
|
let bitcoin_wallet =
|
||||||
bitcoin_network,
|
init_bitcoin_wallet(electrum_rpc_url, seed, data_dir, exec_params).await?;
|
||||||
electrum_rpc_url,
|
|
||||||
seed,
|
|
||||||
data_dir,
|
|
||||||
execution_params,
|
|
||||||
)
|
|
||||||
.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 =
|
||||||
@ -278,14 +247,8 @@ async fn main() -> Result<()> {
|
|||||||
force,
|
force,
|
||||||
electrum_rpc_url,
|
electrum_rpc_url,
|
||||||
} => {
|
} => {
|
||||||
let bitcoin_wallet = init_bitcoin_wallet(
|
let bitcoin_wallet =
|
||||||
bitcoin_network,
|
init_bitcoin_wallet(electrum_rpc_url, seed, data_dir, exec_params).await?;
|
||||||
electrum_rpc_url,
|
|
||||||
seed,
|
|
||||||
data_dir,
|
|
||||||
execution_params,
|
|
||||||
)
|
|
||||||
.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();
|
||||||
|
|
||||||
@ -296,20 +259,18 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn init_bitcoin_wallet(
|
async fn init_bitcoin_wallet(
|
||||||
network: bitcoin::Network,
|
|
||||||
electrum_rpc_url: Url,
|
electrum_rpc_url: Url,
|
||||||
seed: Seed,
|
seed: Seed,
|
||||||
data_dir: PathBuf,
|
data_dir: PathBuf,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
) -> Result<bitcoin::Wallet> {
|
) -> Result<bitcoin::Wallet> {
|
||||||
let wallet_dir = data_dir.join("wallet");
|
let wallet_dir = data_dir.join("wallet");
|
||||||
|
|
||||||
let wallet = bitcoin::Wallet::new(
|
let wallet = bitcoin::Wallet::new(
|
||||||
electrum_rpc_url.clone(),
|
electrum_rpc_url.clone(),
|
||||||
network,
|
|
||||||
execution_params.bitcoin_finality_confirmations,
|
|
||||||
&wallet_dir,
|
&wallet_dir,
|
||||||
seed.derive_extended_private_key(network)?,
|
seed.derive_extended_private_key(exec_params.bitcoin_network)?,
|
||||||
|
exec_params,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("Failed to initialize Bitcoin wallet")?;
|
.context("Failed to initialize Bitcoin wallet")?;
|
||||||
@ -320,24 +281,24 @@ async fn init_bitcoin_wallet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn init_monero_wallet(
|
async fn init_monero_wallet(
|
||||||
monero_network: monero::Network,
|
|
||||||
data_dir: PathBuf,
|
data_dir: PathBuf,
|
||||||
monero_daemon_host: String,
|
monero_daemon_host: String,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
) -> Result<(monero::Wallet, monero::WalletRpcProcess)> {
|
) -> Result<(monero::Wallet, monero::WalletRpcProcess)> {
|
||||||
|
let network = exec_params.monero_network;
|
||||||
|
|
||||||
const MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME: &str = "swap-tool-blockchain-monitoring-wallet";
|
const MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME: &str = "swap-tool-blockchain-monitoring-wallet";
|
||||||
|
|
||||||
let monero_wallet_rpc = monero::WalletRpc::new(data_dir.join("monero")).await?;
|
let monero_wallet_rpc = monero::WalletRpc::new(data_dir.join("monero")).await?;
|
||||||
|
|
||||||
let monero_wallet_rpc_process = monero_wallet_rpc
|
let monero_wallet_rpc_process = monero_wallet_rpc
|
||||||
.run(monero_network, monero_daemon_host.as_str())
|
.run(network, monero_daemon_host.as_str())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let monero_wallet = monero::Wallet::new(
|
let monero_wallet = monero::Wallet::new(
|
||||||
monero_wallet_rpc_process.endpoint(),
|
monero_wallet_rpc_process.endpoint(),
|
||||||
monero_network,
|
|
||||||
MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME.to_string(),
|
MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME.to_string(),
|
||||||
execution_params.monero_avg_block_time,
|
exec_params,
|
||||||
);
|
);
|
||||||
|
|
||||||
monero_wallet.open_or_create().await?;
|
monero_wallet.open_or_create().await?;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::bitcoin::timelocks::BlockHeight;
|
use crate::bitcoin::timelocks::BlockHeight;
|
||||||
use crate::bitcoin::{Address, Amount, Transaction};
|
use crate::bitcoin::{Address, Amount, Transaction};
|
||||||
|
use crate::execution_params::ExecutionParams;
|
||||||
use ::bitcoin::util::psbt::PartiallySignedTransaction;
|
use ::bitcoin::util::psbt::PartiallySignedTransaction;
|
||||||
use ::bitcoin::Txid;
|
use ::bitcoin::Txid;
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
@ -24,16 +25,15 @@ const SLED_TREE_NAME: &str = "default_tree";
|
|||||||
pub struct Wallet {
|
pub struct Wallet {
|
||||||
client: Arc<Mutex<Client>>,
|
client: Arc<Mutex<Client>>,
|
||||||
wallet: Arc<Mutex<bdk::Wallet<ElectrumBlockchain, bdk::sled::Tree>>>,
|
wallet: Arc<Mutex<bdk::Wallet<ElectrumBlockchain, bdk::sled::Tree>>>,
|
||||||
bitcoin_finality_confirmations: u32,
|
finality_confirmations: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Wallet {
|
impl Wallet {
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
electrum_rpc_url: Url,
|
electrum_rpc_url: Url,
|
||||||
network: bitcoin::Network,
|
|
||||||
bitcoin_finality_confirmations: u32,
|
|
||||||
wallet_dir: &Path,
|
wallet_dir: &Path,
|
||||||
key: impl DerivableKey<Segwitv0> + Clone,
|
key: impl DerivableKey<Segwitv0> + Clone,
|
||||||
|
exec_params: ExecutionParams,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
// Workaround for https://github.com/bitcoindevkit/rust-electrum-client/issues/47.
|
// Workaround for https://github.com/bitcoindevkit/rust-electrum-client/issues/47.
|
||||||
let config = electrum_client::ConfigBuilder::default().retry(2).build();
|
let config = electrum_client::ConfigBuilder::default().retry(2).build();
|
||||||
@ -47,7 +47,7 @@ impl Wallet {
|
|||||||
let bdk_wallet = bdk::Wallet::new(
|
let bdk_wallet = bdk::Wallet::new(
|
||||||
bdk::template::BIP84(key.clone(), KeychainKind::External),
|
bdk::template::BIP84(key.clone(), KeychainKind::External),
|
||||||
Some(bdk::template::BIP84(key, KeychainKind::Internal)),
|
Some(bdk::template::BIP84(key, KeychainKind::Internal)),
|
||||||
network,
|
exec_params.bitcoin_network,
|
||||||
db,
|
db,
|
||||||
ElectrumBlockchain::from(client),
|
ElectrumBlockchain::from(client),
|
||||||
)?;
|
)?;
|
||||||
@ -60,7 +60,7 @@ impl Wallet {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
wallet: Arc::new(Mutex::new(bdk_wallet)),
|
wallet: Arc::new(Mutex::new(bdk_wallet)),
|
||||||
client: Arc::new(Mutex::new(Client::new(electrum, interval)?)),
|
client: Arc::new(Mutex::new(Client::new(electrum, interval)?)),
|
||||||
bitcoin_finality_confirmations,
|
finality_confirmations: exec_params.bitcoin_finality_confirmations,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ impl Wallet {
|
|||||||
where
|
where
|
||||||
T: Watchable,
|
T: Watchable,
|
||||||
{
|
{
|
||||||
let conf_target = self.bitcoin_finality_confirmations;
|
let conf_target = self.finality_confirmations;
|
||||||
let txid = tx.id();
|
let txid = tx.id();
|
||||||
|
|
||||||
tracing::info!(%txid, "Waiting for {} confirmation{} of Bitcoin {} transaction", conf_target, if conf_target > 1 { "s" } else { "" }, kind);
|
tracing::info!(%txid, "Waiting for {} confirmation{} of Bitcoin {} transaction", conf_target, if conf_target > 1 { "s" } else { "" }, kind);
|
||||||
|
@ -9,8 +9,10 @@ pub struct ExecutionParams {
|
|||||||
pub bitcoin_avg_block_time: Duration,
|
pub bitcoin_avg_block_time: Duration,
|
||||||
pub bitcoin_cancel_timelock: CancelTimelock,
|
pub bitcoin_cancel_timelock: CancelTimelock,
|
||||||
pub bitcoin_punish_timelock: PunishTimelock,
|
pub bitcoin_punish_timelock: PunishTimelock,
|
||||||
|
pub bitcoin_network: bitcoin::Network,
|
||||||
pub monero_avg_block_time: Duration,
|
pub monero_avg_block_time: Duration,
|
||||||
pub monero_finality_confirmations: u32,
|
pub monero_finality_confirmations: u32,
|
||||||
|
pub monero_network: monero::Network,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GetExecutionParams {
|
pub trait GetExecutionParams {
|
||||||
@ -34,8 +36,10 @@ impl GetExecutionParams for Mainnet {
|
|||||||
bitcoin_avg_block_time: 10.minutes(),
|
bitcoin_avg_block_time: 10.minutes(),
|
||||||
bitcoin_cancel_timelock: CancelTimelock::new(72),
|
bitcoin_cancel_timelock: CancelTimelock::new(72),
|
||||||
bitcoin_punish_timelock: PunishTimelock::new(72),
|
bitcoin_punish_timelock: PunishTimelock::new(72),
|
||||||
|
bitcoin_network: bitcoin::Network::Bitcoin,
|
||||||
monero_avg_block_time: 2.minutes(),
|
monero_avg_block_time: 2.minutes(),
|
||||||
monero_finality_confirmations: 15,
|
monero_finality_confirmations: 15,
|
||||||
|
monero_network: monero::Network::Mainnet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,8 +52,10 @@ impl GetExecutionParams for Testnet {
|
|||||||
bitcoin_avg_block_time: 5.minutes(),
|
bitcoin_avg_block_time: 5.minutes(),
|
||||||
bitcoin_cancel_timelock: CancelTimelock::new(12),
|
bitcoin_cancel_timelock: CancelTimelock::new(12),
|
||||||
bitcoin_punish_timelock: PunishTimelock::new(6),
|
bitcoin_punish_timelock: PunishTimelock::new(6),
|
||||||
|
bitcoin_network: bitcoin::Network::Testnet,
|
||||||
monero_avg_block_time: 2.minutes(),
|
monero_avg_block_time: 2.minutes(),
|
||||||
monero_finality_confirmations: 10,
|
monero_finality_confirmations: 10,
|
||||||
|
monero_network: monero::Network::Stagenet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,8 +68,10 @@ impl GetExecutionParams for Regtest {
|
|||||||
bitcoin_avg_block_time: 5.seconds(),
|
bitcoin_avg_block_time: 5.seconds(),
|
||||||
bitcoin_cancel_timelock: CancelTimelock::new(100),
|
bitcoin_cancel_timelock: CancelTimelock::new(100),
|
||||||
bitcoin_punish_timelock: PunishTimelock::new(50),
|
bitcoin_punish_timelock: PunishTimelock::new(50),
|
||||||
|
bitcoin_network: bitcoin::Network::Regtest,
|
||||||
monero_avg_block_time: 1.seconds(),
|
monero_avg_block_time: 1.seconds(),
|
||||||
monero_finality_confirmations: 10,
|
monero_finality_confirmations: 10,
|
||||||
|
monero_network: monero::Network::Testnet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
use crate::execution_params::ExecutionParams;
|
||||||
use crate::monero::{
|
use crate::monero::{
|
||||||
Amount, InsufficientFunds, PrivateViewKey, PublicViewKey, TransferProof, TxHash,
|
Amount, InsufficientFunds, PrivateViewKey, PublicViewKey, TransferProof, TxHash,
|
||||||
};
|
};
|
||||||
use ::monero::{Address, Network, PrivateKey, PublicKey};
|
use ::monero::{Address, Network, PrivateKey, PublicKey};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use monero_rpc::wallet;
|
use monero_rpc::wallet;
|
||||||
use monero_rpc::wallet::{BlockHeight, CheckTxKey, Refreshed};
|
use monero_rpc::wallet::{BlockHeight, CheckTxKey, Client, Refreshed};
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -23,26 +24,20 @@ pub struct Wallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Wallet {
|
impl Wallet {
|
||||||
pub fn new(url: Url, network: Network, name: String, avg_block_time: Duration) -> Self {
|
pub fn new(url: Url, name: String, exec_params: ExecutionParams) -> Self {
|
||||||
Self {
|
Self::new_with_client(Client::new(url), name, exec_params)
|
||||||
inner: Mutex::new(wallet::Client::new(url)),
|
|
||||||
network,
|
|
||||||
name,
|
|
||||||
avg_block_time,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_client(
|
pub fn new_with_client(
|
||||||
client: wallet::Client,
|
client: wallet::Client,
|
||||||
network: Network,
|
|
||||||
name: String,
|
name: String,
|
||||||
avg_block_time: Duration,
|
exec_params: ExecutionParams,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: Mutex::new(client),
|
inner: Mutex::new(client),
|
||||||
network,
|
network: exec_params.monero_network,
|
||||||
name,
|
name,
|
||||||
avg_block_time,
|
avg_block_time: exec_params.monero_avg_block_time,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ pub struct Swap {
|
|||||||
pub event_loop_handle: EventLoopHandle,
|
pub event_loop_handle: EventLoopHandle,
|
||||||
pub bitcoin_wallet: Arc<bitcoin::Wallet>,
|
pub bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
pub monero_wallet: Arc<monero::Wallet>,
|
pub monero_wallet: Arc<monero::Wallet>,
|
||||||
pub execution_params: ExecutionParams,
|
pub exec_params: ExecutionParams,
|
||||||
pub swap_id: Uuid,
|
pub swap_id: Uuid,
|
||||||
pub db: Arc<Database>,
|
pub db: Arc<Database>,
|
||||||
}
|
}
|
||||||
|
@ -206,11 +206,11 @@ impl Behaviour {
|
|||||||
peer: PeerId,
|
peer: PeerId,
|
||||||
btc: bitcoin::Amount,
|
btc: bitcoin::Amount,
|
||||||
xmr: monero::Amount,
|
xmr: monero::Amount,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
bitcoin_wallet: &bitcoin::Wallet,
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
rng: &mut (impl RngCore + CryptoRng),
|
rng: &mut (impl RngCore + CryptoRng),
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let state0 = State0::new(btc, xmr, execution_params, bitcoin_wallet, rng).await?;
|
let state0 = State0::new(btc, xmr, exec_params, bitcoin_wallet, rng).await?;
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
%peer,
|
%peer,
|
||||||
|
@ -23,7 +23,7 @@ use uuid::Uuid;
|
|||||||
pub struct EventLoop<RS> {
|
pub struct EventLoop<RS> {
|
||||||
swarm: libp2p::Swarm<Behaviour>,
|
swarm: libp2p::Swarm<Behaviour>,
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
db: Arc<Database>,
|
db: Arc<Database>,
|
||||||
@ -53,7 +53,7 @@ where
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
listen_address: Multiaddr,
|
listen_address: Multiaddr,
|
||||||
seed: Seed,
|
seed: Seed,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
db: Arc<Database>,
|
db: Arc<Database>,
|
||||||
@ -81,7 +81,7 @@ where
|
|||||||
let event_loop = EventLoop {
|
let event_loop = EventLoop {
|
||||||
swarm,
|
swarm,
|
||||||
peer_id,
|
peer_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
db,
|
db,
|
||||||
@ -133,7 +133,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.swarm.start_execution_setup(peer, btc, xmr, self.execution_params, self.bitcoin_wallet.as_ref(), &mut OsRng).await {
|
match self.swarm.start_execution_setup(peer, btc, xmr, self.exec_params, self.bitcoin_wallet.as_ref(), &mut OsRng).await {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::warn!(%peer, "failed to start execution setup: {:#}", e);
|
tracing::warn!(%peer, "failed to start execution setup: {:#}", e);
|
||||||
@ -241,7 +241,7 @@ where
|
|||||||
event_loop_handle: handle,
|
event_loop_handle: handle,
|
||||||
bitcoin_wallet: self.bitcoin_wallet.clone(),
|
bitcoin_wallet: self.bitcoin_wallet.clone(),
|
||||||
monero_wallet: self.monero_wallet.clone(),
|
monero_wallet: self.monero_wallet.clone(),
|
||||||
execution_params: self.execution_params,
|
exec_params: self.exec_params,
|
||||||
db: self.db.clone(),
|
db: self.db.clone(),
|
||||||
state: initial_state,
|
state: initial_state,
|
||||||
swap_id,
|
swap_id,
|
||||||
|
@ -96,7 +96,7 @@ impl State0 {
|
|||||||
pub async fn new<R>(
|
pub async fn new<R>(
|
||||||
btc: bitcoin::Amount,
|
btc: bitcoin::Amount,
|
||||||
xmr: monero::Amount,
|
xmr: monero::Amount,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
bitcoin_wallet: &bitcoin::Wallet,
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
) -> Result<Self>
|
) -> Result<Self>
|
||||||
@ -124,8 +124,8 @@ impl State0 {
|
|||||||
punish_address,
|
punish_address,
|
||||||
btc,
|
btc,
|
||||||
xmr,
|
xmr,
|
||||||
cancel_timelock: execution_params.bitcoin_cancel_timelock,
|
cancel_timelock: exec_params.bitcoin_cancel_timelock,
|
||||||
punish_timelock: execution_params.bitcoin_punish_timelock,
|
punish_timelock: exec_params.bitcoin_punish_timelock,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ pub async fn run_until(
|
|||||||
swap.event_loop_handle,
|
swap.event_loop_handle,
|
||||||
swap.bitcoin_wallet,
|
swap.bitcoin_wallet,
|
||||||
swap.monero_wallet,
|
swap.monero_wallet,
|
||||||
swap.execution_params,
|
swap.exec_params,
|
||||||
swap.swap_id,
|
swap.swap_id,
|
||||||
swap.db,
|
swap.db,
|
||||||
)
|
)
|
||||||
@ -67,7 +67,7 @@ async fn run_until_internal(
|
|||||||
mut event_loop_handle: EventLoopHandle,
|
mut event_loop_handle: EventLoopHandle,
|
||||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
db: Arc<Database>,
|
db: Arc<Database>,
|
||||||
) -> Result<AliceState> {
|
) -> Result<AliceState> {
|
||||||
@ -81,7 +81,7 @@ async fn run_until_internal(
|
|||||||
bob_peer_id,
|
bob_peer_id,
|
||||||
} => {
|
} => {
|
||||||
timeout(
|
timeout(
|
||||||
execution_params.bob_time_to_act,
|
exec_params.bob_time_to_act,
|
||||||
bitcoin_wallet
|
bitcoin_wallet
|
||||||
.watch_until_status(&state3.tx_lock, |status| status.has_been_seen()),
|
.watch_until_status(&state3.tx_lock, |status| status.has_been_seen()),
|
||||||
)
|
)
|
||||||
@ -90,7 +90,7 @@ async fn run_until_internal(
|
|||||||
|
|
||||||
bitcoin_wallet
|
bitcoin_wallet
|
||||||
.watch_until_status(&state3.tx_lock, |status| {
|
.watch_until_status(&state3.tx_lock, |status| {
|
||||||
status.is_confirmed_with(execution_params.bitcoin_finality_confirmations)
|
status.is_confirmed_with(exec_params.bitcoin_finality_confirmations)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
@ -144,7 +144,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
@ -192,7 +192,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
@ -258,7 +258,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
@ -291,7 +291,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
@ -326,7 +326,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
@ -355,7 +355,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
@ -432,7 +432,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
@ -452,7 +452,7 @@ async fn run_until_internal(
|
|||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
execution_params,
|
exec_params,
|
||||||
swap_id,
|
swap_id,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
|
@ -37,7 +37,7 @@ pub struct Swap {
|
|||||||
pub db: Database,
|
pub db: Database,
|
||||||
pub bitcoin_wallet: Arc<bitcoin::Wallet>,
|
pub bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
pub monero_wallet: Arc<monero::Wallet>,
|
pub monero_wallet: Arc<monero::Wallet>,
|
||||||
pub execution_params: ExecutionParams,
|
pub exec_params: ExecutionParams,
|
||||||
pub swap_id: Uuid,
|
pub swap_id: Uuid,
|
||||||
pub receive_monero_address: ::monero::Address,
|
pub receive_monero_address: ::monero::Address,
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ pub struct Builder {
|
|||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
|
|
||||||
init_params: InitParams,
|
init_params: InitParams,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
|
|
||||||
event_loop_handle: EventLoopHandle,
|
event_loop_handle: EventLoopHandle,
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ impl Builder {
|
|||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
event_loop_handle: EventLoopHandle,
|
event_loop_handle: EventLoopHandle,
|
||||||
receive_monero_address: ::monero::Address,
|
receive_monero_address: ::monero::Address,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -79,7 +79,7 @@ impl Builder {
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
init_params: InitParams::None,
|
init_params: InitParams::None,
|
||||||
execution_params,
|
exec_params,
|
||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ impl Builder {
|
|||||||
bitcoin_wallet: self.bitcoin_wallet.clone(),
|
bitcoin_wallet: self.bitcoin_wallet.clone(),
|
||||||
monero_wallet: self.monero_wallet.clone(),
|
monero_wallet: self.monero_wallet.clone(),
|
||||||
swap_id: self.swap_id,
|
swap_id: self.swap_id,
|
||||||
execution_params: self.execution_params,
|
exec_params: self.exec_params,
|
||||||
receive_monero_address: self.receive_monero_address,
|
receive_monero_address: self.receive_monero_address,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ pub async fn run_until(
|
|||||||
swap.bitcoin_wallet,
|
swap.bitcoin_wallet,
|
||||||
swap.monero_wallet,
|
swap.monero_wallet,
|
||||||
swap.swap_id,
|
swap.swap_id,
|
||||||
swap.execution_params,
|
swap.exec_params,
|
||||||
swap.receive_monero_address,
|
swap.receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -58,7 +58,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
receive_monero_address: monero::Address,
|
receive_monero_address: monero::Address,
|
||||||
) -> Result<BobState> {
|
) -> Result<BobState> {
|
||||||
trace!("Current state: {}", state);
|
trace!("Current state: {}", state);
|
||||||
@ -74,7 +74,7 @@ async fn run_until_internal(
|
|||||||
let state2 = request_price_and_setup(
|
let state2 = request_price_and_setup(
|
||||||
btc_amount,
|
btc_amount,
|
||||||
&mut event_loop_handle,
|
&mut event_loop_handle,
|
||||||
execution_params,
|
exec_params,
|
||||||
bitcoin_refund_address,
|
bitcoin_refund_address,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@ -90,7 +90,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -121,7 +121,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -177,7 +177,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -232,7 +232,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -275,7 +275,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -311,7 +311,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -342,7 +342,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -368,7 +368,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -398,7 +398,7 @@ async fn run_until_internal(
|
|||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
swap_id,
|
swap_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
receive_monero_address,
|
receive_monero_address,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -414,7 +414,7 @@ async fn run_until_internal(
|
|||||||
pub async fn request_price_and_setup(
|
pub async fn request_price_and_setup(
|
||||||
btc: bitcoin::Amount,
|
btc: bitcoin::Amount,
|
||||||
event_loop_handle: &mut EventLoopHandle,
|
event_loop_handle: &mut EventLoopHandle,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
bitcoin_refund_address: bitcoin::Address,
|
bitcoin_refund_address: bitcoin::Address,
|
||||||
) -> Result<bob::state::State2> {
|
) -> Result<bob::state::State2> {
|
||||||
let xmr = event_loop_handle.request_spot_price(btc).await?;
|
let xmr = event_loop_handle.request_spot_price(btc).await?;
|
||||||
@ -425,10 +425,10 @@ pub async fn request_price_and_setup(
|
|||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
btc,
|
btc,
|
||||||
xmr,
|
xmr,
|
||||||
execution_params.bitcoin_cancel_timelock,
|
exec_params.bitcoin_cancel_timelock,
|
||||||
execution_params.bitcoin_punish_timelock,
|
exec_params.bitcoin_punish_timelock,
|
||||||
bitcoin_refund_address,
|
bitcoin_refund_address,
|
||||||
execution_params.monero_finality_confirmations,
|
exec_params.monero_finality_confirmations,
|
||||||
);
|
);
|
||||||
|
|
||||||
let state2 = event_loop_handle.execution_setup(state0).await?;
|
let state2 = event_loop_handle.execution_setup(state0).await?;
|
||||||
|
@ -52,7 +52,7 @@ struct BobParams {
|
|||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
alice_address: Multiaddr,
|
alice_address: Multiaddr,
|
||||||
alice_peer_id: PeerId,
|
alice_peer_id: PeerId,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BobParams {
|
impl BobParams {
|
||||||
@ -64,7 +64,7 @@ impl BobParams {
|
|||||||
self.swap_id,
|
self.swap_id,
|
||||||
self.bitcoin_wallet.clone(),
|
self.bitcoin_wallet.clone(),
|
||||||
self.monero_wallet.clone(),
|
self.monero_wallet.clone(),
|
||||||
self.execution_params,
|
self.exec_params,
|
||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
receive_address,
|
receive_address,
|
||||||
))
|
))
|
||||||
@ -317,7 +317,7 @@ where
|
|||||||
|
|
||||||
let _guard = init_tracing();
|
let _guard = init_tracing();
|
||||||
|
|
||||||
let execution_params = C::get_execution_params();
|
let exec_params = C::get_execution_params();
|
||||||
|
|
||||||
let (monero, containers) = testutils::init_containers(&cli).await;
|
let (monero, containers) = testutils::init_containers(&cli).await;
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ where
|
|||||||
tempdir().unwrap().path(),
|
tempdir().unwrap().path(),
|
||||||
electrs_rpc_port,
|
electrs_rpc_port,
|
||||||
alice_seed,
|
alice_seed,
|
||||||
execution_params,
|
exec_params,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -373,14 +373,14 @@ where
|
|||||||
tempdir().unwrap().path(),
|
tempdir().unwrap().path(),
|
||||||
electrs_rpc_port,
|
electrs_rpc_port,
|
||||||
bob_seed,
|
bob_seed,
|
||||||
execution_params,
|
exec_params,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let (alice_event_loop, alice_swap_handle) = alice::EventLoop::new(
|
let (alice_event_loop, alice_swap_handle) = alice::EventLoop::new(
|
||||||
alice_listen_address.clone(),
|
alice_listen_address.clone(),
|
||||||
alice_seed,
|
alice_seed,
|
||||||
execution_params,
|
exec_params,
|
||||||
alice_bitcoin_wallet.clone(),
|
alice_bitcoin_wallet.clone(),
|
||||||
alice_monero_wallet.clone(),
|
alice_monero_wallet.clone(),
|
||||||
alice_db,
|
alice_db,
|
||||||
@ -401,7 +401,7 @@ where
|
|||||||
monero_wallet: bob_monero_wallet.clone(),
|
monero_wallet: bob_monero_wallet.clone(),
|
||||||
alice_address: alice_listen_address,
|
alice_address: alice_listen_address,
|
||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
execution_params,
|
exec_params,
|
||||||
};
|
};
|
||||||
|
|
||||||
let test = TestContext {
|
let test = TestContext {
|
||||||
@ -580,7 +580,7 @@ async fn init_test_wallets(
|
|||||||
datadir: &Path,
|
datadir: &Path,
|
||||||
electrum_rpc_port: u16,
|
electrum_rpc_port: u16,
|
||||||
seed: Seed,
|
seed: Seed,
|
||||||
execution_params: ExecutionParams,
|
exec_params: ExecutionParams,
|
||||||
) -> (Arc<bitcoin::Wallet>, Arc<monero::Wallet>) {
|
) -> (Arc<bitcoin::Wallet>, Arc<monero::Wallet>) {
|
||||||
monero
|
monero
|
||||||
.init(vec![(name, starting_balances.xmr.as_piconero())])
|
.init(vec![(name, starting_balances.xmr.as_piconero())])
|
||||||
@ -589,9 +589,8 @@ async fn init_test_wallets(
|
|||||||
|
|
||||||
let xmr_wallet = swap::monero::Wallet::new_with_client(
|
let xmr_wallet = swap::monero::Wallet::new_with_client(
|
||||||
monero.wallet(name).unwrap().client(),
|
monero.wallet(name).unwrap().client(),
|
||||||
monero::Network::default(),
|
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
execution_params.monero_avg_block_time,
|
exec_params,
|
||||||
);
|
);
|
||||||
|
|
||||||
let electrum_rpc_url = {
|
let electrum_rpc_url = {
|
||||||
@ -601,11 +600,10 @@ async fn init_test_wallets(
|
|||||||
|
|
||||||
let btc_wallet = swap::bitcoin::Wallet::new(
|
let btc_wallet = swap::bitcoin::Wallet::new(
|
||||||
electrum_rpc_url,
|
electrum_rpc_url,
|
||||||
bitcoin::Network::Regtest,
|
|
||||||
execution_params.bitcoin_finality_confirmations,
|
|
||||||
datadir,
|
datadir,
|
||||||
seed.derive_extended_private_key(bitcoin::Network::Regtest)
|
seed.derive_extended_private_key(exec_params.bitcoin_network)
|
||||||
.expect("Could not create extended private key from seed"),
|
.expect("Could not create extended private key from seed"),
|
||||||
|
exec_params,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("could not init btc wallet");
|
.expect("could not init btc wallet");
|
||||||
|
Loading…
Reference in New Issue
Block a user