Delay the wrapping in Arc

This commit is contained in:
Franck Royer 2021-01-20 13:36:38 +11:00
parent 83b72c0a45
commit c44b867d01
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 14 additions and 16 deletions

View File

@ -86,8 +86,8 @@ async fn main() -> Result<()> {
seed, seed,
config, config,
swap_id, swap_id,
bitcoin_wallet, Arc::new(bitcoin_wallet),
monero_wallet, Arc::new(monero_wallet),
db_path, db_path,
listen_addr, listen_addr,
) )
@ -131,8 +131,8 @@ async fn main() -> Result<()> {
seed, seed,
db_path, db_path,
swap_id, swap_id,
bitcoin_wallet, Arc::new(bitcoin_wallet),
monero_wallet, Arc::new(monero_wallet),
alice_addr, alice_addr,
alice_peer_id, alice_peer_id,
); );
@ -177,8 +177,8 @@ async fn main() -> Result<()> {
seed, seed,
config, config,
swap_id, swap_id,
bitcoin_wallet, Arc::new(bitcoin_wallet),
monero_wallet, Arc::new(monero_wallet),
db_path, db_path,
listen_addr, listen_addr,
) )
@ -208,8 +208,8 @@ async fn main() -> Result<()> {
seed, seed,
db_path, db_path,
swap_id, swap_id,
bitcoin_wallet, Arc::new(bitcoin_wallet),
monero_wallet, Arc::new(monero_wallet),
alice_addr, alice_addr,
alice_peer_id, alice_peer_id,
); );
@ -228,7 +228,7 @@ async fn setup_wallets(
bitcoin_wallet_name: &str, bitcoin_wallet_name: &str,
monero_wallet_rpc_url: url::Url, monero_wallet_rpc_url: url::Url,
config: Config, config: Config,
) -> Result<(Arc<swap::bitcoin::Wallet>, Arc<swap::monero::Wallet>)> { ) -> Result<(swap::bitcoin::Wallet, swap::monero::Wallet)> {
let bitcoin_wallet = let bitcoin_wallet =
swap::bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network) swap::bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network)
.await?; .await?;
@ -237,7 +237,6 @@ async fn setup_wallets(
"Connection to Bitcoin wallet succeeded, balance: {}", "Connection to Bitcoin wallet succeeded, balance: {}",
bitcoin_balance bitcoin_balance
); );
let bitcoin_wallet = Arc::new(bitcoin_wallet);
let monero_wallet = monero::Wallet::new(monero_wallet_rpc_url, config.monero_network); let monero_wallet = monero::Wallet::new(monero_wallet_rpc_url, config.monero_network);
let monero_balance = monero_wallet.get_balance().await?; let monero_balance = monero_wallet.get_balance().await?;
@ -245,7 +244,6 @@ async fn setup_wallets(
"Connection to Monero wallet succeeded, balance: {}", "Connection to Monero wallet succeeded, balance: {}",
monero_balance monero_balance
); );
let monero_wallet = Arc::new(monero_wallet);
Ok((bitcoin_wallet, monero_wallet)) Ok((bitcoin_wallet, monero_wallet))
} }

View File

@ -118,8 +118,8 @@ impl Builder {
Ok(( Ok((
Swap { Swap {
event_loop_handle, event_loop_handle,
bitcoin_wallet: self.bitcoin_wallet.clone(), bitcoin_wallet: self.bitcoin_wallet,
monero_wallet: self.monero_wallet.clone(), monero_wallet: self.monero_wallet,
config: self.config, config: self.config,
db, db,
state: initial_state, state: initial_state,
@ -148,8 +148,8 @@ impl Builder {
Swap { Swap {
state: resume_state, state: resume_state,
event_loop_handle, event_loop_handle,
bitcoin_wallet: self.bitcoin_wallet.clone(), bitcoin_wallet: self.bitcoin_wallet,
monero_wallet: self.monero_wallet.clone(), monero_wallet: self.monero_wallet,
config: self.config, config: self.config,
swap_id: self.swap_id, swap_id: self.swap_id,
db, db,
@ -183,7 +183,7 @@ impl Builder {
let a = bitcoin::SecretKey::new_random(rng); let a = bitcoin::SecretKey::new_random(rng);
let s_a = cross_curve_dleq::Scalar::random(rng); let s_a = cross_curve_dleq::Scalar::random(rng);
let v_a = monero::PrivateViewKey::new_random(rng); let v_a = monero::PrivateViewKey::new_random(rng);
let redeem_address = self.bitcoin_wallet.as_ref().new_address().await?; let redeem_address = self.bitcoin_wallet.new_address().await?;
let punish_address = redeem_address.clone(); let punish_address = redeem_address.clone();
let state0 = State0::new( let state0 = State0::new(
a, a,