From 2b95017a85cae95d6452c9f9c6df77c0a5d400e0 Mon Sep 17 00:00:00 2001 From: ozkanonur Date: Fri, 2 Dec 2022 14:56:59 +0300 Subject: [PATCH] fix review notes Signed-off-by: ozkanonur --- mm2src/coins/lp_coins.rs | 16 +- mm2src/coins/my_tx_history_v2.rs | 140 +++++---- mm2src/coins/tendermint/mod.rs | 12 + mm2src/coins/tendermint/rpc/mod.rs | 2 +- mm2src/coins/tendermint/tendermint_coin.rs | 108 ++++--- .../tendermint/tendermint_tx_history_v2.rs | 226 ++++++++++---- mm2src/coins/tx_history_storage/mod.rs | 11 +- mm2src/coins/utxo/qtum_delegation.rs | 5 +- .../src/erc20_token_activation.rs | 3 +- .../src/platform_coin_with_tokens.rs | 2 +- .../src/slp_token_activation.rs | 3 +- .../src/spl_token_activation.rs | 3 +- .../src/tendermint_token_activation.rs | 3 +- .../src/tendermint_with_assets_activation.rs | 6 +- mm2src/coins_activation/src/token.rs | 16 +- mm2src/common/common.rs | 13 + mm2src/gossipsub/src/protocol.rs | 6 +- mm2src/hw_common/src/transport/libusb.rs | 23 +- .../src/account/storage/sqlite_storage.rs | 6 +- mm2src/mm2_main/src/lp_ordermatch.rs | 5 +- .../mm2_main/src/lp_ordermatch/best_orders.rs | 10 +- mm2src/mm2_main/src/lp_swap/swap_lock.rs | 6 +- .../tests/mm2_tests/tendermint_tests.rs | 7 +- .../dummy_files/iris_nimda_history.json | 293 ++++++++++++------ .../dummy_files/iris_test_history.json | 226 ++++++++++---- mm2src/mm2_test_helpers/src/structs.rs | 13 +- 26 files changed, 772 insertions(+), 392 deletions(-) diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index a3e4636e3bf..3175d622b06 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -217,8 +217,8 @@ use rpc_command::{init_account_balance::{AccountBalanceTaskManager, AccountBalan init_withdraw::{WithdrawTaskManager, WithdrawTaskManagerShared}}; pub mod tendermint; -use tendermint::{CosmosTransaction, TendermintCoin, TendermintFeeDetails, TendermintProtocolInfo, TendermintToken, - TendermintTokenProtocolInfo}; +use tendermint::{CosmosTransaction, CustomTendermintMsgType, TendermintCoin, TendermintFeeDetails, + TendermintProtocolInfo, TendermintToken, TendermintTokenProtocolInfo}; #[doc(hidden)] #[allow(unused_variables)] @@ -1036,17 +1036,17 @@ impl KmdRewardsDetails { } } -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Default, Clone, Debug, Deserialize, PartialEq, Serialize)] pub enum TransactionType { StakingDelegation, RemoveDelegation, + #[default] StandardTransfer, TokenTransfer(BytesJson), - Fee(BytesJson), -} - -impl Default for TransactionType { - fn default() -> Self { TransactionType::StandardTransfer } + CustomTendermintMsg { + msg_type: CustomTendermintMsgType, + token_id: Option, + }, } /// Transaction details diff --git a/mm2src/coins/my_tx_history_v2.rs b/mm2src/coins/my_tx_history_v2.rs index f05ca0ece49..0c4b59c4816 100644 --- a/mm2src/coins/my_tx_history_v2.rs +++ b/mm2src/coins/my_tx_history_v2.rs @@ -1,5 +1,5 @@ use crate::hd_wallet::{AddressDerivingError, InvalidBip44ChainError}; -use crate::tendermint::{TENDERMINT_ASSET_PROTOCOL_TYPE, TENDERMINT_COIN_PROTOCOL_TYPE}; +use crate::tendermint::{CustomTendermintMsgType, TENDERMINT_ASSET_PROTOCOL_TYPE, TENDERMINT_COIN_PROTOCOL_TYPE}; use crate::tx_history_storage::{CreateTxHistoryStorageError, FilteringAddresses, GetTxHistoryFilters, TxHistoryStorageBuilder, WalletId}; use crate::utxo::utxo_common::big_decimal_from_sat_unsigned; @@ -18,7 +18,6 @@ use mm2_number::BigDecimal; use num_traits::ToPrimitive; use rpc::v1::types::{Bytes as BytesJson, ToTxHash}; use std::collections::HashSet; -use std::mem::discriminant; #[derive(Debug)] pub enum RemoveTxResult { @@ -217,11 +216,20 @@ impl<'a, Addr: Clone + DisplayAddress + Eq + std::hash::Hash, Tx: Transaction> T let tx_hash = self.tx.tx_hash(); let internal_id = match &self.transaction_type { - TransactionType::TokenTransfer(token_id) | TransactionType::Fee(token_id) => { + TransactionType::TokenTransfer(token_id) => { let mut bytes_for_hash = tx_hash.0.clone(); bytes_for_hash.extend_from_slice(&token_id.0); sha256(&bytes_for_hash).to_vec().into() }, + TransactionType::CustomTendermintMsg { token_id, .. } => { + if let Some(token_id) = token_id { + let mut bytes_for_hash = tx_hash.0.clone(); + bytes_for_hash.extend_from_slice(&token_id.0); + sha256(&bytes_for_hash).to_vec().into() + } else { + tx_hash.clone() + } + }, TransactionType::StakingDelegation | TransactionType::RemoveDelegation | TransactionType::StandardTransfer => tx_hash.clone(), @@ -419,58 +427,86 @@ where let protocol_type = coin_conf["protocol"]["type"].as_str().unwrap_or_default(); let decimals = coin.decimals(); - let transactions = - history - .transactions - .into_iter() - .map(|mut details| { - // checking if transaction type is not `Fee` - if discriminant(&details.transaction_type) != discriminant(&TransactionType::Fee(BytesJson::default())) - { - // it can be the platform ticker instead of the token ticker for a pre-saved record - if details.coin != request.coin { - details.coin = request.coin.clone(); + let transactions = history + .transactions + .into_iter() + .map(|mut details| { + // it can be the platform ticker instead of the token ticker for a pre-saved record + if details.coin != request.coin { + details.coin = request.coin.clone(); + } + + // TODO + // !! temporary solution !! + // Tendermint specific mapping + match protocol_type { + TENDERMINT_COIN_PROTOCOL_TYPE | TENDERMINT_ASSET_PROTOCOL_TYPE => { + // 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 { + // We make sure this is filled in `tendermint_tx_history_v2` + coin: fee.coin.as_ref().expect("can't be empty").to_owned(), + 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; + 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 { .. } => { + 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 { - 0 - } else { - current_block + 1 - details.block_height - }; - MyTxHistoryDetails { confirmations, details } - }) - .collect(); + } + }, + _ => {}, + }; + + let confirmations = if details.block_height == 0 || details.block_height > current_block { + 0 + } else { + current_block + 1 - details.block_height + }; + MyTxHistoryDetails { confirmations, details } + }) + .collect(); Ok(MyTxHistoryResponseV2 { coin: request.coin, diff --git a/mm2src/coins/tendermint/mod.rs b/mm2src/coins/tendermint/mod.rs index 2bdaab5b4ac..beacbcd37fb 100644 --- a/mm2src/coins/tendermint/mod.rs +++ b/mm2src/coins/tendermint/mod.rs @@ -11,6 +11,18 @@ pub mod tendermint_tx_history_v2; pub use tendermint_coin::*; pub use tendermint_token::*; +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum CustomTendermintMsgType { + /// Create HTLC as sender + SendHtlcAmount, + /// Claim HTLC as reciever + ClaimHtlcAmount, + /// Claim HTLC for reciever + SignClaimHtlc, + /// Extra tx display for token txs (because cosmos uses platform coin for paying fees) + FeeForTokenTx, +} + pub(crate) const TENDERMINT_COIN_PROTOCOL_TYPE: &str = "TENDERMINT"; pub(crate) const TENDERMINT_ASSET_PROTOCOL_TYPE: &str = "TENDERMINTTOKEN"; diff --git a/mm2src/coins/tendermint/rpc/mod.rs b/mm2src/coins/tendermint/rpc/mod.rs index 64986e25693..bd34834ce9c 100644 --- a/mm2src/coins/tendermint/rpc/mod.rs +++ b/mm2src/coins/tendermint/rpc/mod.rs @@ -9,7 +9,7 @@ pub(crate) const TX_SUCCESS_CODE: u32 = 0; #[repr(u8)] pub enum TendermintResultOrder { - Ascending = 0, + Ascending = 1, Descending, } diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index 5c21d29e96f..d0ee6b9a19a 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -87,6 +87,19 @@ pub(crate) const TX_DEFAULT_MEMO: &str = ""; const MAX_TIME_LOCK: i64 = 34560; const MIN_TIME_LOCK: i64 = 50; +#[async_trait] +pub trait TendermintCommons { + fn platform_denom(&self) -> String; + + fn set_history_sync_state(&self, new_state: HistorySyncState); + + async fn get_block_timestamp(&self, block: i64) -> MmResult, TendermintCoinRpcError>; + + async fn all_balances(&self) -> MmResult; + + async fn rpc_client(&self) -> MmResult; +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct TendermintFeeDetails { pub coin: String, @@ -332,6 +345,62 @@ impl From for SearchForSwapTxSpendErr { fn from(e: DecodeError) -> Self { SearchForSwapTxSpendErr::Proto(e) } } +#[async_trait] +impl TendermintCommons for TendermintCoin { + fn platform_denom(&self) -> String { self.denom.to_string() } + + fn set_history_sync_state(&self, new_state: HistorySyncState) { + *self.history_sync_state.lock().unwrap() = new_state; + } + + async fn get_block_timestamp(&self, block: i64) -> MmResult, TendermintCoinRpcError> { + let block_response = self.get_block_by_height(block).await?; + let block_header = some_or_return_ok_none!(some_or_return_ok_none!(block_response.block).header); + let timestamp = some_or_return_ok_none!(block_header.time); + + Ok(u64::try_from(timestamp.seconds).ok()) + } + + async fn all_balances(&self) -> MmResult { + let platform_balance_denom = self.balance_for_denom(self.denom.to_string()).await?; + let platform_balance = big_decimal_from_sat_unsigned(platform_balance_denom, self.decimals); + let ibc_assets_info = self.tokens_info.lock().clone(); + + let mut result = AllBalancesResult { + platform_balance, + tokens_balances: HashMap::new(), + }; + for (ticker, info) in ibc_assets_info { + let balance_denom = self.balance_for_denom(info.denom.to_string()).await?; + let balance_decimal = big_decimal_from_sat_unsigned(balance_denom, info.decimals); + result.tokens_balances.insert(ticker, balance_decimal); + } + + Ok(result) + } + + // TODO + // Save one working client to the coin context, only try others once it doesn't + // work anymore. + // Also, try couple times more on health check errors. + async fn rpc_client(&self) -> MmResult { + for rpc_client in self.rpc_clients.iter() { + match rpc_client.perform(HealthRequest).timeout(Duration::from_secs(3)).await { + Ok(Ok(_)) => return Ok(rpc_client.clone()), + Ok(Err(e)) => log::warn!( + "Recieved error from Tendermint rpc node during health check. Error: {:?}", + e + ), + Err(_) => log::warn!("Tendermint rpc node: {:?} got timeout during health check", rpc_client), + }; + } + + MmError::err(TendermintCoinRpcError::PerformError( + "All the current rpc nodes are unavailable.".to_string(), + )) + } +} + impl TendermintCoin { pub async fn init( ctx: &MmArc, @@ -415,27 +484,6 @@ impl TendermintCoin { }))) } - // TODO - // Save one working client to the coin context, only try others once it doesn't - // work anymore. - // Also, try couple times more on health check errors. - pub(crate) async fn rpc_client(&self) -> MmResult { - for rpc_client in self.rpc_clients.iter() { - match rpc_client.perform(HealthRequest).timeout(Duration::from_secs(3)).await { - Ok(Ok(_)) => return Ok(rpc_client.clone()), - Ok(Err(e)) => log::warn!( - "Recieved error from Tendermint rpc node during health check. Error: {:?}", - e - ), - Err(_) => log::warn!("Tendermint rpc node: {:?} got timeout during health check", rpc_client), - }; - } - - MmError::err(TendermintCoinRpcError::PerformError( - "All the current rpc nodes are unavailable.".to_string(), - )) - } - #[inline(always)] fn gas_price(&self) -> f64 { self.gas_price.unwrap_or(DEFAULT_GAS_PRICE) } @@ -628,24 +676,6 @@ impl TendermintCoin { .map_to_mm(|e| TendermintCoinRpcError::InvalidResponse(format!("balance is not u64, err {}", e))) } - pub async fn all_balances(&self) -> MmResult { - let platform_balance_denom = self.balance_for_denom(self.denom.to_string()).await?; - let platform_balance = big_decimal_from_sat_unsigned(platform_balance_denom, self.decimals); - let ibc_assets_info = self.tokens_info.lock().clone(); - - let mut result = AllBalancesResult { - platform_balance, - tokens_balances: HashMap::new(), - }; - for (ticker, info) in ibc_assets_info { - let balance_denom = self.balance_for_denom(info.denom.to_string()).await?; - let balance_decimal = big_decimal_from_sat_unsigned(balance_denom, info.decimals); - result.tokens_balances.insert(ticker, balance_decimal); - } - - Ok(result) - } - fn gen_create_htlc_tx( &self, denom: Denom, diff --git a/mm2src/coins/tendermint/tendermint_tx_history_v2.rs b/mm2src/coins/tendermint/tendermint_tx_history_v2.rs index 0d80e458817..59c90368dfd 100644 --- a/mm2src/coins/tendermint/tendermint_tx_history_v2.rs +++ b/mm2src/coins/tendermint/tendermint_tx_history_v2.rs @@ -1,10 +1,10 @@ -use super::{rpc::*, AllBalancesResult, TendermintCoin, TendermintCoinRpcError, TendermintToken}; +use super::{rpc::*, AllBalancesResult, TendermintCoin, TendermintCommons, TendermintToken}; use crate::my_tx_history_v2::{CoinWithTxHistoryV2, MyTxHistoryErrorV2, MyTxHistoryTarget, TxHistoryStorage}; -use crate::tendermint::TendermintFeeDetails; +use crate::tendermint::{CustomTendermintMsgType, TendermintFeeDetails}; use crate::tx_history_storage::{GetTxHistoryFilters, WalletId}; use crate::utxo::utxo_common::big_decimal_from_sat_unsigned; -use crate::{HistorySyncState, MarketCoinOps, TransactionDetails, TransactionType, TxFeeDetails}; +use crate::{HistorySyncState, MarketCoinOps, MmCoin, TransactionDetails, TransactionType, TxFeeDetails}; use async_trait::async_trait; use bitcrypto::sha256; use common::executor::Timer; @@ -68,18 +68,8 @@ macro_rules! some_or_return { }; } -#[async_trait] -pub trait TendermintTxHistoryOps: CoinWithTxHistoryV2 + MarketCoinOps + Send + Sync + 'static { - async fn get_rpc_client(&self) -> MmResult; - - fn decimals(&self) -> u8; - - fn platform_denom(&self) -> String; - - fn set_history_sync_state(&self, new_state: HistorySyncState); - - async fn all_balances(&self) -> MmResult; -} +trait CoinCapabilities: TendermintCommons + CoinWithTxHistoryV2 + MmCoin + MarketCoinOps {} +impl CoinCapabilities for TendermintCoin {} #[async_trait] impl CoinWithTxHistoryV2 for TendermintCoin { @@ -108,7 +98,7 @@ impl CoinWithTxHistoryV2 for TendermintToken { } } -struct TendermintTxHistoryCtx { +struct TendermintTxHistoryCtx { coin: Coin, storage: Storage, balances: AllBalancesResult, @@ -186,7 +176,7 @@ impl TransitionFrom> for #[async_trait] impl State for OnIoErrorCooldown where - Coin: TendermintTxHistoryOps, + Coin: CoinCapabilities, Storage: TxHistoryStorage, { type Ctx = TendermintTxHistoryCtx; @@ -238,7 +228,7 @@ impl TransitionFrom> #[async_trait] impl State for WaitForHistoryUpdateTrigger where - Coin: TendermintTxHistoryOps, + Coin: CoinCapabilities, Storage: TxHistoryStorage, { type Ctx = TendermintTxHistoryCtx; @@ -273,7 +263,7 @@ where #[async_trait] impl State for FetchingTransactionsData where - Coin: TendermintTxHistoryOps, + Coin: CoinCapabilities, Storage: TxHistoryStorage, { type Ctx = TendermintTxHistoryCtx; @@ -298,31 +288,53 @@ where received_by_me: BigDecimal, } - fn get_tx_amounts(amount: u64, sent_by_me: bool, is_self_transfer: bool) -> TxAmounts { - let amount = BigDecimal::from(amount); + fn get_tx_amounts( + transfer_details: &TransferDetails, + is_self_transfer: bool, + sent_by_me: bool, + is_sign_claim_htlc: bool, + fee_details: Option<&TendermintFeeDetails>, + ) -> TxAmounts { + let amount = BigDecimal::from(transfer_details.amount); + + let total = if is_sign_claim_htlc && !is_self_transfer { + BigDecimal::default() + } else { + amount.clone() + }; - let spent_by_me = if sent_by_me && !is_self_transfer { + let spent_by_me = if sent_by_me + && !is_self_transfer + && !matches!(transfer_details.transfer_event_type, TransferEventType::ClaimHtlc) + { amount.clone() } else { BigDecimal::default() }; let received_by_me = if !sent_by_me || is_self_transfer { - amount.clone() + amount } else { BigDecimal::default() }; - TxAmounts { - total: amount, + let mut tx_amounts = TxAmounts { + total, spent_by_me, received_by_me, + }; + + if let Some(fee_details) = fee_details { + tx_amounts.total += BigDecimal::from(fee_details.uamount); + tx_amounts.spent_by_me += BigDecimal::from(fee_details.uamount); } + + tx_amounts } fn get_fee_details(fee: Fee, coin: &Coin) -> Result where - Coin: TendermintTxHistoryOps, + Coin: CoinCapabilities, { let fee_coin = fee .amount @@ -338,17 +350,26 @@ where }) } + #[derive(Default, Clone)] + enum TransferEventType { + #[default] + Standard, + CreateHtlc, + ClaimHtlc, + } + #[derive(Clone)] struct TransferDetails { from: String, to: String, denom: String, amount: u64, + transfer_event_type: TransferEventType, } // updates sender and receiver addressses if tx is htlc, and if not leaves as it is. - fn fix_tx_addresses_if_htlc(transfer_details: &mut TransferDetails, msg_event: &&Event, event_type: &str) { - match event_type { + fn read_real_htlc_addresses(transfer_details: &mut TransferDetails, msg_event: &&Event) { + match msg_event.type_str.as_str() { CREATE_HTLC_EVENT => { transfer_details.from = some_or_return!(msg_event .attributes @@ -363,6 +384,8 @@ where .find(|tag| tag.key.to_string() == RECEIVER_TAG_KEY)) .value .to_string(); + + transfer_details.transfer_event_type = TransferEventType::CreateHtlc; }, CLAIM_HTLC_EVENT => { transfer_details.from = some_or_return!(msg_event @@ -371,13 +394,15 @@ where .find(|tag| tag.key.to_string() == SENDER_TAG_KEY)) .value .to_string(); + + transfer_details.transfer_event_type = TransferEventType::ClaimHtlc; }, _ => {}, } } fn parse_transfer_values_from_events(tx_events: Vec<&Event>) -> Vec { - let mut transfer_details_list = vec![]; + let mut transfer_details_list: Vec = vec![]; for (index, event) in tx_events.iter().enumerate() { if event.type_str.as_str() == TRANSFER_EVENT { @@ -414,6 +439,8 @@ where to, denom: denom.to_owned(), amount, + // Default is Standard, can be changed later in read_real_htlc_addresses + transfer_event_type: TransferEventType::default(), }; if index != 0 { @@ -421,12 +448,23 @@ where // addresses will be wrong. if let Some(prev_event) = tx_events.get(index - 1) { if [CREATE_HTLC_EVENT, CLAIM_HTLC_EVENT].contains(&prev_event.type_str.as_str()) { - fix_tx_addresses_if_htlc(&mut tx_details, prev_event, prev_event.type_str.as_str()); + read_real_htlc_addresses(&mut tx_details, prev_event); } }; } - transfer_details_list.push(tx_details); + // sum the amounts coins and pairs are same + let mut duplicated_details = transfer_details_list.iter_mut().find(|details| { + details.from == tx_details.from + && details.to == tx_details.to + && details.denom == tx_details.denom + }); + + if let Some(duplicated_details) = &mut duplicated_details { + duplicated_details.amount += tx_details.amount; + } else { + transfer_details_list.push(tx_details); + } } } } @@ -463,6 +501,50 @@ where parse_transfer_values_from_events(events) } + fn get_transaction_type( + transfer_event_type: &TransferEventType, + token_id: Option, + is_sign_claim_htlc: bool, + ) -> TransactionType { + match (transfer_event_type, token_id) { + (TransferEventType::CreateHtlc, token_id) => TransactionType::CustomTendermintMsg { + msg_type: CustomTendermintMsgType::SendHtlcAmount, + token_id, + }, + (TransferEventType::ClaimHtlc, token_id) => TransactionType::CustomTendermintMsg { + msg_type: if is_sign_claim_htlc { + CustomTendermintMsgType::SignClaimHtlc + } else { + CustomTendermintMsgType::ClaimHtlcAmount + }, + token_id, + }, + (_, Some(token_id)) => TransactionType::TokenTransfer(token_id), + _ => TransactionType::StandardTransfer, + } + } + + fn get_pair_addresses( + my_address: String, + tx_sent_by_me: bool, + transfer_details: &TransferDetails, + ) -> Option<(Vec, Vec)> { + match transfer_details.transfer_event_type { + TransferEventType::CreateHtlc => { + if tx_sent_by_me { + 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], vec![])), + TransferEventType::Standard => { + Some((vec![transfer_details.from.clone()], vec![transfer_details.to.clone()])) + }, + } + } + async fn fetch_and_insert_txs( address: String, coin: &Coin, @@ -471,7 +553,7 @@ where from_height: u64, ) -> Result> where - Coin: TendermintTxHistoryOps, + Coin: CoinCapabilities, Storage: TxHistoryStorage, { let mut page = 1; @@ -479,7 +561,7 @@ where let mut highest_height = from_height; let client = try_or_return_stopped_as_err!( - coin.get_rpc_client().await, + coin.rpc_client().await, StopReason::RpcClient, "could not get rpc client" ); @@ -505,6 +587,13 @@ where continue; } + let timestamp = try_or_return_stopped_as_err!( + coin.get_block_timestamp(i64::from(tx.height)).await, + StopReason::RpcClient, + "could not get block_timestamp over rpc node" + ); + let timestamp = some_or_continue!(timestamp); + let tx_hash = tx.hash.to_string(); highest_height = cmp::max(highest_height, tx.height.into()); @@ -562,20 +651,32 @@ where continue; } - let tx_sent_by_me = address.clone() == transfer_details.from; + let tx_sent_by_me = address == transfer_details.from; let is_platform_coin_tx = transfer_details.denom == coin.platform_denom(); - let is_self_tx = transfer_details.to == transfer_details.from; - let mut tx_amounts = get_tx_amounts(transfer_details.amount, tx_sent_by_me, is_self_tx); + let is_self_tx = transfer_details.to == transfer_details.from && tx_sent_by_me; + let is_sign_claim_htlc = tx_sent_by_me + && matches!(transfer_details.transfer_event_type, TransferEventType::ClaimHtlc); - if !fee_added + let (from, to) = + some_or_continue!(get_pair_addresses(address.clone(), tx_sent_by_me, transfer_details)); + + let maybe_add_fees = if !fee_added // if tx is platform coin tx and sent by me - && is_platform_coin_tx && tx_sent_by_me && !is_self_tx + && is_platform_coin_tx && tx_sent_by_me { - tx_amounts.total += BigDecimal::from(fee_details.uamount); - tx_amounts.spent_by_me += BigDecimal::from(fee_details.uamount); fee_added = true; - } - drop_mutability!(tx_amounts); + Some(&fee_details) + } else { + None + }; + + let tx_amounts = get_tx_amounts( + transfer_details, + is_self_tx, + tx_sent_by_me, + is_sign_claim_htlc, + maybe_add_fees, + ); let token_id: Option = match !is_platform_coin_tx { true => { @@ -585,18 +686,19 @@ where false => None, }; - let transaction_type = if let Some(token_id) = token_id.clone() { - TransactionType::TokenTransfer(token_id) - } else { - TransactionType::StandardTransfer - }; + let transaction_type = get_transaction_type( + &transfer_details.transfer_event_type, + token_id.clone(), + is_sign_claim_htlc, + ); let details = TransactionDetails { - from: vec![transfer_details.from.clone()], - to: vec![transfer_details.to.clone()], + from, + to, total_amount: tx_amounts.total, spent_by_me: tx_amounts.spent_by_me, received_by_me: tx_amounts.received_by_me, + // This can be 0 since it gets remapped in `coins::my_tx_history_v2` my_balance_change: BigDecimal::default(), tx_hash: tx_hash.to_string(), tx_hex: msg.into(), @@ -604,7 +706,7 @@ where block_height: tx.height.into(), coin: transfer_details.denom.clone(), internal_id, - timestamp: common::now_ms() / 1000, + timestamp, kmd_rewards: None, transaction_type, }; @@ -628,7 +730,10 @@ where fee_tx_details.coin = coin.platform_ticker().to_string(); // Non-reversed version of original internal id fee_tx_details.internal_id = H256::from(internal_id_hash.as_slice()).to_vec().into(); - fee_tx_details.transaction_type = TransactionType::Fee(token_id); + fee_tx_details.transaction_type = TransactionType::CustomTendermintMsg { + msg_type: CustomTendermintMsgType::FeeForTokenTx, + token_id: Some(token_id), + }; tx_details.push(fee_tx_details); fee_added = true; @@ -724,7 +829,7 @@ where #[async_trait] impl State for TendermintInit where - Coin: TendermintTxHistoryOps, + Coin: CoinCapabilities, Storage: TxHistoryStorage, { type Ctx = TendermintTxHistoryCtx; @@ -758,7 +863,7 @@ where #[async_trait] impl LastState for Stopped where - Coin: TendermintTxHistoryOps, + Coin: CoinCapabilities, Storage: TxHistoryStorage, { type Ctx = TendermintTxHistoryCtx; @@ -779,21 +884,6 @@ where } } -#[async_trait] -impl TendermintTxHistoryOps for TendermintCoin { - async fn get_rpc_client(&self) -> MmResult { self.rpc_client().await } - - fn decimals(&self) -> u8 { self.decimals } - - fn platform_denom(&self) -> String { self.denom.to_string() } - - fn set_history_sync_state(&self, new_state: HistorySyncState) { - *self.history_sync_state.lock().unwrap() = new_state; - } - - async fn all_balances(&self) -> MmResult { self.all_balances().await } -} - pub async fn tendermint_history_loop( coin: TendermintCoin, storage: impl TxHistoryStorage, diff --git a/mm2src/coins/tx_history_storage/mod.rs b/mm2src/coins/tx_history_storage/mod.rs index 3186463ab5b..1f0ca4f8d82 100644 --- a/mm2src/coins/tx_history_storage/mod.rs +++ b/mm2src/coins/tx_history_storage/mod.rs @@ -23,7 +23,16 @@ mod tx_history_v2_tests; #[inline] pub fn token_id_from_tx_type(tx_type: &TransactionType) -> String { match tx_type { - TransactionType::Fee(token_id) | TransactionType::TokenTransfer(token_id) => format!("{:02x}", token_id), + TransactionType::TokenTransfer(token_id) => { + format!("{:02x}", token_id) + }, + TransactionType::CustomTendermintMsg { token_id, .. } => { + if let Some(token_id) = token_id { + format!("{:02x}", token_id) + } else { + String::new() + } + }, _ => String::new(), } } diff --git a/mm2src/coins/utxo/qtum_delegation.rs b/mm2src/coins/utxo/qtum_delegation.rs index 5765e482b0e..e2f1fcb1268 100644 --- a/mm2src/coins/utxo/qtum_delegation.rs +++ b/mm2src/coins/utxo/qtum_delegation.rs @@ -156,10 +156,7 @@ impl QtumCoin { .map_to_mm(|e| StakingInfosError::Transport(e.to_string()))?; let am_i_staking = add_delegation_history.len() > remove_delegation_history.len(); if am_i_staking { - let last_tx_add = match add_delegation_history.last() { - Some(last_tx_add) => last_tx_add, - None => return Ok(None), - }; + let last_tx_add = some_or_return_ok_none!(add_delegation_history.last()); let res = &client .blockchain_transaction_get_receipt(&last_tx_add.tx_hash) .compat() diff --git a/mm2src/coins_activation/src/erc20_token_activation.rs b/mm2src/coins_activation/src/erc20_token_activation.rs index cf43ed9a3fd..9a5dff22d9e 100644 --- a/mm2src/coins_activation/src/erc20_token_activation.rs +++ b/mm2src/coins_activation/src/erc20_token_activation.rs @@ -66,7 +66,6 @@ impl TokenProtocolParams for Erc20Protocol { #[async_trait] impl TokenActivationOps for EthCoin { - type PlatformCoin = EthCoin; type ActivationParams = Erc20TokenActivationRequest; type ProtocolInfo = Erc20Protocol; type ActivationResult = Erc20InitResult; @@ -74,7 +73,7 @@ impl TokenActivationOps for EthCoin { async fn enable_token( ticker: String, - platform_coin: ::PlatformCoin, + platform_coin: Self::PlatformCoin, activation_params: Self::ActivationParams, protocol_conf: Self::ProtocolInfo, ) -> Result<(Self, Self::ActivationResult), MmError> { diff --git a/mm2src/coins_activation/src/platform_coin_with_tokens.rs b/mm2src/coins_activation/src/platform_coin_with_tokens.rs index 0145dfea18a..488c3417d51 100644 --- a/mm2src/coins_activation/src/platform_coin_with_tokens.rs +++ b/mm2src/coins_activation/src/platform_coin_with_tokens.rs @@ -21,7 +21,7 @@ pub struct TokenActivationRequest { } pub trait TokenOf: Into { - type PlatformCoin: PlatformWithTokensActivationOps + RegisterTokenInfo; + type PlatformCoin: TryPlatformCoinFromMmCoinEnum + PlatformWithTokensActivationOps + RegisterTokenInfo + Clone; } pub struct TokenActivationParams { diff --git a/mm2src/coins_activation/src/slp_token_activation.rs b/mm2src/coins_activation/src/slp_token_activation.rs index 418a26a5c66..85f017b0cc6 100644 --- a/mm2src/coins_activation/src/slp_token_activation.rs +++ b/mm2src/coins_activation/src/slp_token_activation.rs @@ -73,7 +73,6 @@ pub struct SlpInitResult { #[async_trait] impl TokenActivationOps for SlpToken { - type PlatformCoin = BchCoin; type ActivationParams = SlpActivationRequest; type ProtocolInfo = SlpProtocolConf; type ActivationResult = SlpInitResult; @@ -81,7 +80,7 @@ impl TokenActivationOps for SlpToken { async fn enable_token( ticker: String, - platform_coin: ::PlatformCoin, + platform_coin: Self::PlatformCoin, activation_params: Self::ActivationParams, protocol_conf: Self::ProtocolInfo, ) -> Result<(Self, Self::ActivationResult), MmError> { diff --git a/mm2src/coins_activation/src/spl_token_activation.rs b/mm2src/coins_activation/src/spl_token_activation.rs index d13390de43d..69782e11ac0 100644 --- a/mm2src/coins_activation/src/spl_token_activation.rs +++ b/mm2src/coins_activation/src/spl_token_activation.rs @@ -83,7 +83,6 @@ impl From for EnableTokenError { #[async_trait] impl TokenActivationOps for SplToken { - type PlatformCoin = SolanaCoin; type ActivationParams = SplActivationRequest; type ProtocolInfo = SplProtocolConf; type ActivationResult = SplInitResult; @@ -91,7 +90,7 @@ impl TokenActivationOps for SplToken { async fn enable_token( ticker: String, - platform_coin: ::PlatformCoin, + platform_coin: Self::PlatformCoin, _activation_params: Self::ActivationParams, protocol_conf: Self::ProtocolInfo, ) -> Result<(Self, Self::ActivationResult), MmError> { diff --git a/mm2src/coins_activation/src/tendermint_token_activation.rs b/mm2src/coins_activation/src/tendermint_token_activation.rs index 74cd7cdfc1a..58cc6b90c14 100644 --- a/mm2src/coins_activation/src/tendermint_token_activation.rs +++ b/mm2src/coins_activation/src/tendermint_token_activation.rs @@ -45,7 +45,6 @@ impl TokenProtocolParams for TendermintTokenProtocolInfo { #[async_trait] impl TokenActivationOps for TendermintToken { - type PlatformCoin = TendermintCoin; type ActivationParams = TendermintTokenActivationParams; type ProtocolInfo = TendermintTokenProtocolInfo; type ActivationResult = TendermintTokenInitResult; @@ -53,7 +52,7 @@ impl TokenActivationOps for TendermintToken { async fn enable_token( ticker: String, - platform_coin: ::PlatformCoin, + platform_coin: Self::PlatformCoin, _activation_params: Self::ActivationParams, protocol_conf: Self::ProtocolInfo, ) -> Result<(Self, Self::ActivationResult), MmError> { diff --git a/mm2src/coins_activation/src/tendermint_with_assets_activation.rs b/mm2src/coins_activation/src/tendermint_with_assets_activation.rs index 320a7de1d0a..d9bb87afc22 100644 --- a/mm2src/coins_activation/src/tendermint_with_assets_activation.rs +++ b/mm2src/coins_activation/src/tendermint_with_assets_activation.rs @@ -6,9 +6,9 @@ use crate::prelude::*; use async_trait::async_trait; use coins::my_tx_history_v2::TxHistoryStorage; use coins::tendermint::tendermint_tx_history_v2::tendermint_history_loop; -use coins::tendermint::{TendermintCoin, TendermintConf, TendermintInitError, TendermintInitErrorKind, - TendermintProtocolInfo, TendermintToken, TendermintTokenActivationParams, - TendermintTokenInitError, TendermintTokenProtocolInfo}; +use coins::tendermint::{TendermintCoin, TendermintCommons, TendermintConf, TendermintInitError, + TendermintInitErrorKind, TendermintProtocolInfo, TendermintToken, + TendermintTokenActivationParams, TendermintTokenInitError, TendermintTokenProtocolInfo}; use coins::{CoinBalance, CoinProtocol, MarketCoinOps, MmCoin, PrivKeyBuildPolicy}; use common::executor::{AbortSettings, SpawnAbortable}; use common::Future01CompatExt; diff --git a/mm2src/coins_activation/src/token.rs b/mm2src/coins_activation/src/token.rs index 448b6234d78..fd90378b4c2 100644 --- a/mm2src/coins_activation/src/token.rs +++ b/mm2src/coins_activation/src/token.rs @@ -19,7 +19,6 @@ pub trait TokenProtocolParams { #[async_trait] pub trait TokenActivationOps: Into + platform_coin_with_tokens::TokenOf { - type PlatformCoin: TryPlatformCoinFromMmCoinEnum + RegisterTokenInfo + Clone; type ActivationParams; type ProtocolInfo: TokenProtocolParams + TryFromCoinProtocol; type ActivationResult; @@ -27,7 +26,7 @@ pub trait TokenActivationOps: Into + platform_coin_with_tokens::Toke async fn enable_token( ticker: String, - platform_coin: ::PlatformCoin, + platform_coin: Self::PlatformCoin, activation_params: Self::ActivationParams, protocol_conf: Self::ProtocolInfo, ) -> Result<(Self, Self::ActivationResult), MmError>; @@ -117,13 +116,12 @@ where .await .mm_err(|_| EnableTokenError::PlatformCoinIsNotActivated(token_protocol.platform_coin_ticker().to_owned()))?; - let platform_coin = - ::PlatformCoin::try_from_mm_coin(platform_coin).or_mm_err(|| { - EnableTokenError::UnsupportedPlatformCoin { - platform_coin_ticker: token_protocol.platform_coin_ticker().into(), - token_ticker: req.ticker.clone(), - } - })?; + let platform_coin = Token::PlatformCoin::try_from_mm_coin(platform_coin).or_mm_err(|| { + EnableTokenError::UnsupportedPlatformCoin { + platform_coin_ticker: token_protocol.platform_coin_ticker().into(), + token_ticker: req.ticker.clone(), + } + })?; let (token, activation_result) = Token::enable_token(req.ticker, platform_coin.clone(), req.activation_params, token_protocol).await?; diff --git a/mm2src/common/common.rs b/mm2src/common/common.rs index 755811d0175..65045c24276 100644 --- a/mm2src/common/common.rs +++ b/mm2src/common/common.rs @@ -93,6 +93,19 @@ macro_rules! drop_mutability { }; } +/// Reads inner value of `Option`, returns `Ok(None)` otherwise. +#[macro_export] +macro_rules! some_or_return_ok_none { + ($val:expr) => { + match $val { + Some(t) => t, + None => { + return Ok(None); + }, + } + }; +} + #[macro_use] pub mod jsonrpc_client; #[macro_use] diff --git a/mm2src/gossipsub/src/protocol.rs b/mm2src/gossipsub/src/protocol.rs index ea7f5493452..1173a89b22b 100644 --- a/mm2src/gossipsub/src/protocol.rs +++ b/mm2src/gossipsub/src/protocol.rs @@ -24,6 +24,7 @@ use crate::topic::TopicHash; use byteorder::{BigEndian, ByteOrder}; use bytes::Bytes; use bytes::BytesMut; +use common::some_or_return_ok_none; use futures::future; use futures::prelude::*; use futures_codec::{Decoder, Encoder, Framed}; @@ -211,10 +212,7 @@ impl Decoder for GossipsubCodec { type Error = io::Error; fn decode(&mut self, src: &mut BytesMut) -> Result, Self::Error> { - let packet = match self.length_codec.decode(src)? { - Some(p) => p, - None => return Ok(None), - }; + let packet = some_or_return_ok_none!(self.length_codec.decode(src)?); let rpc = rpc_proto::Rpc::decode(&packet[..])?; diff --git a/mm2src/hw_common/src/transport/libusb.rs b/mm2src/hw_common/src/transport/libusb.rs index ac9351b99c8..da33494dc58 100644 --- a/mm2src/hw_common/src/transport/libusb.rs +++ b/mm2src/hw_common/src/transport/libusb.rs @@ -2,8 +2,8 @@ //! We can spawn it once on [`UsbContext::new`], but we have to set the read/write chunk timeout to 0.5s or smaller. use super::{send_event_recv_response, InternalError}; -use common::block_on; use common::log::error; +use common::{block_on, some_or_return_ok_none}; use derive_more::Display; use futures::channel::{mpsc, oneshot}; use futures::StreamExt; @@ -102,28 +102,17 @@ impl UsbContext { let config_descriptor = device .config_descriptor(filters.config_id) .map_to_mm(UsbError::ErrorGettingDevices)?; - let interface = match config_descriptor + let interface = some_or_return_ok_none!(config_descriptor .interfaces() - .find(|i| i.number() == filters.interface_id) - { - Some(interface) => interface, - None => return Ok(None), - }; - let descriptor = match interface + .find(|i| i.number() == filters.interface_id)); + let descriptor = some_or_return_ok_none!(interface .descriptors() - .find(|d| d.setting_number() == filters.interface_descriptor) - { - Some(descriptor) => descriptor, - None => return Ok(None), - }; + .find(|d| d.setting_number() == filters.interface_descriptor)); if descriptor.class_code() != filters.interface_class_code { return Ok(None); } // Get the first endpoint. - let endpoint = match descriptor.endpoint_descriptors().next() { - Some(endpoint) => endpoint, - None => return Ok(None), - }; + let endpoint = some_or_return_ok_none!(descriptor.endpoint_descriptors().next()); Ok(Some(UsbDeviceInterfaceInfo { interface_number: filters.interface_id, endpoint_number: endpoint.number(), diff --git a/mm2src/mm2_gui_storage/src/account/storage/sqlite_storage.rs b/mm2src/mm2_gui_storage/src/account/storage/sqlite_storage.rs index 18d350d6c98..916854de639 100644 --- a/mm2src/mm2_gui_storage/src/account/storage/sqlite_storage.rs +++ b/mm2src/mm2_gui_storage/src/account/storage/sqlite_storage.rs @@ -3,6 +3,7 @@ use crate::account::{AccountId, AccountInfo, AccountType, AccountWithCoins, Acco EnabledAccountType, HwPubkey, MAX_ACCOUNT_DESCRIPTION_LENGTH, MAX_ACCOUNT_NAME_LENGTH, MAX_TICKER_LENGTH}; use async_trait::async_trait; +use common::some_or_return_ok_none; use db_common::foreign_columns; use db_common::sql_build::*; use db_common::sqlite::rusqlite::types::Type; @@ -244,10 +245,7 @@ impl SqliteAccountStorage { conn: &Connection, account_id: &AccountId, ) -> AccountStorageResult> { - let account_info = match Self::load_account(conn, account_id)? { - Some(acc) => acc, - None => return Ok(None), - }; + let account_info = some_or_return_ok_none!(Self::load_account(conn, account_id)?); let coins = Self::load_account_coins(conn, account_id)?; Ok(Some(AccountWithCoins { account_info, coins })) diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index bd1aad254ec..8a7d78508fa 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -838,10 +838,7 @@ fn process_sync_pubkey_orderbook_state( ) -> Result, String> { let ordermatch_ctx = OrdermatchContext::from_ctx(&ctx).unwrap(); let orderbook = ordermatch_ctx.orderbook.lock(); - let pubkey_state = match orderbook.pubkeys_state.get(&pubkey) { - Some(s) => s, - None => return Ok(None), - }; + let pubkey_state = some_or_return_ok_none!(orderbook.pubkeys_state.get(&pubkey)); let order_getter = |uuid: &Uuid| orderbook.order_set.get(uuid).cloned(); let pair_orders_diff: Result, _> = trie_roots diff --git a/mm2src/mm2_main/src/lp_ordermatch/best_orders.rs b/mm2src/mm2_main/src/lp_ordermatch/best_orders.rs index 43050526999..35f59f8253f 100644 --- a/mm2src/mm2_main/src/lp_ordermatch/best_orders.rs +++ b/mm2src/mm2_main/src/lp_ordermatch/best_orders.rs @@ -65,10 +65,7 @@ pub fn process_best_orders_p2p_request( BestOrdersAction::Buy => &orderbook.pairs_existing_for_base, BestOrdersAction::Sell => &orderbook.pairs_existing_for_rel, }; - let tickers = match search_pairs_in.get(&coin) { - Some(tickers) => tickers, - None => return Ok(None), - }; + let tickers = some_or_return_ok_none!(search_pairs_in.get(&coin)); let mut result = HashMap::new(); let pairs = tickers.iter().map(|ticker| match action { BestOrdersAction::Buy => (coin.clone(), ticker.clone()), @@ -154,10 +151,7 @@ pub fn process_best_orders_p2p_request_by_number( BestOrdersAction::Buy => &orderbook.pairs_existing_for_base, BestOrdersAction::Sell => &orderbook.pairs_existing_for_rel, }; - let tickers = match search_pairs_in.get(&coin) { - Some(tickers) => tickers, - None => return Ok(None), - }; + let tickers = some_or_return_ok_none!(search_pairs_in.get(&coin)); let mut result = HashMap::new(); let pairs = tickers.iter().map(|ticker| match action { BestOrdersAction::Buy => (coin.clone(), ticker.clone()), diff --git a/mm2src/mm2_main/src/lp_swap/swap_lock.rs b/mm2src/mm2_main/src/lp_swap/swap_lock.rs index b28f15dc97e..f9f84a6cb72 100644 --- a/mm2src/mm2_main/src/lp_swap/swap_lock.rs +++ b/mm2src/mm2_main/src/lp_swap/swap_lock.rs @@ -57,10 +57,8 @@ mod native_lock { impl SwapLockOps for SwapLock { async fn lock(ctx: &MmArc, swap_uuid: Uuid, ttl_sec: f64) -> SwapLockResult> { let lock_path = my_swaps_dir(ctx).join(format!("{}.lock", swap_uuid)); - let file_lock = match FileLock::lock(lock_path, ttl_sec)? { - Some(lock) => lock, - None => return Ok(None), - }; + let file_lock = some_or_return_ok_none!(FileLock::lock(lock_path, ttl_sec)?); + Ok(Some(SwapLock { file_lock })) } diff --git a/mm2src/mm2_main/tests/mm2_tests/tendermint_tests.rs b/mm2src/mm2_main/tests/mm2_tests/tendermint_tests.rs index 06923fddd4d..6864c556fe2 100644 --- a/mm2src/mm2_main/tests/mm2_tests/tendermint_tests.rs +++ b/mm2src/mm2_main/tests/mm2_tests/tendermint_tests.rs @@ -198,12 +198,13 @@ fn test_tendermint_token_activation_and_withdraw() { } #[test] +#[ignore] fn test_tendermint_tx_history() { const TEST_SEED: &str = "Vdo8Xt8pTAetRlMq3kV0LzE393eVYbPSn5Mhtw4p"; const TX_FINISHED_LOG: &str = "Tx history fetching finished for IRIS-TEST."; const TX_HISTORY_PAGE_LIMIT: usize = 50; - const IRIS_TEST_EXPECTED_TX_COUNT: u64 = 7; - const IRIS_NIMDA_EXPECTED_TX_COUNT: u64 = 11; + const IRIS_TEST_EXPECTED_TX_COUNT: u64 = 10; + const IRIS_NIMDA_EXPECTED_TX_COUNT: u64 = 15; let iris_test_constant_history_txs = include_str!("../../../mm2_test_helpers/dummy_files/iris_test_history.json"); let iris_test_constant_history_txs: Vec = @@ -245,7 +246,6 @@ fn test_tendermint_tx_history() { let mut iris_txs_from_request = iris_tx_history_response["result"]["transactions"].clone(); for i in 0..IRIS_TEST_EXPECTED_TX_COUNT { - iris_txs_from_request[i as usize]["timestamp"] = json!(0); iris_txs_from_request[i as usize] .as_object_mut() .unwrap() @@ -261,7 +261,6 @@ fn test_tendermint_tx_history() { let mut nimda_txs_from_request = nimda_tx_history_response["result"]["transactions"].clone(); for i in 0..IRIS_NIMDA_EXPECTED_TX_COUNT { - nimda_txs_from_request[i as usize]["timestamp"] = json!(0); nimda_txs_from_request[i as usize] .as_object_mut() .unwrap() diff --git a/mm2src/mm2_test_helpers/dummy_files/iris_nimda_history.json b/mm2src/mm2_test_helpers/dummy_files/iris_nimda_history.json index b9e3316a8da..2d76f7e49a0 100644 --- a/mm2src/mm2_test_helpers/dummy_files/iris_nimda_history.json +++ b/mm2src/mm2_test_helpers/dummy_files/iris_nimda_history.json @@ -1,4 +1,157 @@ [ + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a726130122a696161316530727838376d646a37397a656a65777563346a6737716c39756432323836673275733866322a0c0a036e696d1205313030303032403838613735653161306166373662636161386266353566313437616266616262313362323964646333316465323161373431363835333966373135643032343240980c", + "tx_hash": "B06D02A1449B07E89D15E709C347E0EE72A944687942E5A10467EC096D067FE7", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.027385", + "spent_by_me": "0.027385", + "received_by_me": "0", + "my_balance_change": "-0.027385", + "block_height": 6175147, + "timestamp": 1669934633, + "fee_details": null, + "coin": "IRIS-NIMDA", + "internal_id": "0000000000000000423036443032413134343942303745383944313545373039", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "FeeForTokenTx", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } + } + }, + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a726130122a696161316530727838376d646a37397a656a65777563346a6737716c39756432323836673275733866322a0c0a036e696d1205313030303032403838613735653161306166373662636161386266353566313437616266616262313362323964646333316465323161373431363835333966373135643032343240980c", + "tx_hash": "B06D02A1449B07E89D15E709C347E0EE72A944687942E5A10467EC096D067FE7", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.01", + "spent_by_me": "0.01", + "received_by_me": "0", + "my_balance_change": "-0.01", + "block_height": 6175147, + "timestamp": 1669934633, + "fee_details": { + "type": "Tendermint", + "coin": "IRIS-TEST", + "amount": "0.027385", + "gas_limit": 100000 + }, + "coin": "IRIS-NIMDA", + "internal_id": "3930374535314439384537304239343431413230443630420000000000000000", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "SendHtlcAmount", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } + } + }, + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a726130122a696161316530727838376d646a37397a656a65777563346a6737716c39756432323836673275733866322a0c0a036e696d1205313030303032406466313465616234366366623230663736613465336233393537656234326137666130646435366137386466623038656134323034666334383762663536323040980c", + "tx_hash": "26E7CA4A95C70316195E8C8A3249351710B1BFE89AE9B910463BC8280C0AA9CF", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.028433", + "spent_by_me": "0.028433", + "received_by_me": "0", + "my_balance_change": "-0.028433", + "block_height": 6175115, + "timestamp": 1669934472, + "fee_details": null, + "coin": "IRIS-NIMDA", + "internal_id": "0000000000000000323645374341344139354337303331363139354538433841", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "FeeForTokenTx", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } + } + }, + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a726130122a696161316530727838376d646a37397a656a65777563346a6737716c39756432323836673275733866322a0c0a036e696d1205313030303032406466313465616234366366623230663736613465336233393537656234326137666130646435366137386466623038656134323034666334383762663536323040980c", + "tx_hash": "26E7CA4A95C70316195E8C8A3249351710B1BFE89AE9B910463BC8280C0AA9CF", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.01", + "spent_by_me": "0.01", + "received_by_me": "0", + "my_balance_change": "-0.01", + "block_height": 6175115, + "timestamp": 1669934472, + "fee_details": { + "type": "Tendermint", + "coin": "IRIS-TEST", + "amount": "0.028433", + "gas_limit": 100000 + }, + "coin": "IRIS-NIMDA", + "internal_id": "4138433845353931363133303743353941344143374536320000000000000000", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "SendHtlcAmount", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } + } + }, + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301240364636394643303235393632413032463736363741414142393932313245393434454244444436434143314235354431443336333139383341413433454145421a4030646432663130353032343463386235316363636239316535363734386336373032343634393263383465323835656234353365363166373630623730356432", + "tx_hash": "459F88CACCD57756DDFE2164AABBA2C3D463D0FBA5D85DFD79488416A9BD54FC", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.026403", + "spent_by_me": "0.026403", + "received_by_me": "0", + "my_balance_change": "-0.026403", + "block_height": 6175070, + "timestamp": 1669934246, + "fee_details": null, + "coin": "IRIS-NIMDA", + "internal_id": "0000000000000000343539463838434143434435373735364444464532313634", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "FeeForTokenTx", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } + } + }, + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301240364636394643303235393632413032463736363741414142393932313245393434454244444436434143314235354431443336333139383341413433454145421a4030646432663130353032343463386235316363636239316535363734386336373032343634393263383465323835656234353365363166373630623730356432", + "tx_hash": "459F88CACCD57756DDFE2164AABBA2C3D463D0FBA5D85DFD79488416A9BD54FC", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.01", + "spent_by_me": "0", + "received_by_me": "0.01", + "my_balance_change": "0.01", + "block_height": 6175070, + "timestamp": 1669934246, + "fee_details": { + "type": "Tendermint", + "coin": "IRIS-TEST", + "amount": "0.026403", + "gas_limit": 100000 + }, + "coin": "IRIS-NIMDA", + "internal_id": "3436313245464444363537373544434341433838463935340000000000000000", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "SignClaimHtlc", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } + } + }, { "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a726130122a696161316530727838376d646a37397a656a65777563346a6737716c39756432323836673275733866322a0c0a036e696d1205313030303032403738646661636564613462346362373336366362626638643436336237393061666566363566656538613764356464356264616633613365303766343330623640980c", "tx_hash": "25D9A1F1C9383AC7D56E3E19F3D6B9ED3F52F7D0E9225ABBEA0258FF75E28FC2", @@ -11,12 +164,15 @@ "received_by_me": "0", "my_balance_change": "-0.028433", "block_height": 6148309, - "timestamp": 0, + "timestamp": 1669798875, "fee_details": null, - "coin": "IRIS-TEST", + "coin": "IRIS-NIMDA", "internal_id": "0000000000000000323544394131463143393338334143374435364533453139", "transaction_type": { - "Fee": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + "CustomTendermintMsg": { + "msg_type": "FeeForTokenTx", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } } }, { @@ -25,24 +181,26 @@ "from": [ "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" ], - "to": [ - "iaa1e0rx87mdj79zejewuc4jg7ql9ud2286g2us8f2" - ], + "to": [], "total_amount": "0.01", "spent_by_me": "0.01", "received_by_me": "0", "my_balance_change": "-0.01", "block_height": 6148309, - "timestamp": 0, + "timestamp": 1669798875, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.028433" + "amount": "0.028433", + "gas_limit": 100000 }, "coin": "IRIS-NIMDA", "internal_id": "3931453345363544374341333833394331463141394435320000000000000000", "transaction_type": { - "TokenTransfer": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + "CustomTendermintMsg": { + "msg_type": "SendHtlcAmount", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } } }, { @@ -57,12 +215,15 @@ "received_by_me": "0", "my_balance_change": "-0.025763", "block_height": 6148307, - "timestamp": 0, + "timestamp": 1669798865, "fee_details": null, - "coin": "IRIS-TEST", + "coin": "IRIS-NIMDA", "internal_id": "0000000000000000443833443831343343414438433232354633424332344336", "transaction_type": { - "Fee": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + "CustomTendermintMsg": { + "msg_type": "FeeForTokenTx", + "token_id": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" + } } }, { @@ -79,11 +240,12 @@ "received_by_me": "0", "my_balance_change": "-0.0001", "block_height": 6148307, - "timestamp": 0, + "timestamp": 1669798865, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.025763" + "amount": "0.025763", + "gas_limit": 100000 }, "coin": "IRIS-NIMDA", "internal_id": "3643343243423346353232433844414333343138443338440000000000000000", @@ -100,16 +262,17 @@ "to": [ "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" ], - "total_amount": "1", + "total_amount": "2", "spent_by_me": "0", - "received_by_me": "1", - "my_balance_change": "1", + "received_by_me": "2", + "my_balance_change": "2", "block_height": 6148055, - "timestamp": 0, + "timestamp": 1669797598, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.022114" + "amount": "0.022114", + "gas_limit": 100000 }, "coin": "IRIS-NIMDA", "internal_id": "4631313139343742323142303344373639303343333441370000000000000000", @@ -117,32 +280,6 @@ "TokenTransfer": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" } }, - { - "tx_hex": "0a2a696161316530727838376d646a37397a656a65777563346a6737716c3975643232383667327573386632122a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301a0e0a036e696d120731303030303030", - "tx_hash": "7A43C30967D30B12B749111F217A670C0B47B7C5F272BCD82C442C1554351CB7", - "from": [ - "iaa1e0rx87mdj79zejewuc4jg7ql9ud2286g2us8f2" - ], - "to": [ - "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" - ], - "total_amount": "1", - "spent_by_me": "0", - "received_by_me": "1", - "my_balance_change": "1", - "block_height": 6148055, - "timestamp": 0, - "fee_details": { - "type": "Utxo", - "coin": "IRIS-TEST", - "amount": "0.022114" - }, - "coin": "IRIS-NIMDA", - "internal_id": "4631313139343742323142303344373639303343333441370000000000000001", - "transaction_type": { - "TokenTransfer": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" - } - }, { "tx_hex": "0a2a696161316530727838376d646a37397a656a65777563346a6737716c3975643232383667327573386632122a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301a0e0a036e696d1207313030303030301a100a05756e79616e120731303030303030", "tx_hash": "3057F075161ECD149F4F5A629F852D5E7E57411DECE7AD35CC7D11E7EB06E0BF", @@ -152,16 +289,17 @@ "to": [ "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" ], - "total_amount": "1", + "total_amount": "2", "spent_by_me": "0", - "received_by_me": "1", - "my_balance_change": "1", + "received_by_me": "2", + "my_balance_change": "2", "block_height": 6148039, - "timestamp": 0, + "timestamp": 1669797517, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.026861" + "amount": "0.026861", + "gas_limit": 100000 }, "coin": "IRIS-NIMDA", "internal_id": "3236413546344639343144434531363135373046373530330000000000000000", @@ -169,32 +307,6 @@ "TokenTransfer": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" } }, - { - "tx_hex": "0a2a696161316530727838376d646a37397a656a65777563346a6737716c3975643232383667327573386632122a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301a0e0a036e696d1207313030303030301a100a05756e79616e120731303030303030", - "tx_hash": "3057F075161ECD149F4F5A629F852D5E7E57411DECE7AD35CC7D11E7EB06E0BF", - "from": [ - "iaa1e0rx87mdj79zejewuc4jg7ql9ud2286g2us8f2" - ], - "to": [ - "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" - ], - "total_amount": "1", - "spent_by_me": "0", - "received_by_me": "1", - "my_balance_change": "1", - "block_height": 6148039, - "timestamp": 0, - "fee_details": { - "type": "Utxo", - "coin": "IRIS-TEST", - "amount": "0.026861" - }, - "coin": "IRIS-NIMDA", - "internal_id": "3236413546344639343144434531363135373046373530330000000000000002", - "transaction_type": { - "TokenTransfer": "e13c266c61de5e79cf37a99b94d4d4462d6857fe8a5dbdde9e041ae01b14a7db" - } - }, { "tx_hex": "0a2a696161316530727838376d646a37397a656a65777563346a6737716c3975643232383667327573386632122a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301a0e0a036e696d1207313030303030301a100a05756e79616e120731303030303030", "tx_hash": "14FA04603223A5753DD60ADCE2593FD4AFA0A386E008AF7130916152F11D5748", @@ -209,11 +321,12 @@ "received_by_me": "1", "my_balance_change": "1", "block_height": 6148028, - "timestamp": 0, + "timestamp": 1669797462, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.026861" + "amount": "0.026861", + "gas_limit": 100000 }, "coin": "IRIS-NIMDA", "internal_id": "4344413036444433353735413332323330363430414634310000000000000000", @@ -235,11 +348,12 @@ "received_by_me": "1", "my_balance_change": "1", "block_height": 6148010, - "timestamp": 0, + "timestamp": 1669797371, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.022114" + "amount": "0.022114", + "gas_limit": 100000 }, "coin": "IRIS-NIMDA", "internal_id": "4339384239303045393643333738453237333945314344330000000000000000", @@ -261,11 +375,12 @@ "received_by_me": "1", "my_balance_change": "1", "block_height": 6147988, - "timestamp": 0, + "timestamp": 1669797261, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.02316" + "amount": "0.02316", + "gas_limit": 100000 }, "coin": "IRIS-NIMDA", "internal_id": "4136303630343838314237323638453734433246453537450000000000000000", diff --git a/mm2src/mm2_test_helpers/dummy_files/iris_test_history.json b/mm2src/mm2_test_helpers/dummy_files/iris_test_history.json index ff9026c32ff..872bfe2d3d5 100644 --- a/mm2src/mm2_test_helpers/dummy_files/iris_test_history.json +++ b/mm2src/mm2_test_helpers/dummy_files/iris_test_history.json @@ -1,27 +1,140 @@ [ { - "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301240384636304534433336384335344539343233344145424135394331344531384146413138443437303530314434383944444641364539363635444135323738451a4064363034613132626531616239643966343531306435343832666232323762613530363238373531326466333561626337303730313763366439306165303837", - "tx_hash": "6BA67D4C7A0F48E5D85EE18EF5A649ED456B539D902828D56849B57DCFF5914B", + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301240353136384331423544333836313243373835414530364141344130363036443537433444454343373939333834314338344544313932363138303941333335361a4064323032323032336639656565633338393561326637323063383463613363383638653632656232393139666262613732376262333464623434313739333232", + "tx_hash": "072AB56BE582BB1EF82193D6EDF855A0311E53D9240EBEEE5E7844898C54DADD", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.037215", + "spent_by_me": "0.027215", + "received_by_me": "0.01", + "my_balance_change": "-0.017215", + "block_height": 6175150, + "timestamp": 1669934648, + "fee_details": { + "type": "Tendermint", + "coin": "IRIS-TEST", + "amount": "0.027215", + "gas_limit": 100000 + }, + "coin": "IRIS-TEST", + "internal_id": "3644333931323846453142423238354542363542413237300000000000000000", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "SignClaimHtlc", + "token_id": null + } + } + }, + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a726130122a696161316530727838376d646a37397a656a65777563346a6737716c39756432323836673275733866322a0e0a05756e79616e1205313030303032403835306338333863393930363661323466373330363866623537336638356337353836323036613733366330353331323030396233323437313834643130656340980c", + "tx_hash": "8A4BD1D952AC833C4C11313580CAC61374C80D1641D6EBD459DE73AFA7DF47F2", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.03856", + "spent_by_me": "0.03856", + "received_by_me": "0", + "my_balance_change": "-0.03856", + "block_height": 6175068, + "timestamp": 1669934236, + "fee_details": { + "type": "Tendermint", + "coin": "IRIS-TEST", + "amount": "0.02856", + "gas_limit": 100000 + }, + "coin": "IRIS-TEST", + "internal_id": "3533313331314334433333384341323539443144423441380000000000000000", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "SendHtlcAmount", + "token_id": null + } + } + }, + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a726130122a696161316567307167617a37336a737676727676747a713478383233686d7a387161706c64643078347a1a0c0a05756e79616e1203313030", + "tx_hash": "734623F6744A44ABA5D551233B409400CF69EC8858302E9AE868A8400E925D51", "from": [ "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" ], "to": [ - "iaa1erfnkjsmalkwtvj44qnfr2drfzdt4n9ldh0kjv" + "iaa1eg0qgaz73jsvvrvvtzq4x823hmz8qapldd0x4z" ], - "total_amount": "0.026427", - "spent_by_me": "0.026427", + "total_amount": "0.022185", + "spent_by_me": "0.022185", "received_by_me": "0", - "my_balance_change": "-0.026427", + "my_balance_change": "-0.022185", + "block_height": 6175065, + "timestamp": 1669934221, + "fee_details": { + "type": "Tendermint", + "coin": "IRIS-TEST", + "amount": "0.022085", + "gas_limit": 100000 + }, + "coin": "IRIS-TEST", + "internal_id": "3332313535443541424134344134343736463332363433370000000000000000", + "transaction_type": "StandardTransfer" + }, + { + "tx_hex": "0a2a696161316530727838376d646a37397a656a65777563346a6737716c39756432323836673275733866321240413231314538373937463739314534434439333241423539424239333545324138354644453843393638374143463644383345373933424545373438463936431a4037626266353433313865643235643530366131393565363432636433343736613835303438393833623030346334653534336663313938313866333130353237", + "tx_hash": "252D31A8AFEF8B4C8D9058E9EFAF4ED5A41DB7C032B3849A87375F1DE2B8B9C1", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.000001", + "spent_by_me": "0", + "received_by_me": "0.000001", + "my_balance_change": "0.000001", + "block_height": 6173346, + "timestamp": 1669925588, + "fee_details": { + "type": "Tendermint", + "coin": "IRIS-TEST", + "amount": "0.026446", + "gas_limit": 100000 + }, + "coin": "IRIS-TEST", + "internal_id": "3945383530394438433442384645464138413133443235320000000000000000", + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "ClaimHtlcAmount", + "token_id": null + } + } + }, + { + "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301240384636304534433336384335344539343233344145424135394331344531384146413138443437303530314434383944444641364539363635444135323738451a4064363034613132626531616239643966343531306435343832666232323762613530363238373531326466333561626337303730313763366439306165303837", + "tx_hash": "6BA67D4C7A0F48E5D85EE18EF5A649ED456B539D902828D56849B57DCFF5914B", + "from": [ + "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" + ], + "to": [], + "total_amount": "0.026426", + "spent_by_me": "0.026426", + "received_by_me": "0", + "my_balance_change": "-0.026426", "block_height": 6148319, - "timestamp": 0, + "timestamp": 1669798925, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.026426" + "amount": "0.026426", + "gas_limit": 100000 }, "coin": "IRIS-TEST", "internal_id": "4538314545353844354538344630413743344437364142360000000000000000", - "transaction_type": "StandardTransfer" + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "SignClaimHtlc", + "token_id": null + } + } }, { "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a726130122a696161316572666e6b6a736d616c6b7774766a3434716e6672326472667a6474346e396c6468306b6a762a0a0a05756e79616e12013132403834373331663565393739643965616263343838393234356131613165663932396430386437383832353163353133633834303632373535313032343765326540e807", @@ -29,23 +142,27 @@ "from": [ "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" ], - "to": [ - "iaa1erfnkjsmalkwtvj44qnfr2drfzdt4n9ldh0kjv" - ], + "to": [], "total_amount": "0.028456", "spent_by_me": "0.028456", "received_by_me": "0", "my_balance_change": "-0.028456", "block_height": 6148318, - "timestamp": 0, + "timestamp": 1669798920, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.028455" + "amount": "0.028455", + "gas_limit": 100000 }, "coin": "IRIS-TEST", "internal_id": "4135353530353436314138373531433631443333364331460000000000000000", - "transaction_type": "StandardTransfer" + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "SendHtlcAmount", + "token_id": null + } + } }, { "tx_hex": "0a2a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301240304544424136304632423642383739324133333739423232453445323144373243343145413530464436353331433243383445413135353937303834373432391a4034353138383334373164316536383461323334663362323063626638646137393338636330643038383562626237326266303837363465386431356536353138", @@ -53,23 +170,27 @@ "from": [ "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" ], - "to": [ - "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" - ], - "total_amount": "0.01", - "spent_by_me": "0", + "to": [], + "total_amount": "0.03648", + "spent_by_me": "0.02648", "received_by_me": "0.01", - "my_balance_change": "0.01", + "my_balance_change": "-0.01648", "block_height": 6148311, - "timestamp": 0, + "timestamp": 1669798885, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.02648" + "amount": "0.02648", + "gas_limit": 100000 }, "coin": "IRIS-TEST", "internal_id": "4444394136304639344533383037313336353232394430310000000000000000", - "transaction_type": "StandardTransfer" + "transaction_type": { + "CustomTendermintMsg": { + "msg_type": "SignClaimHtlc", + "token_id": null + } + } }, { "tx_hex": "0a2a696161316530727838376d646a37397a656a65777563346a6737716c3975643232383667327573386632122a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301a0e0a036e696d1207313030303030301a100a05756e79616e120731303030303030", @@ -80,45 +201,22 @@ "to": [ "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" ], - "total_amount": "1", + "total_amount": "2", "spent_by_me": "0", - "received_by_me": "1", - "my_balance_change": "1", + "received_by_me": "2", + "my_balance_change": "2", "block_height": 6148039, - "timestamp": 0, + "timestamp": 1669797517, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.026861" + "amount": "0.026861", + "gas_limit": 100000 }, "coin": "IRIS-TEST", "internal_id": "3236413546344639343144434531363135373046373530330000000000000001", "transaction_type": "StandardTransfer" }, - { - "tx_hex": "0a2a696161316530727838376d646a37397a656a65777563346a6737716c3975643232383667327573386632122a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301a0e0a036e696d1207313030303030301a100a05756e79616e120731303030303030", - "tx_hash": "3057F075161ECD149F4F5A629F852D5E7E57411DECE7AD35CC7D11E7EB06E0BF", - "from": [ - "iaa1e0rx87mdj79zejewuc4jg7ql9ud2286g2us8f2" - ], - "to": [ - "iaa1z609g9z8ef4jlkcfgg36c2ljgcmna50l2yjra0" - ], - "total_amount": "1", - "spent_by_me": "0", - "received_by_me": "1", - "my_balance_change": "1", - "block_height": 6148039, - "timestamp": 0, - "fee_details": { - "type": "Utxo", - "coin": "IRIS-TEST", - "amount": "0.026861" - }, - "coin": "IRIS-TEST", - "internal_id": "3236413546344639343144434531363135373046373530330000000000000003", - "transaction_type": "StandardTransfer" - }, { "tx_hex": "0a2a696161316530727838376d646a37397a656a65777563346a6737716c3975643232383667327573386632122a696161317a36303967397a386566346a6c6b63666767333663326c6a67636d6e6135306c32796a7261301a0e0a036e696d1207313030303030301a100a05756e79616e120731303030303030", "tx_hash": "14FA04603223A5753DD60ADCE2593FD4AFA0A386E008AF7130916152F11D5748", @@ -133,11 +231,12 @@ "received_by_me": "1", "my_balance_change": "1", "block_height": 6148028, - "timestamp": 0, + "timestamp": 1669797462, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.026861" + "amount": "0.026861", + "gas_limit": 100000 }, "coin": "IRIS-TEST", "internal_id": "4344413036444433353735413332323330363430414634310000000000000001", @@ -157,11 +256,12 @@ "received_by_me": "100", "my_balance_change": "100", "block_height": 6147959, - "timestamp": 0, + "timestamp": 1669797114, "fee_details": { - "type": "Utxo", + "type": "Tendermint", "coin": "IRIS-TEST", - "amount": "0.2" + "amount": "0.2", + "gas_limit": 100000 }, "coin": "IRIS-TEST", "internal_id": "3846394537344334443745414531314244303741424145410000000000000000", diff --git a/mm2src/mm2_test_helpers/src/structs.rs b/mm2src/mm2_test_helpers/src/structs.rs index 8239a0423b1..ff42637da25 100644 --- a/mm2src/mm2_test_helpers/src/structs.rs +++ b/mm2src/mm2_test_helpers/src/structs.rs @@ -535,13 +535,24 @@ pub mod raw_transaction_error { } } +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum CustomTendermintMsgType { + SendHtlcAmount, + ClaimHtlcAmount, + SignClaimHtlc, + FeeForTokenTx, +} + #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] pub enum TransactionType { StakingDelegation, RemoveDelegation, StandardTransfer, TokenTransfer(String), - Fee(String), + CustomTendermintMsg { + msg_type: CustomTendermintMsgType, + token_id: Option, + }, } #[derive(Debug, Deserialize, PartialEq)]