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): introduce db cache support (non-wasm target) #1833

Merged
merged 84 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
7a62de0
draft
laruh Apr 3, 2023
350f1d5
wip
laruh Apr 5, 2023
08ba26c
wip
laruh Apr 6, 2023
7d0edf1
wip
laruh Apr 10, 2023
5df609e
remove StorageFactory
laruh Apr 10, 2023
b0d965f
add wasm target in NftStorageBuilder::build
laruh Apr 10, 2023
6d12a42
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Apr 10, 2023
6d84038
add StorageOps todos
laruh Apr 10, 2023
9ef02b7
impl trait err for target err
laruh Apr 11, 2023
67133a2
change functions in Ops
laruh Apr 11, 2023
f935e5a
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Apr 11, 2023
f249593
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Apr 12, 2023
2d66f8f
wasm: add lock_db fn and From IDB errors
laruh Apr 12, 2023
9225e99
wasm: change name
laruh Apr 12, 2023
9f977f3
sql: table names
laruh Apr 12, 2023
de5cff6
sql: save create table commands
laruh Apr 13, 2023
65c702b
sql: init fnc
laruh Apr 13, 2023
52b3c32
sql: is_initialized_for fnc
laruh Apr 13, 2023
6d34df5
remove wip, leave draft
laruh Apr 20, 2023
9bf6453
add possible_spam
laruh Apr 21, 2023
0a19dba
unite traits
laruh Apr 23, 2023
9e2b935
fmt
laruh Apr 23, 2023
8349de1
wip
laruh Apr 23, 2023
d2e0653
save wip state, moralis was removed from get_nft_list
laruh Apr 24, 2023
3e5cd51
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Apr 24, 2023
7ba5c30
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Apr 25, 2023
64fa485
save state
laruh Apr 28, 2023
b37f9a8
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Apr 28, 2023
844c9e5
get_nft_list with storage
laruh Apr 28, 2023
d9c36a5
add get_nft method
laruh Apr 28, 2023
62ebf79
optimize get_nft_list_builder_preimage
laruh Apr 28, 2023
9811680
fix fmt
laruh Apr 28, 2023
d652772
wip update_nft
laruh Apr 30, 2023
190aba3
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Apr 30, 2023
8a64b4a
wip update_nft
laruh May 1, 2023
330af7a
wip update_nft
laruh May 1, 2023
c31baa0
add tx to history
laruh May 3, 2023
590cb76
wip get table
laruh May 4, 2023
8cc5413
possible_spam bool
laruh May 4, 2023
9bae1af
fix get methods
laruh May 4, 2023
1b10b14
filters send and receive
laruh May 5, 2023
12d0b60
from to filters in history
laruh May 5, 2023
429161a
get nft and latest block, delete nft
laruh May 7, 2023
d5efb28
get_nft_metadata
laruh May 7, 2023
e68155c
refresh_nft_metadata
laruh May 7, 2023
106e18d
save update nft
laruh May 8, 2023
3d5dd43
order by block_number ASC for get txs from block
laruh May 9, 2023
6fc16cf
order_desc for nft_list.block_number and nft_history.block_timestamp …
laruh May 9, 2023
2e70203
impl last scanned block
laruh May 9, 2023
c08d996
update only amount when some erc1155 tokens were sent or received
laruh May 15, 2023
342491c
fix last_scanned_block logic
laruh May 15, 2023
16f028b
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh May 19, 2023
158542c
add uri meta, impl update collection name in txs history
laruh May 21, 2023
cb29933
find wallet_amount in withdraw_erc1155
laruh May 22, 2023
7941fe3
todos in wasm target
laruh May 22, 2023
3323643
update empty meta in txs
laruh May 22, 2023
9947d97
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh May 25, 2023
4d2e5e2
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh May 26, 2023
94b9fe8
fix conflicts
laruh May 26, 2023
b67e5e1
add todos in wasm target
laruh May 26, 2023
ef7bf54
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh May 26, 2023
54220c3
split update nft into fns, add TxMeta, add RefreshMetadataReq
laruh May 28, 2023
e3d19f1
send and receive filters fix
laruh May 28, 2023
be984ef
move nft wasm db into wasm module, add tables into wasm
laruh May 31, 2023
76e2505
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Jun 1, 2023
38814e4
use ok_or_else when get_nft()
laruh Jun 1, 2023
f919a37
use pub(crate) for mod nft_storage, move import below it
laruh Jun 1, 2023
217c199
allow(dead_code) for RemoveNftResult
laruh Jun 1, 2023
9c1e2f4
error in union_sql_strings, Some for date filters,remove nft_table_bu…
laruh Jun 4, 2023
8291f20
make mod storage
laruh Jun 5, 2023
a45fd13
use prepared stmt in get_nft_list, get_tx_history
laruh Jun 6, 2023
4f16c82
move impl nft errors from lp_coins into nft mod
laruh Jun 6, 2023
72a85c1
use u64 timestamp for block_timestamp in tx history
laruh Jun 6, 2023
e80c4b0
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Jun 9, 2023
02b9f5f
make contract_type in NftTransferHistory optional
laruh Jun 9, 2023
464dbdf
polish code in update_nft, move ParseTimestampError from Internal, ad…
laruh Jun 12, 2023
8be6ab0
make contract_type mandatory
laruh Jun 12, 2023
8e3be13
contract_type is some check
laruh Jun 14, 2023
5ca2933
match contract_type, NOT_FOUND contract_type
laruh Jun 16, 2023
5df10a8
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Jun 18, 2023
0936e01
use try_into in parse_rfc3339
laruh Jun 20, 2023
db86a67
make error format prettier, SlurpError::InvalidRequest as InvalidRequ…
laruh Jun 21, 2023
0761425
Merge remote-tracking branch 'origin/dev' into add-nft-cache-support
laruh Jun 21, 2023
e612d1f
match SlurpError::InvalidRequest with GetInfoFromUriError::InvalidReq…
laruh Jun 21, 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
23 changes: 7 additions & 16 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
//
use super::eth::Action::{Call, Create};
use crate::lp_price::get_base_price_in_rel;
use crate::nft::nft_structs::{ContractType, ConvertChain, NftListReq, TransactionNftDetails, WithdrawErc1155,
WithdrawErc721};
use crate::nft::nft_structs::{ContractType, ConvertChain, TransactionNftDetails, WithdrawErc1155, WithdrawErc721};
use async_trait::async_trait;
use bitcrypto::{keccak256, ripemd160, sha256};
use common::custom_futures::repeatable::{Ready, Retry, RetryOnError};
Expand Down Expand Up @@ -67,7 +66,6 @@ use std::ops::Deref;
use std::str::FromStr;
use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering};
use std::sync::{Arc, Mutex};
use url::Url;
use web3::types::{Action as TraceAction, BlockId, BlockNumber, Bytes, CallRequest, FilterBuilder, Log, Trace,
TraceFilterBuilder, Transaction as Web3Transaction, TransactionId, U64};
use web3::{self, Web3};
Expand Down Expand Up @@ -107,7 +105,7 @@ pub use rlp;
mod web3_transport;

#[path = "eth/v2_activation.rs"] pub mod v2_activation;
use crate::nft::{find_wallet_amount, WithdrawNftResult};
use crate::nft::{find_wallet_nft_amount, WithdrawNftResult};
use v2_activation::{build_address_and_priv_key_policy, EthActivationV2Error};

mod nonce;
Expand Down Expand Up @@ -875,26 +873,19 @@ 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, url: Url) -> WithdrawNftResult {
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 (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()?;

// todo check amount in nft cache, instead of sending new moralis req
// dont use `get_nft_metadata` for erc1155, it can return info related to other owner.
let nft_req = NftListReq {
chains: vec![withdraw_type.chain],
url,
};
let wallet_amount = find_wallet_amount(
ctx,
nft_req,
withdraw_type.token_address.clone(),
let wallet_amount = find_wallet_nft_amount(
&ctx,
&withdraw_type.chain,
withdraw_type.token_address.to_lowercase(),
withdraw_type.token_id.clone(),
)
.await?;

let amount_dec = if withdraw_type.max {
wallet_amount.clone()
} else {
Expand Down
17 changes: 11 additions & 6 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ cfg_wasm32! {
use mm2_db::indexed_db::{ConstructibleDb, DbLocked, SharedDb};
use tx_history_storage::wasm::{clear_tx_history, load_tx_history, save_tx_history, TxHistoryDb};
pub type TxHistoryDbLocked<'a> = DbLocked<'a, TxHistoryDb>;
use nft::storage::wasm::nft_idb::NftCacheIDB;
}

// using custom copy of try_fus as futures crate was renamed to futures01
Expand Down Expand Up @@ -359,7 +360,7 @@ impl From<CoinFindError> for RawTransactionError {
}
}

#[derive(Debug, Deserialize, Display, EnumFromStringify, Serialize, SerializeErrorType)]
#[derive(Clone, Debug, Deserialize, Display, EnumFromStringify, PartialEq, Serialize, SerializeErrorType)]
#[serde(tag = "error_type", content = "error_data")]
pub enum GetMyAddressError {
CoinsConfCheckError(String),
Expand Down Expand Up @@ -1921,10 +1922,8 @@ pub enum WithdrawError {
available: BigDecimal,
required: BigDecimal,
},
}

impl From<GetNftInfoError> for WithdrawError {
fn from(e: GetNftInfoError) -> Self { WithdrawError::GetNftInfoError(e) }
#[display(fmt = "DB error {}", _0)]
DbError(String),
}

impl HttpStatusCode for WithdrawError {
Expand Down Expand Up @@ -1953,7 +1952,9 @@ impl HttpStatusCode for WithdrawError {
WithdrawError::HwError(_) => StatusCode::GONE,
#[cfg(target_arch = "wasm32")]
WithdrawError::BroadcastExpected(_) => StatusCode::BAD_REQUEST,
WithdrawError::Transport(_) | WithdrawError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
WithdrawError::Transport(_) | WithdrawError::InternalError(_) | WithdrawError::DbError(_) => {
StatusCode::INTERNAL_SERVER_ERROR
},
}
}
}
Expand Down Expand Up @@ -2541,6 +2542,8 @@ pub struct CoinsContext {
tx_history_db: SharedDb<TxHistoryDb>,
#[cfg(target_arch = "wasm32")]
hd_wallet_db: SharedDb<HDWalletDb>,
#[cfg(target_arch = "wasm32")]
pub nft_cache_db: SharedDb<NftCacheIDB>,
}

#[derive(Debug)]
Expand All @@ -2565,6 +2568,8 @@ impl CoinsContext {
tx_history_db: ConstructibleDb::new(ctx).into_shared(),
#[cfg(target_arch = "wasm32")]
hd_wallet_db: ConstructibleDb::new_shared_db(ctx).into_shared(),
#[cfg(target_arch = "wasm32")]
nft_cache_db: ConstructibleDb::new(ctx).into_shared(),
})
})))
}
Expand Down
Loading