From a0da414bca3d9bc43aac8baaeaa7975ae008bf7f Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Mon, 2 Dec 2019 15:16:04 -0800 Subject: [PATCH] fix deadlock while adding new addresses --- lib/src/lightclient.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 01b32e4..2177a81 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -827,15 +827,17 @@ impl LightClient { return Err("Wallet is locked".to_string()); } - let wallet = self.wallet.write().unwrap(); - - let new_address = match addr_type { - "z" => wallet.add_zaddr(), - "t" => wallet.add_taddr(), - _ => { - let e = format!("Unrecognized address type: {}", addr_type); - error!("{}", e); - return Err(e); + let new_address = { + let wallet = self.wallet.write().unwrap(); + + match addr_type { + "z" => wallet.add_zaddr(), + "t" => wallet.add_taddr(), + _ => { + let e = format!("Unrecognized address type: {}", addr_type); + error!("{}", e); + return Err(e); + } } };