Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nft): exclude spam and phishing, refactored db #1959

Merged
merged 50 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6102d90
impl functions to update spam in native, unit tests added.
laruh Aug 28, 2023
40c5739
Merge remote-tracking branch 'origin/dev' into spam-phishing-nft
laruh Aug 28, 2023
d31ca2a
update_spam func, db impls for wasm, additional unit tests
laruh Aug 29, 2023
a1f8655
use separated fields in nft sql tables
laruh Sep 1, 2023
2e4a24a
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Sep 1, 2023
79a468c
add `path_to_address`
laruh Sep 1, 2023
e3526c3
split antispam tests
laruh Sep 1, 2023
7d55445
exclude spam phishing impls
laruh Sep 4, 2023
e1f2b1c
check update_spam logs
laruh Sep 4, 2023
e7b9162
add more doc comments
laruh Sep 4, 2023
7fea1e2
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Sep 4, 2023
f5a142b
doc comments
laruh Sep 5, 2023
0ba06ef
impl `to_table_name` fncs, `filter_nfts` and `filter_transfers`,use H…
laruh Sep 6, 2023
3ae16b8
remove Chain ref in some db methods
laruh Sep 6, 2023
c91fccb
move common consts in wasm_storage
laruh Sep 6, 2023
d698708
use iter
laruh Sep 6, 2023
220d672
lock db after getting items
laruh Sep 6, 2023
62796e9
dont use several locks in wasm storage methods, limit const endpoints…
laruh Sep 7, 2023
a47dcb3
don't scan spam contracts if there are no token addresses
laruh Sep 8, 2023
f6c91ed
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Sep 8, 2023
0ae9b3e
doc comments
laruh Sep 8, 2023
9b6e297
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Sep 11, 2023
3c697e5
remove redundant doc com
laruh Sep 12, 2023
b3c10c6
use ref to chain.to_string()
laruh Sep 13, 2023
58ba7ae
add unit tests for camo
laruh Sep 14, 2023
46c9a08
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Sep 14, 2023
410330a
send req to camo to get `UriMeta` from `token_uri`
laruh Sep 15, 2023
50aefef
doc com for DbInstance
laruh Sep 18, 2023
5ebc974
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Sep 19, 2023
060081d
update_phishing fnc, storage methods and unit test
laruh Sep 19, 2023
83206e4
test update phishing, polish refresh metadata
laruh Sep 20, 2023
45d26dd
process text/metadata for spam links, use set_spam in update_transfer…
laruh Sep 21, 2023
935d375
add indexes for NftListTable
laruh Sep 21, 2023
6f33a11
move `cannot_be_a_base` at the beginning of construct camo
laruh Sep 22, 2023
f35e9b6
remove repetitive code in wasm update phishing
laruh Sep 22, 2023
9abc1e8
use match url.path_segments_mut()
laruh Sep 22, 2023
1545ff9
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Sep 22, 2023
42719f3
move `hex_token_uri`
laruh Sep 22, 2023
a7185eb
add cross tests
laruh Sep 23, 2023
840a3a1
leave only cross tests
laruh Sep 23, 2023
bae45b8
protect_from_nft_spam_links, ignore get meta from moralis error
laruh Sep 24, 2023
dd22837
test exclude phishing and spam
laruh Sep 25, 2023
df19597
remove MnemonicHQ endpoint
laruh Sep 26, 2023
3b8108b
polish handle_receive_erc
laruh Sep 26, 2023
e228715
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Oct 3, 2023
9275544
url.path_segments_mut().ok(), move cross_test! to common.rs
laruh Oct 3, 2023
932364e
use const `DB_NAME` for trait `DbInstance`
laruh Oct 5, 2023
92e088e
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Oct 8, 2023
34229a9
dont send scan spam/phishing req in refresh funct if value is `true`
laruh Oct 13, 2023
b147b43
Merge remote-tracking branch 'origin/dev' into spam-nft-refactor-db
laruh Oct 25, 2023
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
3 changes: 1 addition & 2 deletions mm2src/coins/hd_wallet_storage/wasm_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use mm2_db::indexed_db::{DbIdentifier, DbInstance, DbLocked, DbTable, DbTransact
TableSignature, WeakDb};
use mm2_err_handle::prelude::*;

const DB_NAME: &str = "hd_wallet";
const DB_VERSION: u32 = 1;
/// An index of the `HDAccountTable` table that consists of the following properties:
/// * coin - coin ticker
Expand Down Expand Up @@ -142,7 +141,7 @@ pub struct HDWalletDb {

#[async_trait]
impl DbInstance for HDWalletDb {
fn db_name() -> &'static str { DB_NAME }
const DB_NAME: &'static str = "hd_wallet";

async fn init(db_id: DbIdentifier) -> InitDbResult<Self> {
let inner = IndexedDbBuilder::new(db_id)
Expand Down
847 changes: 616 additions & 231 deletions mm2src/coins/nft.rs

Large diffs are not rendered by default.

103 changes: 86 additions & 17 deletions mm2src/coins/nft/nft_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use common::{HttpStatusCode, ParseRfc3339Err};
use derive_more::Display;
use enum_from::EnumFromStringify;
use http::StatusCode;
use mm2_net::transport::SlurpError;
use mm2_net::transport::{GetInfoFromUriError, SlurpError};
use serde::{Deserialize, Serialize};
use web3::Error;

/// Enumerates potential errors that can arise when fetching NFT information.
#[derive(Clone, Debug, Deserialize, Display, EnumFromStringify, PartialEq, Serialize, SerializeErrorType)]
#[serde(tag = "error_type", content = "error_data")]
pub enum GetNftInfoError {
Expand Down Expand Up @@ -119,6 +120,16 @@ impl HttpStatusCode for GetNftInfoError {
}
}

/// Enumerates possible errors that can occur while updating NFT details in the database.
///
/// The errors capture various issues that can arise during:
/// - Metadata refresh
/// - NFT transfer history updating
/// - NFT list updating
///
/// The issues addressed include database errors, invalid hex strings,
/// inconsistencies in block numbers, and problems related to fetching or interpreting
/// fetched metadata.
#[derive(Clone, Debug, Deserialize, Display, EnumFromStringify, PartialEq, Serialize, SerializeErrorType)]
#[serde(tag = "error_type", content = "error_data")]
pub enum UpdateNftError {
Expand Down Expand Up @@ -168,6 +179,11 @@ pub enum UpdateNftError {
},
#[display(fmt = "Invalid hex string: {}", _0)]
InvalidHexString(String),
UpdateSpamPhishingError(UpdateSpamPhishingError),
GetInfoFromUriError(GetInfoFromUriError),
#[from_stringify("serde_json::Error")]
SerdeError(String),
ProtectFromSpamError(ProtectFromSpamError),
}

impl From<CreateNftStorageError> for UpdateNftError {
Expand All @@ -190,6 +206,18 @@ impl<T: NftStorageError> From<T> for UpdateNftError {
fn from(err: T) -> Self { UpdateNftError::DbError(format!("{:?}", err)) }
}

impl From<UpdateSpamPhishingError> for UpdateNftError {
fn from(e: UpdateSpamPhishingError) -> Self { UpdateNftError::UpdateSpamPhishingError(e) }
}

impl From<GetInfoFromUriError> for UpdateNftError {
fn from(e: GetInfoFromUriError) -> Self { UpdateNftError::GetInfoFromUriError(e) }
}

impl From<ProtectFromSpamError> for UpdateNftError {
fn from(e: ProtectFromSpamError) -> Self { UpdateNftError::ProtectFromSpamError(e) }
}

impl HttpStatusCode for UpdateNftError {
fn status_code(&self) -> StatusCode {
match self {
Expand All @@ -202,15 +230,35 @@ impl HttpStatusCode for UpdateNftError {
| UpdateNftError::InvalidBlockOrder { .. }
| UpdateNftError::LastScannedBlockNotFound { .. }
| UpdateNftError::AttemptToReceiveAlreadyOwnedErc721 { .. }
| UpdateNftError::InvalidHexString(_) => StatusCode::INTERNAL_SERVER_ERROR,
| UpdateNftError::InvalidHexString(_)
| UpdateNftError::UpdateSpamPhishingError(_)
| UpdateNftError::GetInfoFromUriError(_)
| UpdateNftError::SerdeError(_)
| UpdateNftError::ProtectFromSpamError(_) => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}

/// Enumerates the errors that can occur during spam protection operations.
///
/// This includes issues such as regex failures during text validation and
/// serialization/deserialization problems.
#[derive(Clone, Debug, Deserialize, Display, EnumFromStringify, PartialEq, Serialize)]
pub(crate) enum GetInfoFromUriError {
/// `http::Error` can appear on an HTTP request [`http::Builder::build`] building.
#[from_stringify("http::Error")]
pub enum ProtectFromSpamError {
#[from_stringify("regex::Error")]
RegexError(String),
#[from_stringify("serde_json::Error")]
SerdeError(String),
}

/// An enumeration representing the potential errors encountered
/// during the process of updating spam or phishing-related information.
///
/// This error set captures various failures, from request malformation
/// to database interaction errors, providing a comprehensive view of
/// possible issues during the spam/phishing update operations.
#[derive(Clone, Debug, Deserialize, Display, EnumFromStringify, PartialEq, Serialize)]
pub enum UpdateSpamPhishingError {
#[display(fmt = "Invalid request: {}", _0)]
InvalidRequest(String),
#[display(fmt = "Transport: {}", _0)]
Expand All @@ -220,24 +268,45 @@ pub(crate) enum GetInfoFromUriError {
InvalidResponse(String),
#[display(fmt = "Internal: {}", _0)]
Internal(String),
#[display(fmt = "DB error {}", _0)]
DbError(String),
GetMyAddressError(GetMyAddressError),
}

impl From<SlurpError> for GetInfoFromUriError {
fn from(e: SlurpError) -> Self {
let error_str = e.to_string();
impl From<GetMyAddressError> for UpdateSpamPhishingError {
fn from(e: GetMyAddressError) -> Self { UpdateSpamPhishingError::GetMyAddressError(e) }
}

impl From<GetInfoFromUriError> for UpdateSpamPhishingError {
fn from(e: GetInfoFromUriError) -> Self {
match e {
SlurpError::ErrorDeserializing { .. } => GetInfoFromUriError::InvalidResponse(error_str),
SlurpError::Transport { .. } | SlurpError::Timeout { .. } => GetInfoFromUriError::Transport(error_str),
SlurpError::InvalidRequest(_) => GetInfoFromUriError::InvalidRequest(error_str),
SlurpError::Internal(_) => GetInfoFromUriError::Internal(error_str),
GetInfoFromUriError::InvalidRequest(e) => UpdateSpamPhishingError::InvalidRequest(e),
GetInfoFromUriError::Transport(e) => UpdateSpamPhishingError::Transport(e),
GetInfoFromUriError::InvalidResponse(e) => UpdateSpamPhishingError::InvalidResponse(e),
GetInfoFromUriError::Internal(e) => UpdateSpamPhishingError::Internal(e),
}
}
}

#[derive(Clone, Debug, Deserialize, Display, EnumFromStringify, PartialEq, Serialize)]
pub enum ProtectFromSpamError {
#[from_stringify("regex::Error")]
RegexError(String),
impl<T: NftStorageError> From<T> for UpdateSpamPhishingError {
fn from(err: T) -> Self { UpdateSpamPhishingError::DbError(format!("{:?}", err)) }
}

/// Errors encountered when parsing a `Chain` from a string.
#[derive(Debug, Display)]
pub enum ParseChainTypeError {
/// The provided string does not correspond to any of the supported blockchain types.
UnsupportedChainType,
}

#[derive(Debug, Display, EnumFromStringify)]
pub(crate) enum MetaFromUrlError {
#[from_stringify("serde_json::Error")]
SerdeError(String),
#[display(fmt = "Invalid response: {}", _0)]
InvalidResponse(String),
GetInfoFromUriError(GetInfoFromUriError),
}

impl From<GetInfoFromUriError> for MetaFromUrlError {
fn from(e: GetInfoFromUriError) -> Self { MetaFromUrlError::GetInfoFromUriError(e) }
}
Loading
Loading