Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into swap-proto-upgrade-ite…
Browse files Browse the repository at this point in the history
…ration-4

# Conflicts:
#	mm2src/mm2_main/src/lp_native_dex.rs
  • Loading branch information
artemii235 committed Dec 13, 2023
2 parents bae1f48 + 52dab22 commit 8313bc4
Show file tree
Hide file tree
Showing 28 changed files with 1,432 additions and 649 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ pub struct EthCoinImpl {
swap_contract_address: Address,
fallback_swap_contract: Option<Address>,
contract_supports_watchers: bool,
web3: Web3<Web3Transport>,
pub(crate) web3: Web3<Web3Transport>,
/// The separate web3 instances kept to get nonce, will replace the web3 completely soon
web3_instances: Vec<Web3Instance>,
decimals: u8,
Expand Down Expand Up @@ -875,7 +875,7 @@ async fn withdraw_impl(coin: EthCoin, req: WithdrawRequest) -> WithdrawResult {
/// `withdraw_erc1155` function returns details of `ERC-1155` transaction including tx hex,
/// which should be sent to`send_raw_transaction` RPC to broadcast the transaction.
pub async fn withdraw_erc1155(ctx: MmArc, withdraw_type: WithdrawErc1155) -> WithdrawNftResult {
let coin = lp_coinfind_or_err(&ctx, &withdraw_type.chain.to_ticker()).await?;
let coin = lp_coinfind_or_err(&ctx, withdraw_type.chain.to_ticker()).await?;
let (to_addr, token_addr, eth_coin) =
get_valid_nft_add_to_withdraw(coin, &withdraw_type.to, &withdraw_type.token_address)?;
let my_address = eth_coin.my_address()?;
Expand Down Expand Up @@ -977,7 +977,7 @@ pub async fn withdraw_erc1155(ctx: MmArc, withdraw_type: WithdrawErc1155) -> Wit
/// `withdraw_erc721` function returns details of `ERC-721` transaction including tx hex,
/// which should be sent to`send_raw_transaction` RPC to broadcast the transaction.
pub async fn withdraw_erc721(ctx: MmArc, withdraw_type: WithdrawErc721) -> WithdrawNftResult {
let coin = lp_coinfind_or_err(&ctx, &withdraw_type.chain.to_ticker()).await?;
let coin = lp_coinfind_or_err(&ctx, withdraw_type.chain.to_ticker()).await?;
let (to_addr, token_addr, eth_coin) =
get_valid_nft_add_to_withdraw(coin, &withdraw_type.to, &withdraw_type.token_address)?;
let my_address = eth_coin.my_address()?;
Expand Down Expand Up @@ -4716,7 +4716,7 @@ pub struct EthTxFeeDetails {
}

impl EthTxFeeDetails {
fn new(gas: U256, gas_price: U256, coin: &str) -> NumConversResult<EthTxFeeDetails> {
pub(crate) fn new(gas: U256, gas_price: U256, coin: &str) -> NumConversResult<EthTxFeeDetails> {
let total_fee = gas * gas_price;
// Fees are always paid in ETH, can use 18 decimals by default
let total_fee = u256_to_big_decimal(total_fee, ETH_DECIMALS)?;
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/lp_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::collections::HashMap;
use std::str::Utf8Error;

const PRICE_ENDPOINTS: [&str; 2] = [
"https://prices.komodo.earth/api/v2/tickers",
"https://prices.komodian.info/api/v2/tickers",
"https://prices.cipig.net:1717/api/v2/tickers",
];

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/my_tx_history_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ where
_ => {},
};

let confirmations = if details.block_height == 0 || details.block_height > current_block {
let confirmations = if details.block_height > current_block {
0
} else {
current_block + 1 - details.block_height
Expand Down
174 changes: 126 additions & 48 deletions mm2src/coins/nft.rs

Large diffs are not rendered by default.

96 changes: 76 additions & 20 deletions mm2src/coins/nft/nft_errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::eth::GetEthAddressError;
use crate::nft::storage::{CreateNftStorageError, NftStorageError};
use crate::{GetMyAddressError, WithdrawError};
#[cfg(target_arch = "wasm32")]
use crate::nft::storage::wasm::WasmNftCacheError;
use crate::nft::storage::NftStorageError;
use crate::{CoinFindError, GetMyAddressError, WithdrawError};
use common::{HttpStatusCode, ParseRfc3339Err};
#[cfg(not(target_arch = "wasm32"))]
use db_common::sqlite::rusqlite::Error as SqlError;
use derive_more::Display;
use enum_from::EnumFromStringify;
use http::StatusCode;
Expand Down Expand Up @@ -38,6 +42,7 @@ pub enum GetNftInfoError {
#[display(fmt = "The contract type is required and should not be null.")]
ContractTypeIsNull,
ProtectFromSpamError(ProtectFromSpamError),
TransferConfirmationsError(TransferConfirmationsError),
}

impl From<GetNftInfoError> for WithdrawError {
Expand Down Expand Up @@ -73,14 +78,6 @@ impl From<GetEthAddressError> for GetNftInfoError {
fn from(e: GetEthAddressError) -> Self { GetNftInfoError::GetEthAddressError(e) }
}

impl From<CreateNftStorageError> for GetNftInfoError {
fn from(e: CreateNftStorageError) -> Self {
match e {
CreateNftStorageError::Internal(err) => GetNftInfoError::Internal(err),
}
}
}

impl<T: NftStorageError> From<T> for GetNftInfoError {
fn from(err: T) -> Self { GetNftInfoError::DbError(format!("{:?}", err)) }
}
Expand All @@ -104,6 +101,14 @@ impl From<ProtectFromSpamError> for GetNftInfoError {
fn from(e: ProtectFromSpamError) -> Self { GetNftInfoError::ProtectFromSpamError(e) }
}

impl From<LockDBError> for GetNftInfoError {
fn from(e: LockDBError) -> Self { GetNftInfoError::DbError(e.to_string()) }
}

impl From<TransferConfirmationsError> for GetNftInfoError {
fn from(e: TransferConfirmationsError) -> Self { GetNftInfoError::TransferConfirmationsError(e) }
}

impl HttpStatusCode for GetNftInfoError {
fn status_code(&self) -> StatusCode {
match self {
Expand All @@ -115,7 +120,8 @@ impl HttpStatusCode for GetNftInfoError {
| GetNftInfoError::GetEthAddressError(_)
| GetNftInfoError::TokenNotFoundInWallet { .. }
| GetNftInfoError::DbError(_)
| GetNftInfoError::ProtectFromSpamError(_) => StatusCode::INTERNAL_SERVER_ERROR,
| GetNftInfoError::ProtectFromSpamError(_)
| GetNftInfoError::TransferConfirmationsError(_) => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
Expand Down Expand Up @@ -184,14 +190,14 @@ pub enum UpdateNftError {
#[from_stringify("serde_json::Error")]
SerdeError(String),
ProtectFromSpamError(ProtectFromSpamError),
}

impl From<CreateNftStorageError> for UpdateNftError {
fn from(e: CreateNftStorageError) -> Self {
match e {
CreateNftStorageError::Internal(err) => UpdateNftError::Internal(err),
}
}
#[display(fmt = "No such coin {}", coin)]
NoSuchCoin {
coin: String,
},
#[display(fmt = "{} coin doesn't support NFT", coin)]
CoinDoesntSupportNft {
coin: String,
},
}

impl From<GetNftInfoError> for UpdateNftError {
Expand All @@ -218,6 +224,18 @@ impl From<ProtectFromSpamError> for UpdateNftError {
fn from(e: ProtectFromSpamError) -> Self { UpdateNftError::ProtectFromSpamError(e) }
}

impl From<LockDBError> for UpdateNftError {
fn from(e: LockDBError) -> Self { UpdateNftError::DbError(e.to_string()) }
}

impl From<CoinFindError> for UpdateNftError {
fn from(e: CoinFindError) -> Self {
match e {
CoinFindError::NoSuchCoin { coin } => UpdateNftError::NoSuchCoin { coin },
}
}
}

impl HttpStatusCode for UpdateNftError {
fn status_code(&self) -> StatusCode {
match self {
Expand All @@ -234,7 +252,9 @@ impl HttpStatusCode for UpdateNftError {
| UpdateNftError::UpdateSpamPhishingError(_)
| UpdateNftError::GetInfoFromUriError(_)
| UpdateNftError::SerdeError(_)
| UpdateNftError::ProtectFromSpamError(_) => StatusCode::INTERNAL_SERVER_ERROR,
| UpdateNftError::ProtectFromSpamError(_)
| UpdateNftError::NoSuchCoin { .. }
| UpdateNftError::CoinDoesntSupportNft { .. } => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
Expand Down Expand Up @@ -310,3 +330,39 @@ pub(crate) enum MetaFromUrlError {
impl From<GetInfoFromUriError> for MetaFromUrlError {
fn from(e: GetInfoFromUriError) -> Self { MetaFromUrlError::GetInfoFromUriError(e) }
}

#[derive(Debug, Display)]
pub enum LockDBError {
#[cfg(target_arch = "wasm32")]
WasmNftCacheError(WasmNftCacheError),
#[cfg(not(target_arch = "wasm32"))]
SqlError(SqlError),
}

#[cfg(not(target_arch = "wasm32"))]
impl From<SqlError> for LockDBError {
fn from(e: SqlError) -> Self { LockDBError::SqlError(e) }
}

#[cfg(target_arch = "wasm32")]
impl From<WasmNftCacheError> for LockDBError {
fn from(e: WasmNftCacheError) -> Self { LockDBError::WasmNftCacheError(e) }
}

#[derive(Clone, Debug, Deserialize, Display, PartialEq, Serialize)]
pub enum TransferConfirmationsError {
#[display(fmt = "No such coin {}", coin)]
NoSuchCoin { coin: String },
#[display(fmt = "{} coin doesn't support NFT", coin)]
CoinDoesntSupportNft { coin: String },
#[display(fmt = "Get current block error: {}", _0)]
GetCurrentBlockErr(String),
}

impl From<CoinFindError> for TransferConfirmationsError {
fn from(e: CoinFindError) -> Self {
match e {
CoinFindError::NoSuchCoin { coin } => TransferConfirmationsError::NoSuchCoin { coin },
}
}
}
Loading

0 comments on commit 8313bc4

Please sign in to comment.