From 00388c7c819eda0e6b08dceb5689d13b3a4ccde1 Mon Sep 17 00:00:00 2001 From: Divyansh Gupta Date: Sat, 7 Sep 2024 21:54:04 +0530 Subject: [PATCH] take TakerConfig from struct instead of having parameter for it. --- src/bin/taker.rs | 11 +---------- src/taker/api.rs | 18 ++++++------------ 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/bin/taker.rs b/src/bin/taker.rs index d5064744..cec27ab1 100644 --- a/src/bin/taker.rs +++ b/src/bin/taker.rs @@ -169,16 +169,7 @@ fn main() { println!("{:?}", address); } Commands::SyncOfferBook => { - let taker2 = Taker::init( - args.data_directory, - Some(args.wallet_name), - Some(rpc_config), - TakerBehavior::Normal, - Some(connection_type), - ) - .unwrap(); - let config = taker2.config.clone(); - taker.sync_offerbook(&config, args.maker_count).unwrap(); + taker.sync_offerbook(args.maker_count).unwrap(); } Commands::DoCoinswap => { taker.do_coinswap(swap_params).unwrap(); diff --git a/src/taker/api.rs b/src/taker/api.rs index 0ff3badd..61f62b1f 100644 --- a/src/taker/api.rs +++ b/src/taker/api.rs @@ -299,9 +299,7 @@ impl Taker { /// If that fails too. Open an issue at [our github](https://github.com/citadel-tech/coinswap/issues) pub fn send_coinswap(&mut self, swap_params: SwapParams) -> Result<(), TakerError> { log::info!("Syncing Offerbook"); - let config = self.config.clone(); - self.sync_offerbook(&config, swap_params.maker_count)?; - + self.sync_offerbook(swap_params.maker_count)?; // Generate new random preimage and initiate the first hop. let mut preimage = [0u8; 32]; OsRng.fill_bytes(&mut preimage); @@ -1909,21 +1907,17 @@ impl Taker { } /// Synchronizes the offer book with addresses obtained from directory servers and local configurations. - pub fn sync_offerbook( - &mut self, - config: &TakerConfig, - maker_count: usize, - ) -> Result<(), TakerError> { + pub fn sync_offerbook(&mut self, maker_count: usize) -> Result<(), TakerError> { let directory_address = match self.config.connection_type { ConnectionType::CLEARNET => { - let mut address = config.directory_server_clearnet_address.clone(); + let mut address = self.config.directory_server_clearnet_address.clone(); if cfg!(feature = "integration-test") { address = format!("127.0.0.1:{}", 8080); } address } ConnectionType::TOR => { - let mut address = config.directory_server_onion_address.clone(); + let mut address = self.config.directory_server_onion_address.clone(); if cfg!(feature = "integration-test") { let directory_hs_path_str = "/tmp/tor-rust-directory/hs-dir/hostname".to_string(); @@ -1951,9 +1945,9 @@ impl Taker { socks_port, directory_address, maker_count, - config.connection_type, + self.config.connection_type, )?; - let offers = fetch_offer_from_makers(addresses_from_dns, config); + let offers = fetch_offer_from_makers(addresses_from_dns, &self.config); let new_offers = offers .into_iter()