Skip to content

Commit

Permalink
fix lint & update tendermint mapping condition
Browse files Browse the repository at this point in the history
Signed-off-by: ozkanonur <[email protected]>
  • Loading branch information
onur-ozkan committed Dec 2, 2022
1 parent 452fc50 commit d7197e9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 52 deletions.
103 changes: 53 additions & 50 deletions mm2src/coins/my_tx_history_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/tendermint/tendermint_tx_history_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]))
},
Expand Down

0 comments on commit d7197e9

Please sign in to comment.