diff --git a/mm2src/coins/utxo.rs b/mm2src/coins/utxo.rs index 2d69c7fcf4..ac935d2095 100644 --- a/mm2src/coins/utxo.rs +++ b/mm2src/coins/utxo.rs @@ -1241,8 +1241,10 @@ pub trait UtxoCoinBuilder { *p2sh_addr_prefix = self.p2sh_address_prefix(); } - if address_format.is_segwit() && !self.conf()["segwit"].as_bool().unwrap_or(false) { - ERR!("Cannot use Segwit address format for coin without segwit support") + if address_format.is_segwit() + && (!self.conf()["segwit"].as_bool().unwrap_or(false) || self.conf()["bech32_hrp"].is_null()) + { + ERR!("Cannot use Segwit address format for coin without segwit support or bech32_hrp in config") } else { Ok(address_format) } diff --git a/mm2src/coins/utxo/rpc_clients.rs b/mm2src/coins/utxo/rpc_clients.rs index 3ec076439c..750dbc7d6f 100644 --- a/mm2src/coins/utxo/rpc_clients.rs +++ b/mm2src/coins/utxo/rpc_clients.rs @@ -560,7 +560,10 @@ impl JsonRpcClient for NativeClientImpl { impl UtxoRpcClientOps for NativeClient { fn list_unspent(&self, address: &Address, decimals: u8) -> UtxoRpcFut> { let addresses = match address.addr_format { - UtxoAddressFormat::Segwit => vec![address.to_segwitaddress().unwrap().to_string()], + UtxoAddressFormat::Segwit => vec![address + .to_segwitaddress() + .expect("to_segwitaddress should not fail for UtxoAddressFormat::Segwit") + .to_string()], _ => vec![address.to_string()], }; let fut = self @@ -612,14 +615,18 @@ impl UtxoRpcClientOps for NativeClient { } fn display_balance(&self, address: Address, _decimals: u8) -> RpcRes { - Box::new( - self.list_unspent_impl(0, std::i32::MAX, vec![address.to_string()]) - .map(|unspents| { - unspents - .iter() - .fold(BigDecimal::from(0), |sum, unspent| sum + unspent.amount.to_decimal()) - }), - ) + let addresses = match address.addr_format { + UtxoAddressFormat::Segwit => vec![address + .to_segwitaddress() + .expect("to_segwitaddress should not fail for UtxoAddressFormat::Segwit") + .to_string()], + _ => vec![address.to_string()], + }; + Box::new(self.list_unspent_impl(0, std::i32::MAX, addresses).map(|unspents| { + unspents + .iter() + .fold(BigDecimal::from(0), |sum, unspent| sum + unspent.amount.to_decimal()) + })) } fn estimate_fee_sat( diff --git a/mm2src/mm2_tests.rs b/mm2src/mm2_tests.rs index 60f118a3a7..eb17fc2864 100644 --- a/mm2src/mm2_tests.rs +++ b/mm2src/mm2_tests.rs @@ -1580,7 +1580,6 @@ fn test_withdraw_and_send_from_segwit() { "segwit": true, "bech32_hrp": "tb", "txfee": 1000, - "estimate_fee_mode": "ECONOMICAL", "mm2": 1, "required_confirmations": 0, "protocol": { @@ -1681,7 +1680,6 @@ fn test_withdraw_and_send_legacy_to_segwit() { "segwit": true, "bech32_hrp": "tb", "txfee": 1000, - "estimate_fee_mode": "ECONOMICAL", "mm2": 1, "required_confirmations": 0, "protocol": { @@ -1766,7 +1764,6 @@ fn test_tbtc_withdraw_to_cashaddresses_should_fail() { "segwit": true, "bech32_hrp": "tb", "txfee": 1000, - "estimate_fee_mode": "ECONOMICAL", "mm2": 1, "required_confirmations": 0, "protocol": {