Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mm2src/coins/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
25 changes: 16 additions & 9 deletions mm2src/coins/utxo/rpc_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,10 @@ impl JsonRpcClient for NativeClientImpl {
impl UtxoRpcClientOps for NativeClient {
fn list_unspent(&self, address: &Address, decimals: u8) -> UtxoRpcFut<Vec<UnspentInfo>> {
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
Expand Down Expand Up @@ -612,14 +615,18 @@ impl UtxoRpcClientOps for NativeClient {
}

fn display_balance(&self, address: Address, _decimals: u8) -> RpcRes<BigDecimal> {
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(
Expand Down
3 changes: 0 additions & 3 deletions mm2src/mm2_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down