diff --git a/swap/src/alice.rs b/swap/src/alice.rs index 7149e06f..b394436c 100644 --- a/swap/src/alice.rs +++ b/swap/src/alice.rs @@ -47,8 +47,6 @@ pub async fn swap( monero_wallet: Arc, listen: Multiaddr, local_port: Option, - redeem_address: ::bitcoin::Address, - punish_address: ::bitcoin::Address, ) -> Result<()> { struct Network { swarm: Arc>, @@ -131,6 +129,9 @@ pub async fn swap( None => unreachable!("should have amounts by here"), }; + let redeem_address = bitcoin_wallet.as_ref().new_address().await?; + let punish_address = redeem_address.clone(); + // TODO: Pass this in using let rng = &mut OsRng; let state0 = State0::new( diff --git a/swap/src/bob.rs b/swap/src/bob.rs index 4194a7bd..2da7350c 100644 --- a/swap/src/bob.rs +++ b/swap/src/bob.rs @@ -46,7 +46,6 @@ pub async fn swap( addr: Multiaddr, mut cmd_tx: Sender, mut rsp_rx: Receiver, - refund_address: ::bitcoin::Address, ) -> Result<()> { struct Network(Swarm); @@ -106,6 +105,8 @@ pub async fn swap( other => panic!("unexpected event: {:?}", other), }; + let refund_address = bitcoin_wallet.new_address().await?; + // TODO: Pass this in using let rng = &mut OsRng; let state0 = State0::new( diff --git a/swap/src/main.rs b/swap/src/main.rs index 7c93159d..a813aa62 100644 --- a/swap/src/main.rs +++ b/swap/src/main.rs @@ -74,20 +74,11 @@ async fn main() -> Result<()> { let bitcoin_wallet = bitcoin::Wallet::new("alice", &url) .await .expect("failed to create bitcoin wallet"); + let bitcoin_wallet = Arc::new(bitcoin_wallet); let monero_wallet = Arc::new(monero::Wallet::localhost(MONERO_WALLET_RPC_PORT)); - let redeem = bitcoin_wallet - .new_address() - .await - .expect("failed to get new redeem address"); - let punish = bitcoin_wallet - .new_address() - .await - .expect("failed to get new punish address"); - - let bitcoin_wallet = Arc::new(bitcoin_wallet); - swap_as_alice(bitcoin_wallet, monero_wallet, alice.clone(), redeem, punish).await?; + swap_as_alice(bitcoin_wallet, monero_wallet, alice.clone()).await?; } else { info!("running swap node as Bob ..."); @@ -101,21 +92,16 @@ async fn main() -> Result<()> { let bitcoin_wallet = bitcoin::Wallet::new("bob", &url) .await .expect("failed to create bitcoin wallet"); + let bitcoin_wallet = Arc::new(bitcoin_wallet); let monero_wallet = Arc::new(monero::Wallet::localhost(MONERO_WALLET_RPC_PORT)); - let refund = bitcoin_wallet - .new_address() - .await - .expect("failed to get new address"); - - let bitcoin_wallet = Arc::new(bitcoin_wallet); match (opt.piconeros, opt.satoshis) { (Some(_), Some(_)) => bail!("Please supply only a single amount to swap"), (None, None) => bail!("Please supply an amount to swap"), (Some(_picos), _) => todo!("support starting with picos"), (None, Some(sats)) => { - swap_as_bob(bitcoin_wallet, monero_wallet, sats, alice, refund).await?; + swap_as_bob(bitcoin_wallet, monero_wallet, sats, alice).await?; } }; } @@ -145,24 +131,14 @@ async fn swap_as_alice( bitcoin_wallet: Arc, monero_wallet: Arc, addr: Multiaddr, - redeem: ::bitcoin::Address, - punish: ::bitcoin::Address, ) -> Result<()> { #[cfg(not(feature = "tor"))] { - alice::swap(bitcoin_wallet, monero_wallet, addr, None, redeem, punish).await + alice::swap(bitcoin_wallet, monero_wallet, addr, None).await } #[cfg(feature = "tor")] { - alice::swap( - bitcoin_wallet, - monero_wallet, - addr, - Some(PORT), - redeem, - punish, - ) - .await + alice::swap(bitcoin_wallet, monero_wallet, addr, Some(PORT)).await } } @@ -171,7 +147,6 @@ async fn swap_as_bob( monero_wallet: Arc, sats: u64, alice: Multiaddr, - refund: ::bitcoin::Address, ) -> Result<()> { let (cmd_tx, mut cmd_rx) = mpsc::channel(1); let (mut rsp_tx, rsp_rx) = mpsc::channel(1); @@ -182,7 +157,6 @@ async fn swap_as_bob( alice, cmd_tx, rsp_rx, - refund, )); loop {