mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Remove unecessary fields from bob::SwapFactory
This commit is contained in:
parent
3c68026cfe
commit
e26629b593
@ -112,7 +112,7 @@ async fn main() -> Result<()> {
|
||||
xmr: receive_monero,
|
||||
};
|
||||
|
||||
let (bitcoin_wallet, monero_wallet, starting_balances) = setup_wallets(
|
||||
let (bitcoin_wallet, monero_wallet, _starting_balances) = setup_wallets(
|
||||
bitcoind_url,
|
||||
bitcoin_wallet_name.as_str(),
|
||||
monero_wallet_rpc_url,
|
||||
@ -133,12 +133,10 @@ async fn main() -> Result<()> {
|
||||
swap_id,
|
||||
bitcoin_wallet,
|
||||
monero_wallet,
|
||||
config,
|
||||
starting_balances,
|
||||
alice_addr,
|
||||
alice_peer_id,
|
||||
);
|
||||
let (swap, event_loop) = bob_factory.new_swap_as_bob(swap_amounts).await?;
|
||||
let (swap, event_loop) = bob_factory.new_swap_as_bob(swap_amounts, config).await?;
|
||||
|
||||
tokio::spawn(async move { event_loop.run().await });
|
||||
bob::run(swap).await?;
|
||||
@ -196,7 +194,7 @@ async fn main() -> Result<()> {
|
||||
alice_peer_id,
|
||||
alice_addr,
|
||||
}) => {
|
||||
let (bitcoin_wallet, monero_wallet, starting_balances) = setup_wallets(
|
||||
let (bitcoin_wallet, monero_wallet, _starting_balances) = setup_wallets(
|
||||
bitcoind_url,
|
||||
bitcoin_wallet_name.as_str(),
|
||||
monero_wallet_rpc_url,
|
||||
@ -210,8 +208,6 @@ async fn main() -> Result<()> {
|
||||
swap_id,
|
||||
bitcoin_wallet,
|
||||
monero_wallet,
|
||||
config,
|
||||
starting_balances,
|
||||
alice_addr,
|
||||
alice_peer_id,
|
||||
);
|
||||
|
@ -55,26 +55,21 @@ pub struct SwapFactory {
|
||||
identity: Keypair,
|
||||
peer_id: PeerId,
|
||||
db_path: PathBuf,
|
||||
config: Config,
|
||||
|
||||
alice_connect_address: Multiaddr,
|
||||
alice_connect_peer_id: PeerId,
|
||||
|
||||
pub bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||
pub monero_wallet: Arc<monero::Wallet>,
|
||||
pub starting_balances: StartingBalances,
|
||||
}
|
||||
|
||||
impl SwapFactory {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
seed: Seed,
|
||||
db_path: PathBuf,
|
||||
swap_id: Uuid,
|
||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||
monero_wallet: Arc<monero::Wallet>,
|
||||
config: Config,
|
||||
starting_balances: StartingBalances,
|
||||
alice_connect_address: Multiaddr,
|
||||
alice_connect_peer_id: PeerId,
|
||||
) -> Self {
|
||||
@ -86,24 +81,23 @@ impl SwapFactory {
|
||||
identity,
|
||||
peer_id,
|
||||
db_path,
|
||||
config,
|
||||
alice_connect_address,
|
||||
alice_connect_peer_id,
|
||||
bitcoin_wallet,
|
||||
monero_wallet,
|
||||
starting_balances,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn new_swap_as_bob(
|
||||
&self,
|
||||
swap_amounts: SwapAmounts,
|
||||
config: Config,
|
||||
) -> Result<(bob::Swap, bob::EventLoop)> {
|
||||
let initial_state = init_bob_state(
|
||||
swap_amounts.btc,
|
||||
swap_amounts.xmr,
|
||||
self.bitcoin_wallet.clone(),
|
||||
self.config,
|
||||
config,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -21,9 +21,9 @@ use uuid::Uuid;
|
||||
|
||||
pub struct TestContext {
|
||||
swap_amounts: SwapAmounts,
|
||||
|
||||
alice_swap_factory: alice::SwapFactory,
|
||||
bob_swap_factory: bob::SwapFactory,
|
||||
bob_starting_balances: StartingBalances,
|
||||
}
|
||||
|
||||
impl TestContext {
|
||||
@ -42,7 +42,7 @@ impl TestContext {
|
||||
pub async fn new_swap_as_bob(&self) -> bob::Swap {
|
||||
let (swap, event_loop) = self
|
||||
.bob_swap_factory
|
||||
.new_swap_as_bob(self.swap_amounts)
|
||||
.new_swap_as_bob(self.swap_amounts, Config::regtest())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@ -185,9 +185,7 @@ impl TestContext {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
btc_balance_after_swap,
|
||||
self.bob_swap_factory.starting_balances.btc
|
||||
- self.swap_amounts.btc
|
||||
- lock_tx_bitcoin_fee
|
||||
self.bob_starting_balances.btc - self.swap_amounts.btc - lock_tx_bitcoin_fee
|
||||
);
|
||||
|
||||
// Ensure that Bob's balance is refreshed as we use a newly created wallet
|
||||
@ -207,7 +205,7 @@ impl TestContext {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
xmr_balance_after_swap,
|
||||
self.bob_swap_factory.starting_balances.xmr + self.swap_amounts.xmr
|
||||
self.bob_starting_balances.xmr + self.swap_amounts.xmr
|
||||
);
|
||||
}
|
||||
|
||||
@ -233,12 +231,12 @@ impl TestContext {
|
||||
.unwrap();
|
||||
|
||||
let alice_submitted_cancel = btc_balance_after_swap
|
||||
== self.bob_swap_factory.starting_balances.btc
|
||||
== self.bob_starting_balances.btc
|
||||
- lock_tx_bitcoin_fee
|
||||
- bitcoin::Amount::from_sat(bitcoin::TX_FEE);
|
||||
|
||||
let bob_submitted_cancel = btc_balance_after_swap
|
||||
== self.bob_swap_factory.starting_balances.btc
|
||||
== self.bob_starting_balances.btc
|
||||
- lock_tx_bitcoin_fee
|
||||
- bitcoin::Amount::from_sat(2 * bitcoin::TX_FEE);
|
||||
|
||||
@ -253,10 +251,7 @@ impl TestContext {
|
||||
.get_balance()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
xmr_balance_after_swap,
|
||||
self.bob_swap_factory.starting_balances.xmr
|
||||
);
|
||||
assert_eq!(xmr_balance_after_swap, self.bob_starting_balances.xmr);
|
||||
}
|
||||
|
||||
pub async fn assert_bob_punished(&self, state: BobState) {
|
||||
@ -282,9 +277,7 @@ impl TestContext {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
btc_balance_after_swap,
|
||||
self.bob_swap_factory.starting_balances.btc
|
||||
- self.swap_amounts.btc
|
||||
- lock_tx_bitcoin_fee
|
||||
self.bob_starting_balances.btc - self.swap_amounts.btc - lock_tx_bitcoin_fee
|
||||
);
|
||||
|
||||
let xmr_balance_after_swap = self
|
||||
@ -294,10 +287,7 @@ impl TestContext {
|
||||
.get_balance()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
xmr_balance_after_swap,
|
||||
self.bob_swap_factory.starting_balances.xmr
|
||||
);
|
||||
assert_eq!(xmr_balance_after_swap, self.bob_starting_balances.xmr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,8 +361,6 @@ where
|
||||
Uuid::new_v4(),
|
||||
bob_bitcoin_wallet,
|
||||
bob_monero_wallet,
|
||||
config,
|
||||
bob_starting_balances,
|
||||
alice_swap_factory.listen_address(),
|
||||
alice_swap_factory.peer_id(),
|
||||
);
|
||||
@ -381,6 +369,7 @@ where
|
||||
swap_amounts,
|
||||
alice_swap_factory,
|
||||
bob_swap_factory,
|
||||
bob_starting_balances,
|
||||
};
|
||||
|
||||
testfn(test).await
|
||||
|
Loading…
Reference in New Issue
Block a user