diff --git a/mm2src/coins/my_tx_history_v2.rs b/mm2src/coins/my_tx_history_v2.rs index ede09c91c3..caf55dcfe4 100644 --- a/mm2src/coins/my_tx_history_v2.rs +++ b/mm2src/coins/my_tx_history_v2.rs @@ -439,58 +439,61 @@ where // TODO // !! temporary solution !! // Tendermint specific mapping - // By-passed only when `CustomTendermintMsg` is `FeeForTokenTx` - match &details.transaction_type { - TransactionType::CustomTendermintMsg { msg_type, .. } - if matches!(msg_type, CustomTendermintMsgType::FeeForTokenTx) => {}, - TransactionType::StakingDelegation - | TransactionType::RemoveDelegation - | TransactionType::StandardTransfer - | TransactionType::TokenTransfer(_) - | TransactionType::CustomTendermintMsg { .. } => { - // TODO - // see this https://github.com/KomodoPlatform/atomicDEX-API/pull/1526#discussion_r1037001780 - if let Some(TxFeeDetails::Utxo(fee)) = &mut details.fee_details { - let mapped_fee = crate::tendermint::TendermintFeeDetails { - coin: request.coin.clone(), - amount: fee.amount.clone(), - gas_limit: crate::tendermint::GAS_LIMIT_DEFAULT, - // ignored anyway - uamount: 0, + match protocol_type { + TENDERMINT_COIN_PROTOCOL_TYPE | TENDERMINT_ASSET_PROTOCOL_TYPE => match &details.transaction_type { + // By-passed when `CustomTendermintMsg` is `FeeForTokenTx` + TransactionType::CustomTendermintMsg { msg_type, .. } + if matches!(msg_type, CustomTendermintMsgType::FeeForTokenTx) => {}, + TransactionType::StakingDelegation + | TransactionType::RemoveDelegation + | TransactionType::StandardTransfer + | TransactionType::TokenTransfer(_) + | TransactionType::CustomTendermintMsg { .. } => { + // TODO + // see this https://github.com/KomodoPlatform/atomicDEX-API/pull/1526#discussion_r1037001780 + if let Some(TxFeeDetails::Utxo(fee)) = &mut details.fee_details { + let mapped_fee = crate::tendermint::TendermintFeeDetails { + coin: request.coin.clone(), + amount: fee.amount.clone(), + gas_limit: crate::tendermint::GAS_LIMIT_DEFAULT, + // ignored anyway + uamount: 0, + }; + details.fee_details = Some(TxFeeDetails::Tendermint(mapped_fee)); + } + + match protocol_type { + // for tendermint, tx_history_v2 implementation doesn't include amount parsing logic. + // therefore, re-mapping is required + TENDERMINT_COIN_PROTOCOL_TYPE | TENDERMINT_ASSET_PROTOCOL_TYPE => { + // In order to use error result instead of panicking, we should do an extra iteration above this map. + // Because all the values are inserted by u64 convertion in tx_history_v2 implementation, using `panic` + // shouldn't harm. + + let u_total_amount = details.total_amount.to_u64().unwrap_or_else(|| { + panic!("Parsing '{}' into u64 should not fail", details.total_amount) + }); + details.total_amount = big_decimal_from_sat_unsigned(u_total_amount, decimals); + + let u_spent_by_me = details.spent_by_me.to_u64().unwrap_or_else(|| { + panic!("Parsing '{}' into u64 should not fail", details.spent_by_me) + }); + details.spent_by_me = big_decimal_from_sat_unsigned(u_spent_by_me, decimals); + + let u_received_by_me = details.received_by_me.to_u64().unwrap_or_else(|| { + panic!("Parsing '{}' into u64 should not fail", details.received_by_me) + }); + details.received_by_me = big_decimal_from_sat_unsigned(u_received_by_me, decimals); + + // Because this can be negative values, no need to read and parse + // this since it's always 0 from tx_history_v2 implementation. + details.my_balance_change = &details.received_by_me - &details.spent_by_me; + }, + _ => {}, }; - details.fee_details = Some(TxFeeDetails::Tendermint(mapped_fee)); - } - - match protocol_type { - // for tendermint, tx_history_v2 implementation doesn't include amount parsing logic. - // therefore, re-mapping is required - TENDERMINT_COIN_PROTOCOL_TYPE | TENDERMINT_ASSET_PROTOCOL_TYPE => { - // In order to use error result instead of panicking, we should do an extra iteration above this map. - // Because all the values are inserted by u64 convertion in tx_history_v2 implementation, using `panic` - // shouldn't harm. - - let u_total_amount = details.total_amount.to_u64().unwrap_or_else(|| { - panic!("Parsing '{}' into u64 should not fail", details.total_amount) - }); - details.total_amount = big_decimal_from_sat_unsigned(u_total_amount, decimals); - - let u_spent_by_me = details.spent_by_me.to_u64().unwrap_or_else(|| { - panic!("Parsing '{}' into u64 should not fail", details.spent_by_me) - }); - details.spent_by_me = big_decimal_from_sat_unsigned(u_spent_by_me, decimals); - - let u_received_by_me = details.received_by_me.to_u64().unwrap_or_else(|| { - panic!("Parsing '{}' into u64 should not fail", details.received_by_me) - }); - details.received_by_me = big_decimal_from_sat_unsigned(u_received_by_me, decimals); - - // Because this can be negative values, no need to read and parse - // this since it's always 0 from tx_history_v2 implementation. - details.my_balance_change = &details.received_by_me - &details.spent_by_me; - }, - _ => {}, - }; + }, }, + _ => {}, }; let confirmations = if details.block_height == 0 || details.block_height > current_block { diff --git a/mm2src/coins/tendermint/tendermint_tx_history_v2.rs b/mm2src/coins/tendermint/tendermint_tx_history_v2.rs index f830f01d85..6dd14bf661 100644 --- a/mm2src/coins/tendermint/tendermint_tx_history_v2.rs +++ b/mm2src/coins/tendermint/tendermint_tx_history_v2.rs @@ -532,13 +532,13 @@ where match transfer_details.transfer_event_type { TransferEventType::CreateHtlc => { if tx_sent_by_me { - Some((vec![my_address.clone()], vec![])) + Some((vec![my_address], vec![])) } else { // This shouldn't happen if rpc node properly executes the tx search query. None } }, - TransferEventType::ClaimHtlc => Some((vec![my_address.clone()], vec![])), + TransferEventType::ClaimHtlc => Some((vec![my_address], vec![])), TransferEventType::Standard => { Some((vec![transfer_details.from.clone()], vec![transfer_details.to.clone()])) },