Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions mm2src/coins/rpc_command/account_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ pub async fn account_balance(
req: HDAccountBalanceRequest,
) -> MmResult<HDAccountBalanceResponseEnum, HDAccountBalanceRpcError> {
match lp_coinfind_or_err(&ctx, &req.coin).await? {
MmCoinEnum::UtxoCoin(utxo) => Ok(HDAccountBalanceResponseEnum::Single(
Comment thread
mariocynicys marked this conversation as resolved.
MmCoinEnum::UtxoCoin(utxo) => Ok(HDAccountBalanceResponseEnum::Map(
utxo.account_balance_rpc(req.params).await?,
)),
MmCoinEnum::QtumCoin(qtum) => Ok(HDAccountBalanceResponseEnum::Single(
MmCoinEnum::QtumCoin(qtum) => Ok(HDAccountBalanceResponseEnum::Map(
qtum.account_balance_rpc(req.params).await?,
)),
MmCoinEnum::EthCoin(eth) => Ok(HDAccountBalanceResponseEnum::Map(
Expand Down
8 changes: 4 additions & 4 deletions mm2src/coins/rpc_command/get_new_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl RpcTask for InitGetNewAddressTask {
}

match self.coin {
MmCoinEnum::UtxoCoin(ref utxo) => Ok(GetNewAddressResponseEnum::Single(
MmCoinEnum::UtxoCoin(ref utxo) => Ok(GetNewAddressResponseEnum::Map(
get_new_address_helper(
&self.ctx,
utxo,
Expand All @@ -330,7 +330,7 @@ impl RpcTask for InitGetNewAddressTask {
)
.await?,
)),
MmCoinEnum::QtumCoin(ref qtum) => Ok(GetNewAddressResponseEnum::Single(
MmCoinEnum::QtumCoin(ref qtum) => Ok(GetNewAddressResponseEnum::Map(
get_new_address_helper(
&self.ctx,
qtum,
Expand Down Expand Up @@ -362,10 +362,10 @@ pub async fn get_new_address(
) -> MmResult<GetNewAddressResponseEnum, GetNewAddressRpcError> {
let coin = lp_coinfind_or_err(&ctx, &req.coin).await?;
match coin {
MmCoinEnum::UtxoCoin(utxo) => Ok(GetNewAddressResponseEnum::Single(
MmCoinEnum::UtxoCoin(utxo) => Ok(GetNewAddressResponseEnum::Map(
utxo.get_new_address_rpc_without_conf(req.params).await?,
)),
MmCoinEnum::QtumCoin(qtum) => Ok(GetNewAddressResponseEnum::Single(
MmCoinEnum::QtumCoin(qtum) => Ok(GetNewAddressResponseEnum::Map(
qtum.get_new_address_rpc_without_conf(req.params).await?,
)),
MmCoinEnum::EthCoin(eth) => Ok(GetNewAddressResponseEnum::Map(
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/rpc_command/init_account_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ impl RpcTask for InitAccountBalanceTask {
_task_handle: InitAccountBalanceTaskHandleShared,
) -> Result<Self::Item, MmError<Self::Error>> {
match self.coin {
MmCoinEnum::UtxoCoin(ref utxo) => Ok(HDAccountBalanceEnum::Single(
MmCoinEnum::UtxoCoin(ref utxo) => Ok(HDAccountBalanceEnum::Map(
utxo.init_account_balance_rpc(self.req.params.clone()).await?,
)),
MmCoinEnum::QtumCoin(ref qtum) => Ok(HDAccountBalanceEnum::Single(
MmCoinEnum::QtumCoin(ref qtum) => Ok(HDAccountBalanceEnum::Map(
qtum.init_account_balance_rpc(self.req.params.clone()).await?,
)),
MmCoinEnum::EthCoin(ref eth) => Ok(HDAccountBalanceEnum::Map(
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/rpc_command/init_create_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl RpcTask for InitCreateAccountTask {
}

match self.coin {
MmCoinEnum::UtxoCoin(ref utxo) => Ok(HDAccountBalanceEnum::Single(
MmCoinEnum::UtxoCoin(ref utxo) => Ok(HDAccountBalanceEnum::Map(
create_new_account_helper(
&self.ctx,
utxo,
Expand All @@ -298,7 +298,7 @@ impl RpcTask for InitCreateAccountTask {
)
.await?,
)),
MmCoinEnum::QtumCoin(ref qtum) => Ok(HDAccountBalanceEnum::Single(
MmCoinEnum::QtumCoin(ref qtum) => Ok(HDAccountBalanceEnum::Map(
create_new_account_helper(
&self.ctx,
qtum,
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/rpc_command/init_scan_for_new_addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ impl RpcTask for InitScanAddressesTask {

async fn run(&mut self, _task_handle: ScanAddressesTaskHandleShared) -> Result<Self::Item, MmError<Self::Error>> {
match self.coin {
MmCoinEnum::UtxoCoin(ref utxo) => Ok(ScanAddressesResponseEnum::Single(
MmCoinEnum::UtxoCoin(ref utxo) => Ok(ScanAddressesResponseEnum::Map(
utxo.init_scan_for_new_addresses_rpc(self.req.params.clone()).await?,
)),
MmCoinEnum::QtumCoin(ref qtum) => Ok(ScanAddressesResponseEnum::Single(
MmCoinEnum::QtumCoin(ref qtum) => Ok(ScanAddressesResponseEnum::Map(
qtum.init_scan_for_new_addresses_rpc(self.req.params.clone()).await?,
)),
MmCoinEnum::EthCoin(ref eth) => Ok(ScanAddressesResponseEnum::Map(
Expand Down
29 changes: 15 additions & 14 deletions mm2src/coins/utxo/bch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ use crate::utxo::utxo_common::{big_decimal_from_sat_unsigned, utxo_prepare_addre
use crate::utxo::utxo_hd_wallet::{UtxoHDAccount, UtxoHDAddress};
use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetailsError, UtxoTxDetailsParams,
UtxoTxHistoryOps};
use crate::{coin_balance, BlockHeightAndTime, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinProtocol,
CoinWithDerivationMethod, CoinWithPrivKeyPolicy, ConfirmPaymentInput, DexFee, GetWithdrawSenderAddress,
IguanaBalanceOps, IguanaPrivKey, MakerSwapTakerCoin, MmCoinEnum, NegotiateSwapContractAddrErr,
PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy,
RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundError, RefundPaymentArgs,
RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs,
SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, SwapOps, TakerSwapMakerCoin,
TradePreimageValue, TransactionFut, TransactionResult, TransactionType, TxFeeDetails, TxMarshalingErr,
UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr,
ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput,
ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WatcherReward,
WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput,
use crate::{coin_balance, BlockHeightAndTime, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinBalanceMap,
CoinProtocol, CoinWithDerivationMethod, CoinWithPrivKeyPolicy, ConfirmPaymentInput, DexFee,
GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MakerSwapTakerCoin, MmCoinEnum,
NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr,
PrivKeyBuildPolicy, RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundError,
RefundPaymentArgs, RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput,
SendPaymentArgs, SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, SwapOps,
TakerSwapMakerCoin, TradePreimageValue, TransactionFut, TransactionResult, TransactionType, TxFeeDetails,
TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs,
ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut,
ValidatePaymentInput, ValidateWatcherSpendInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps,
WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput,
WatcherValidateTakerFeeInput, WithdrawFut};
use common::executor::{AbortableSystem, AbortedError};
use common::log::warn;
Expand Down Expand Up @@ -1450,7 +1450,7 @@ impl HDCoinWithdrawOps for BchCoin {}
#[async_trait]
impl HDWalletBalanceOps for BchCoin {
type HDAddressScanner = UtxoAddressScanner;
type BalanceObject = CoinBalance;
type BalanceObject = CoinBalanceMap;

async fn produce_hd_address_scanner(&self) -> BalanceResult<Self::HDAddressScanner> {
utxo_common::produce_hd_address_scanner(self).await
Expand Down Expand Up @@ -1487,7 +1487,8 @@ impl HDWalletBalanceOps for BchCoin {
}

async fn known_address_balance(&self, address: &Address) -> BalanceResult<Self::BalanceObject> {
utxo_common::address_balance(self, address).await
let balance = utxo_common::address_balance(self, address).await?;
Ok(HashMap::from([(self.ticker().to_string(), balance)]))
}

async fn known_addresses_balances(
Expand Down
24 changes: 14 additions & 10 deletions mm2src/coins/utxo/qtum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::utxo::utxo_builder::{MergeUtxoArcOps, UtxoCoinBuildError, UtxoCoinBui
use crate::utxo::utxo_hd_wallet::{UtxoHDAccount, UtxoHDAddress};
use crate::utxo::utxo_tx_history_v2::{UtxoMyAddressesHistoryError, UtxoTxDetailsError, UtxoTxDetailsParams,
UtxoTxHistoryOps};
use crate::{eth, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinWithDerivationMethod,
use crate::{eth, CanRefundHtlc, CheckIfMyPaymentSentArgs, CoinBalance, CoinBalanceMap, CoinWithDerivationMethod,
CoinWithPrivKeyPolicy, ConfirmPaymentInput, DelegationError, DelegationFut, DexFee,
GetWithdrawSenderAddress, IguanaBalanceOps, IguanaPrivKey, MakerSwapTakerCoin, MmCoinEnum,
NegotiateSwapContractAddrErr, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr,
Expand Down Expand Up @@ -1062,9 +1062,12 @@ impl CoinWithDerivationMethod for QtumCoin {

#[async_trait]
impl IguanaBalanceOps for QtumCoin {
type BalanceObject = CoinBalance;
type BalanceObject = CoinBalanceMap;

async fn iguana_balances(&self) -> BalanceResult<Self::BalanceObject> { self.my_balance().compat().await }
async fn iguana_balances(&self) -> BalanceResult<Self::BalanceObject> {
let balance = self.my_balance().compat().await?;
Ok(HashMap::from([(self.ticker().to_string(), balance)]))
}
}

#[async_trait]
Expand Down Expand Up @@ -1103,7 +1106,7 @@ impl HDCoinWithdrawOps for QtumCoin {}
#[async_trait]
impl HDWalletBalanceOps for QtumCoin {
type HDAddressScanner = UtxoAddressScanner;
type BalanceObject = CoinBalance;
type BalanceObject = CoinBalanceMap;

async fn produce_hd_address_scanner(&self) -> BalanceResult<Self::HDAddressScanner> {
utxo_common::produce_hd_address_scanner(self).await
Expand Down Expand Up @@ -1140,7 +1143,8 @@ impl HDWalletBalanceOps for QtumCoin {
}

async fn known_address_balance(&self, address: &Address) -> BalanceResult<Self::BalanceObject> {
utxo_common::address_balance(self, address).await
let balance = utxo_common::address_balance(self, address).await?;
Ok(HashMap::from([(self.ticker().to_string(), balance)]))
}

async fn known_addresses_balances(
Expand All @@ -1160,7 +1164,7 @@ impl HDWalletBalanceOps for QtumCoin {

#[async_trait]
impl GetNewAddressRpcOps for QtumCoin {
type BalanceObject = CoinBalance;
type BalanceObject = CoinBalanceMap;

async fn get_new_address_rpc_without_conf(
&self,
Expand All @@ -1183,7 +1187,7 @@ impl GetNewAddressRpcOps for QtumCoin {

#[async_trait]
impl AccountBalanceRpcOps for QtumCoin {
type BalanceObject = CoinBalance;
type BalanceObject = CoinBalanceMap;

async fn account_balance_rpc(
&self,
Expand All @@ -1195,7 +1199,7 @@ impl AccountBalanceRpcOps for QtumCoin {

#[async_trait]
impl InitAccountBalanceRpcOps for QtumCoin {
type BalanceObject = CoinBalance;
type BalanceObject = CoinBalanceMap;

async fn init_account_balance_rpc(
&self,
Expand All @@ -1207,7 +1211,7 @@ impl InitAccountBalanceRpcOps for QtumCoin {

#[async_trait]
impl InitScanAddressesRpcOps for QtumCoin {
type BalanceObject = CoinBalance;
type BalanceObject = CoinBalanceMap;

async fn init_scan_for_new_addresses_rpc(
&self,
Expand All @@ -1219,7 +1223,7 @@ impl InitScanAddressesRpcOps for QtumCoin {

#[async_trait]
impl InitCreateAccountRpcOps for QtumCoin {
type BalanceObject = CoinBalance;
type BalanceObject = CoinBalanceMap;

async fn init_create_account_rpc<XPubExtractor>(
&self,
Expand Down
8 changes: 6 additions & 2 deletions mm2src/coins/utxo/rpc_clients/electrum_rpc/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,15 @@ impl ElectrumConnection {
};

let Some(dns_name) = uri.host().map(String::from) else {
return Err(ElectrumConnectionErr::Irrecoverable("Couldn't retrieve host from address".to_string()));
return Err(ElectrumConnectionErr::Irrecoverable(
"Couldn't retrieve host from address".to_string(),
));
};

let Ok(dns) = server_name_from_domain(dns_name.as_str()) else {
return Err(ElectrumConnectionErr::Irrecoverable("Address isn't a valid domain name".to_string()));
return Err(ElectrumConnectionErr::Irrecoverable(
"Address isn't a valid domain name".to_string(),
));
};

let tls_connector = if connection.settings.disable_cert_verification {
Expand Down
22 changes: 11 additions & 11 deletions mm2src/coins/utxo/utxo_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use crate::utxo::tx_cache::TxCacheResult;
use crate::utxo::utxo_hd_wallet::UtxoHDAddress;
use crate::utxo::utxo_withdraw::{InitUtxoWithdraw, StandardUtxoWithdraw, UtxoWithdraw};
use crate::watcher_common::validate_watcher_reward;
use crate::{scan_for_new_addresses_impl, CanRefundHtlc, CoinBalance, CoinWithDerivationMethod, ConfirmPaymentInput,
DexFee, GenPreimageResult, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs, GetWithdrawSenderAddress,
RawTransactionError, RawTransactionRequest, RawTransactionRes, RawTransactionResult,
RefundFundingSecretArgs, RefundMakerPaymentSecretArgs, RefundPaymentArgs, RewardTarget,
SearchForSwapTxSpendInput, SendMakerPaymentArgs, SendMakerPaymentSpendPreimageInput, SendPaymentArgs,
SendTakerFundingArgs, SignRawTransactionEnum, SignRawTransactionRequest, SignUtxoTransactionParams,
SignatureError, SignatureResult, SpendMakerPaymentArgs, SpendPaymentArgs, SwapOps,
SwapTxTypeWithSecretHash, TradePreimageValue, TransactionData, TransactionFut, TransactionResult,
use crate::{scan_for_new_addresses_impl, CanRefundHtlc, CoinBalance, CoinBalanceMap, CoinWithDerivationMethod,
ConfirmPaymentInput, DexFee, GenPreimageResult, GenTakerFundingSpendArgs, GenTakerPaymentSpendArgs,
GetWithdrawSenderAddress, RawTransactionError, RawTransactionRequest, RawTransactionRes,
RawTransactionResult, RefundFundingSecretArgs, RefundMakerPaymentSecretArgs, RefundPaymentArgs,
RewardTarget, SearchForSwapTxSpendInput, SendMakerPaymentArgs, SendMakerPaymentSpendPreimageInput,
SendPaymentArgs, SendTakerFundingArgs, SignRawTransactionEnum, SignRawTransactionRequest,
SignUtxoTransactionParams, SignatureError, SignatureResult, SpendMakerPaymentArgs, SpendPaymentArgs,
SwapOps, SwapTxTypeWithSecretHash, TradePreimageValue, TransactionData, TransactionFut, TransactionResult,
TxFeeDetails, TxGenError, TxMarshalingErr, TxPreimageWithSig, ValidateAddressResult,
ValidateOtherPubKeyErr, ValidatePaymentFut, ValidatePaymentInput, ValidateSwapV2TxError,
ValidateSwapV2TxResult, ValidateTakerFundingArgs, ValidateTakerFundingSpendPreimageError,
Expand Down Expand Up @@ -230,7 +230,7 @@ where

/// Requests balances of the given `addresses`.
/// The pairs `(Address, CoinBalance)` are guaranteed to be in the same order in which they were requested.
Comment thread
mariocynicys marked this conversation as resolved.
pub async fn addresses_balances<T>(coin: &T, addresses: Vec<Address>) -> BalanceResult<Vec<(Address, CoinBalance)>>
pub async fn addresses_balances<T>(coin: &T, addresses: Vec<Address>) -> BalanceResult<Vec<(Address, CoinBalanceMap)>>
where
T: UtxoCommonOps + GetUtxoMapOps + MarketCoinOps,
{
Expand All @@ -244,7 +244,7 @@ where
BalanceError::Internal(error)
})?;
let balance = unspents.to_coin_balance(coin.as_ref().decimals);
Ok((address, balance))
Ok((address, HashMap::from([(coin.ticker().to_string(), balance)])))
})
.collect()
} else {
Expand All @@ -258,7 +258,7 @@ where
.map(|(address, spendable)| {
let unspendable = BigDecimal::from(0);
let balance = CoinBalance { spendable, unspendable };
(address, balance)
(address, HashMap::from([(coin.ticker().to_string(), balance)]))
})
.collect())
}
Expand Down
Loading