Use unwrap_or_else

As directed by clippy use `unwrap_or_else` in order to take advantage of
lazy evaluation.
This commit is contained in:
Tobin Harding 2020-12-21 20:08:24 +11:00
parent 4ad0f54c30
commit 5eaa3b0916
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607

View File

@ -60,13 +60,13 @@ fn get_auth() -> Auth {
), ),
_ => Auth::CookieFile(PathBuf::from( _ => Auth::CookieFile(PathBuf::from(
env::var("BDK_RPC_COOKIEFILE") env::var("BDK_RPC_COOKIEFILE")
.unwrap_or("/home/user/.bitcoin/regtest/.cookie".to_string()), .unwrap_or_else(|_| "/home/user/.bitcoin/regtest/.cookie".to_string()),
)), )),
} }
} }
pub fn get_electrum_url() -> String { pub fn get_electrum_url() -> String {
env::var("BDK_ELECTRUM_URL").unwrap_or("tcp://127.0.0.1:50001".to_string()) env::var("BDK_ELECTRUM_URL").unwrap_or_else(|_| "tcp://127.0.0.1:50001".to_string())
} }
pub struct TestClient { pub struct TestClient {
@ -311,8 +311,8 @@ where
impl TestClient { impl TestClient {
pub fn new() -> Self { pub fn new() -> Self {
let url = env::var("BDK_RPC_URL").unwrap_or("127.0.0.1:18443".to_string()); let url = env::var("BDK_RPC_URL").unwrap_or_else(|_| "127.0.0.1:18443".to_string());
let wallet = env::var("BDK_RPC_WALLET").unwrap_or("bdk-test".to_string()); let wallet = env::var("BDK_RPC_WALLET").unwrap_or_else(|_| "bdk-test".to_string());
let client = let client =
RpcClient::new(format!("http://{}/wallet/{}", url, wallet), get_auth()).unwrap(); RpcClient::new(format!("http://{}/wallet/{}", url, wallet), get_auth()).unwrap();
let electrum = ElectrumClient::new(&get_electrum_url()).unwrap(); let electrum = ElectrumClient::new(&get_electrum_url()).unwrap();