Skip to content

Commit

Permalink
improvide wasm stack and add wasm pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: ozkanonur <[email protected]>
  • Loading branch information
onur-ozkan committed Mar 9, 2023
1 parent 98d0594 commit 0058f71
Show file tree
Hide file tree
Showing 33 changed files with 150 additions and 174 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Code format & lint
name: CI
on:
push:
branches:
Expand Down Expand Up @@ -43,6 +43,7 @@ jobs:
run: |
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile=minimal --component rustfmt clippy
rustup default ${{ matrix.rust }}
rustup target add wasm32-unknown-unknown
- name: wasm code lint
run: cargo clippy --target wasm32-unknown-unknown --profile ci -- --D warnings
2 changes: 1 addition & 1 deletion mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4064,7 +4064,7 @@ impl MmCoin for EthCoin {
&[&"tx_history", &self.ticker],
&ERRL!("Transaction history is not supported for ETH/ERC20 coins"),
);
return Box::new(futures01::future::ok(()));
Box::new(futures01::future::ok(()))
}
cfg_native! {
let coin = self.clone();
Expand Down
1 change: 0 additions & 1 deletion mm2src/coins/eth/eth_wasm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ wasm_bindgen_test_configure!(run_in_browser);
fn pass() {
let ctx = MmCtxBuilder::default().into_mm_arc();
let _coins_context = CoinsContext::from_ctx(&ctx).unwrap();
assert_eq!(1, 1);
}

#[wasm_bindgen_test]
Expand Down
22 changes: 10 additions & 12 deletions mm2src/coins/hd_wallet_storage/wasm_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,16 @@ impl TableSignature for HDAccountTable {
fn table_name() -> &'static str { "hd_account" }

fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
match (old_version, new_version) {
(0, 1) => {
let table = upgrader.create_table(Self::table_name())?;
table.create_multi_index(WALLET_ID_INDEX, &["coin", "hd_wallet_rmd160"], false)?;
table.create_multi_index(
WALLET_ACCOUNT_ID_INDEX,
&["coin", "hd_wallet_rmd160", "account_id"],
true,
)?;
},
_ => (),
if let (0, 1) = (old_version, new_version) {
let table = upgrader.create_table(Self::table_name())?;
table.create_multi_index(WALLET_ID_INDEX, &["coin", "hd_wallet_rmd160"], false)?;
table.create_multi_index(
WALLET_ACCOUNT_ID_INDEX,
&["coin", "hd_wallet_rmd160", "account_id"],
true,
)?;
}

Ok(())
}
}
Expand Down Expand Up @@ -318,7 +316,7 @@ impl HDWalletIndexedDbStorage {

/// This function is used in `hd_wallet_storage::tests`.
pub(super) async fn get_all_storage_items(ctx: &MmArc) -> Vec<HDAccountStorageItem> {
let coins_ctx = CoinsContext::from_ctx(&ctx).unwrap();
let coins_ctx = CoinsContext::from_ctx(ctx).unwrap();
let db = coins_ctx.hd_wallet_db.get_or_initialize().await.unwrap();
let transaction = db.inner.transaction().await.unwrap();
let table = transaction.table::<HDAccountTable>().await.unwrap();
Expand Down
8 changes: 2 additions & 6 deletions mm2src/coins/tx_history_storage/tx_history_v2_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ async fn test_get_raw_tx_bytes_on_add_transactions_impl() {

let tx_hash = "6686ee013620d31ba645b27d581fed85437ce00f46b595a576718afac4dd5b69";

let maybe_tx_hex = storage.tx_bytes_from_cache(&wallet_id, &tx_hash).await.unwrap();
let maybe_tx_hex = storage.tx_bytes_from_cache(&wallet_id, tx_hash).await.unwrap();
assert!(maybe_tx_hex.is_none());

let tx1 = get_bch_tx_details("6686ee013620d31ba645b27d581fed85437ce00f46b595a576718afac4dd5b69");
Expand All @@ -409,11 +409,7 @@ async fn test_get_raw_tx_bytes_on_add_transactions_impl() {
.await
.unwrap();

let tx_hex = storage
.tx_bytes_from_cache(&wallet_id, &tx_hash)
.await
.unwrap()
.unwrap();
let tx_hex = storage.tx_bytes_from_cache(&wallet_id, tx_hash).await.unwrap().unwrap();

assert_eq!(tx_hex, expected_tx_hex);
}
Expand Down
16 changes: 8 additions & 8 deletions mm2src/coins/tx_history_storage/wasm/tx_history_storage_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ impl HistoryId {
fn new(ticker: &str, wallet_address: &str) -> HistoryId { HistoryId(format!("{}_{}", ticker, wallet_address)) }

fn as_str(&self) -> &str { &self.0 }
}

fn to_string(&self) -> String { self.0.clone() }
impl std::fmt::Display for HistoryId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &self.0) }
}

#[derive(Debug, Deserialize, Serialize)]
Expand All @@ -74,13 +76,11 @@ impl TableSignature for TxHistoryTableV1 {
fn table_name() -> &'static str { "tx_history" }

fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
match (old_version, new_version) {
(0, 1) => {
let table = upgrader.create_table(Self::table_name())?;
table.create_index("history_id", true)?;
},
_ => (),
if let (0, 1) = (old_version, new_version) {
let table = upgrader.create_table(Self::table_name())?;
table.create_index("history_id", true)?;
}

Ok(())
}
}
Expand All @@ -94,7 +94,7 @@ mod tests {

#[wasm_bindgen_test]
async fn test_tx_history() {
const DB_NAME: &'static str = "TEST_TX_HISTORY";
const DB_NAME: &str = "TEST_TX_HISTORY";
let db = TxHistoryDb::init(DbIdentifier::for_test(DB_NAME))
.await
.expect("!TxHistoryDb::init_with_fs_path");
Expand Down
58 changes: 26 additions & 32 deletions mm2src/coins/tx_history_storage/wasm/tx_history_storage_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,32 +417,29 @@ impl TableSignature for TxHistoryTableV2 {
fn table_name() -> &'static str { "tx_history_v2" }

fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
match (old_version, new_version) {
(0, 1) => {
let table = upgrader.create_table(Self::table_name())?;
table.create_multi_index(TxHistoryTableV2::WALLET_ID_INDEX, &["coin", "hd_wallet_rmd160"], false)?;
table.create_multi_index(
TxHistoryTableV2::WALLET_ID_INTERNAL_ID_INDEX,
&["coin", "hd_wallet_rmd160", "internal_id"],
true,
)?;
table.create_multi_index(
TxHistoryTableV2::WALLET_ID_TX_HASH_INDEX,
&["coin", "hd_wallet_rmd160", "tx_hash"],
false,
)?;
table.create_multi_index(
TxHistoryTableV2::WALLET_ID_CONFIRMATION_STATUS_INDEX,
&["coin", "hd_wallet_rmd160", "confirmation_status"],
false,
)?;
table.create_multi_index(
TxHistoryTableV2::WALLET_ID_TOKEN_ID_INDEX,
&["coin", "hd_wallet_rmd160", "token_id"],
false,
)?;
},
_ => (),
if let (0, 1) = (old_version, new_version) {
let table = upgrader.create_table(Self::table_name())?;
table.create_multi_index(TxHistoryTableV2::WALLET_ID_INDEX, &["coin", "hd_wallet_rmd160"], false)?;
table.create_multi_index(
TxHistoryTableV2::WALLET_ID_INTERNAL_ID_INDEX,
&["coin", "hd_wallet_rmd160", "internal_id"],
true,
)?;
table.create_multi_index(
TxHistoryTableV2::WALLET_ID_TX_HASH_INDEX,
&["coin", "hd_wallet_rmd160", "tx_hash"],
false,
)?;
table.create_multi_index(
TxHistoryTableV2::WALLET_ID_CONFIRMATION_STATUS_INDEX,
&["coin", "hd_wallet_rmd160", "confirmation_status"],
false,
)?;
table.create_multi_index(
TxHistoryTableV2::WALLET_ID_TOKEN_ID_INDEX,
&["coin", "hd_wallet_rmd160", "token_id"],
false,
)?;
}
Ok(())
}
Expand Down Expand Up @@ -474,12 +471,9 @@ impl TableSignature for TxCacheTableV2 {
fn table_name() -> &'static str { "tx_cache_v2" }

fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
match (old_version, new_version) {
(0, 1) => {
let table = upgrader.create_table(Self::table_name())?;
table.create_multi_index(TxCacheTableV2::COIN_TX_HASH_INDEX, &["coin", "tx_hash"], true)?;
},
_ => (),
if let (0, 1) = (old_version, new_version) {
let table = upgrader.create_table(Self::table_name())?;
table.create_multi_index(TxCacheTableV2::COIN_TX_HASH_INDEX, &["coin", "tx_hash"], true)?;
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions mm2src/coins/utxo/rpc_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,7 @@ enum ElectrumConfig {
}

/// Electrum client configuration
#[allow(clippy::upper_case_acronyms)]
#[cfg(target_arch = "wasm32")]
#[derive(Clone, Debug, Serialize)]
enum ElectrumConfig {
Expand Down
10 changes: 5 additions & 5 deletions mm2src/coins/utxo/utxo_block_header_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ mod block_headers_storage_tests {
let block_header: BlockHeader = "0000002076d41d3e4b0bfd4c0d3b30aa69fdff3ed35d85829efd04000000000000000000b386498b583390959d9bac72346986e3015e83ac0b54bc7747a11a494ac35c94bb3ce65a53fb45177f7e311c".into();
headers.insert(520481, block_header);
storage.add_block_headers_to_storage(headers).await.unwrap();
assert!(!storage.is_table_empty().await.is_ok());
assert!(storage.is_table_empty().await.is_err());
}

pub(crate) async fn test_get_block_header_impl(for_coin: &str) {
Expand All @@ -152,7 +152,7 @@ mod block_headers_storage_tests {
headers.insert(520481, block_header);

storage.add_block_headers_to_storage(headers).await.unwrap();
assert!(!storage.is_table_empty().await.is_ok());
assert!(storage.is_table_empty().await.is_err());

let hex = storage.get_block_header_raw(520481).await.unwrap().unwrap();
assert_eq!(hex, "0000002076d41d3e4b0bfd4c0d3b30aa69fdff3ed35d85829efd04000000000000000000b386498b583390959d9bac72346986e3015e83ac0b54bc7747a11a494ac35c94bb3ce65a53fb45177f7e311c".to_string());
Expand Down Expand Up @@ -189,7 +189,7 @@ mod block_headers_storage_tests {
headers.insert(201593, block_header);

storage.add_block_headers_to_storage(headers).await.unwrap();
assert!(!storage.is_table_empty().await.is_ok());
assert!(storage.is_table_empty().await.is_err());

let actual_block_header = storage
.get_last_block_header_with_non_max_bits(MAX_BITS_BTC)
Expand Down Expand Up @@ -222,7 +222,7 @@ mod block_headers_storage_tests {
headers.insert(201593, block_header);

storage.add_block_headers_to_storage(headers).await.unwrap();
assert!(!storage.is_table_empty().await.is_ok());
assert!(storage.is_table_empty().await.is_err());

let last_block_height = storage.get_last_block_height().await.unwrap();
assert_eq!(last_block_height.unwrap(), 201595);
Expand Down Expand Up @@ -250,7 +250,7 @@ mod block_headers_storage_tests {
headers.insert(201593, block_header);

storage.add_block_headers_to_storage(headers).await.unwrap();
assert!(!storage.is_table_empty().await.is_ok());
assert!(storage.is_table_empty().await.is_err());

// Remove 2 headers from storage.
storage.remove_headers_up_to_height(201594).await.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ impl TableSignature for BlockHeaderStorageTable {
fn table_name() -> &'static str { "block_header_storage_cache_table" }

fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
match (old_version, new_version) {
(0, 1) => {
let table = upgrader.create_table(Self::table_name())?;
table.create_multi_index(Self::TICKER_HEIGHT_INDEX, &["ticker", "height"], true)?;
table.create_multi_index(Self::HASH_TICKER_INDEX, &["hash", "ticker"], true)?;
table.create_index("ticker", false)?;
},
_ => (),
if let (0, 1) = (old_version, new_version) {
let table = upgrader.create_table(Self::table_name())?;
table.create_multi_index(Self::TICKER_HEIGHT_INDEX, &["ticker", "height"], true)?;
table.create_multi_index(Self::HASH_TICKER_INDEX, &["hash", "ticker"], true)?;
table.create_index("ticker", false)?;
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl BlockHeaderStorageOps for IDBBlockHeadersStorage {
let index_keys = MultiIndex::new(BlockHeaderStorageTable::TICKER_HEIGHT_INDEX)
.with_value(&ticker)
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?
.with_value(&BeBigUint::from(height))
.with_value(BeBigUint::from(height))
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?;

block_headers_db
Expand Down Expand Up @@ -152,7 +152,7 @@ impl BlockHeaderStorageOps for IDBBlockHeadersStorage {
let index_keys = MultiIndex::new(BlockHeaderStorageTable::TICKER_HEIGHT_INDEX)
.with_value(&ticker)
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?
.with_value(&BeBigUint::from(height))
.with_value(BeBigUint::from(height))
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?;

Ok(block_headers_db
Expand Down Expand Up @@ -281,7 +281,7 @@ impl BlockHeaderStorageOps for IDBBlockHeadersStorage {
.await
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?;
let index_keys = MultiIndex::new(BlockHeaderStorageTable::HASH_TICKER_INDEX)
.with_value(&hash.to_string())
.with_value(hash.to_string())
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?
.with_value(&ticker)
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?;
Expand Down Expand Up @@ -320,7 +320,7 @@ impl BlockHeaderStorageOps for IDBBlockHeadersStorage {
let index_keys = MultiIndex::new(BlockHeaderStorageTable::TICKER_HEIGHT_INDEX)
.with_value(&ticker)
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?
.with_value(&BeBigUint::from(height))
.with_value(BeBigUint::from(height))
.map_err(|err| BlockHeaderStorageError::table_err(&ticker, err.to_string()))?;

block_headers_db
Expand Down
6 changes: 3 additions & 3 deletions mm2src/coins/utxo/utxo_common_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use std::convert::TryFrom;
use std::num::NonZeroUsize;
use std::time::Duration;

pub(super) const TEST_COIN_NAME: &'static str = "RICK";
pub(super) const TEST_COIN_NAME: &str = "RICK";
// Made-up hrp for rick to test p2wpkh script
pub(super) const TEST_COIN_HRP: &'static str = "rck";
pub(super) const TEST_COIN_HRP: &str = "rck";
pub(super) const TEST_COIN_DECIMALS: u8 = 8;

const MORTY_HD_TX_HISTORY_STR: &str = include_str!("../for_tests/MORTY_HD_tx_history_fixtures.json");
Expand Down Expand Up @@ -185,7 +185,7 @@ pub(super) fn get_morty_hd_transactions_ordered(tx_hashes: &[&str]) -> Vec<Trans
.map(|tx_hash| {
MORTY_HD_TX_HISTORY_MAP
.get(*tx_hash)
.expect(&format!("No such {tx_hash:?} TX in the file"))
.unwrap_or_else(|| panic!("No such {:?} TX in the file", tx_hash))
.clone()
})
.sorted_by(compare_transaction_details)
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/utxo_wasm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

const TEST_COIN_NAME: &'static str = "RICK";
const TEST_COIN_NAME: &str = "RICK";

pub async fn electrum_client_for_test(servers: &[&str]) -> ElectrumClient {
let ctx = MmCtxBuilder::default().into_mm_arc();
Expand Down
2 changes: 1 addition & 1 deletion mm2src/crypto/src/metamask_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl MetamaskCtx {
.await?;

let sig = sig.strip_prefix("0x").unwrap_or(&sig);
let signature = Signature::from_str(&sig)
let signature = Signature::from_str(sig)
.map_to_mm(|_| MetamaskError::Internal(format!("'{sig}' signature is invalid")))?;
let pubkey = recover_pubkey(hash, signature).mm_err(|_| {
let error = format!("Couldn't recover a public key from the signature: '{sig}'");
Expand Down
3 changes: 3 additions & 0 deletions mm2src/mm2_bin_lib/src/mm2_bin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#[cfg(not(target_arch = "wasm32"))] use mm2_main::mm2::mm2_main;

#[cfg(not(target_arch = "wasm32"))]
const MM_VERSION: &str = env!("MM_VERSION");

#[cfg(not(target_arch = "wasm32"))]
const MM_DATETIME: &str = env!("MM_DATETIME");

#[cfg(all(target_os = "linux", target_arch = "x86_64", target_env = "gnu"))]
Expand Down
6 changes: 3 additions & 3 deletions mm2src/mm2_db/src/indexed_db/db_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<Db: DbInstance> ConstructibleDb<Db> {
ConstructibleDb {
mutex: AsyncMutex::new(None),
db_namespace: ctx.db_namespace,
wallet_rmd160: ctx.rmd160().clone(),
wallet_rmd160: *ctx.rmd160(),
}
}

Expand All @@ -37,7 +37,7 @@ impl<Db: DbInstance> ConstructibleDb<Db> {
ConstructibleDb {
mutex: AsyncMutex::new(None),
db_namespace: ctx.db_namespace,
wallet_rmd160: ctx.shared_db_id().clone(),
wallet_rmd160: *ctx.shared_db_id(),
}
}

Expand All @@ -50,7 +50,7 @@ impl<Db: DbInstance> ConstructibleDb<Db> {
return Ok(unwrap_db_instance(locked_db));
}

let db_id = DbIdentifier::new::<Db>(self.db_namespace, self.wallet_rmd160.clone());
let db_id = DbIdentifier::new::<Db>(self.db_namespace, self.wallet_rmd160);

let db = Db::init(db_id).await?;
*locked_db = Some(db);
Expand Down
Loading

0 comments on commit 0058f71

Please sign in to comment.