Skip to content

Commit 33af1f5

Browse files
authored
feat(zcoin): ARRR WASM implementation (#1957)
1 parent af57160 commit 33af1f5

File tree

61 files changed

+5657
-1162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5657
-1162
lines changed

Cargo.lock

Lines changed: 260 additions & 175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mm2src/coins/Cargo.toml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ uuid = { version = "1.2.2", features = ["fast-rng", "serde", "v4"] }
107107
# We don't need the default web3 features at all since we added our own web3 transport using shared HYPER instance.
108108
web3 = { git = "https://github.com/KomodoPlatform/rust-web3", tag = "v0.19.0", default-features = false }
109109
zbase32 = "0.1.2"
110-
zcash_client_backend = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
111-
zcash_primitives = { features = ["transparent-inputs"], git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
112-
zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
110+
zcash_client_backend = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.0" }
111+
zcash_extras = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.0" }
112+
zcash_primitives = {features = ["transparent-inputs"], git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.0" }
113113

114114
[target.'cfg(all(not(target_os = "ios"), not(target_os = "android"), not(target_arch = "wasm32")))'.dependencies]
115115
bincode = { version = "1.3.3", default-features = false, optional = true }
@@ -121,15 +121,23 @@ spl-token = { version = "3", optional = true }
121121
spl-associated-token-account = { version = "1", optional = true }
122122

123123
[target.'cfg(target_arch = "wasm32")'.dependencies]
124+
blake2b_simd = "0.5"
125+
ff = "0.8"
126+
futures-util = "0.3"
124127
instant = "0.1.12"
128+
jubjub = "0.5.1"
125129
js-sys = { version = "0.3.27" }
126130
mm2_db = { path = "../mm2_db" }
127131
mm2_metamask = { path = "../mm2_metamask" }
128132
mm2_test_helpers = { path = "../mm2_test_helpers" }
133+
time = { version = "0.3.20", features = ["wasm-bindgen"] }
134+
tonic = { version = "0.7", default-features = false, features = ["prost", "codegen", "compression"] }
135+
tower-service = "0.3"
129136
wasm-bindgen = "0.2.86"
130137
wasm-bindgen-futures = { version = "0.4.1" }
131138
wasm-bindgen-test = { version = "0.3.2" }
132139
web-sys = { version = "0.3.55", features = ["console", "Headers", "Request", "RequestInit", "RequestMode", "Response", "Window"] }
140+
zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.0", default-features = false, features = ["local-prover"] }
133141

134142
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
135143
dirs = { version = "1" }
@@ -151,14 +159,18 @@ tokio = { version = "1.20" }
151159
tokio-rustls = { version = "0.23" }
152160
tonic = { version = "0.7", features = ["tls", "tls-webpki-roots", "compression"] }
153161
webpki-roots = { version = "0.22" }
154-
zcash_client_sqlite = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
162+
zcash_client_sqlite = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.0" }
163+
zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.0", default-features =false, features = ["local-prover", "multicore"] }
155164

156165
[target.'cfg(windows)'.dependencies]
157166
winapi = "0.3"
158167

159168
[dev-dependencies]
160169
mm2_test_helpers = { path = "../mm2_test_helpers" }
161170

171+
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
172+
wagyu-zcash-parameters = { version = "0.2" }
173+
162174
[build-dependencies]
163175
prost-build = { version = "0.10.4", default-features = false }
164-
tonic-build = { version = "0.7", features = ["prost", "compression"] }
176+
tonic-build = { version = "0.7", default-features = false, features = ["prost", "compression"] }

mm2src/coins/eth/eth_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::*;
22
use crate::{DexFee, IguanaPrivKey};
33
use common::{block_on, now_sec};
44
use crypto::privkey::key_pair_from_seed;
5+
#[cfg(not(target_arch = "wasm32"))]
56
use ethkey::{Generator, Random};
67
use mm2_core::mm_ctx::{MmArc, MmCtxBuilder};
78
use mm2_test_helpers::{for_tests::{eth_jst_testnet_conf, eth_testnet_conf, ETH_DEV_NODE, ETH_DEV_NODES,
@@ -88,6 +89,7 @@ fn eth_coin_for_test(
8889
eth_coin_from_keypair(coin_type, urls, fallback_swap_contract, key_pair)
8990
}
9091

92+
#[cfg(not(target_arch = "wasm32"))]
9193
fn random_eth_coin_for_test(
9294
coin_type: EthCoinType,
9395
urls: &[&str],
@@ -157,6 +159,7 @@ fn eth_coin_from_keypair(
157159
(ctx, eth_coin)
158160
}
159161

162+
#[cfg(not(target_arch = "wasm32"))]
160163
pub fn fill_eth(to_addr: Address, amount: f64) {
161164
let wei_per_eth: u64 = 1_000_000_000_000_000_000;
162165
let amount_in_wei = (amount * wei_per_eth as f64) as u64;
@@ -464,6 +467,7 @@ fn test_gas_station() {
464467
assert_eq!(expected_eth_polygon, res_polygon);
465468
}
466469

470+
#[cfg(not(target_arch = "wasm32"))]
467471
#[test]
468472
fn test_withdraw_impl_manual_fee() {
469473
let (_ctx, coin) = eth_coin_for_test(EthCoinType::Eth, &["http://dummy.dummy"], None);
@@ -501,6 +505,7 @@ fn test_withdraw_impl_manual_fee() {
501505
assert_eq!(expected, tx_details.fee_details);
502506
}
503507

508+
#[cfg(not(target_arch = "wasm32"))]
504509
#[test]
505510
fn test_withdraw_impl_fee_details() {
506511
let (_ctx, coin) = eth_coin_for_test(

mm2src/coins/eth/web3_transport/http_transport.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ async fn send_request_once(
326326
event_handlers: &Vec<RpcTransportEventHandlerShared>,
327327
) -> Result<Json, Error> {
328328
use http::header::ACCEPT;
329-
use mm2_net::wasm_http::FetchRequest;
329+
use mm2_net::wasm::http::FetchRequest;
330330

331331
// account for outgoing traffic
332332
event_handlers.on_outgoing_request(request_payload.as_bytes());

mm2src/coins/hd_wallet_storage/wasm_storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ pub struct HDAccountTable {
9494
}
9595

9696
impl TableSignature for HDAccountTable {
97-
fn table_name() -> &'static str { "hd_account" }
97+
const TABLE_NAME: &'static str = "hd_account";
9898

9999
fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
100100
if let (0, 1) = (old_version, new_version) {
101-
let table = upgrader.create_table(Self::table_name())?;
101+
let table = upgrader.create_table(Self::TABLE_NAME)?;
102102
table.create_multi_index(WALLET_ID_INDEX, &["coin", "hd_wallet_rmd160"], false)?;
103103
table.create_multi_index(
104104
WALLET_ACCOUNT_ID_INDEX,

mm2src/coins/lp_price.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ async fn process_price_request(price_url: &str) -> Result<TickerInfosRegistry, M
200200
#[cfg(target_arch = "wasm32")]
201201
async fn process_price_request(price_url: &str) -> Result<TickerInfosRegistry, MmError<PriceServiceRequestError>> {
202202
debug!("Fetching price from: {}", price_url);
203-
let (status, headers, body) = mm2_net::wasm_http::slurp_url(price_url).await?;
203+
let (status, headers, body) = mm2_net::wasm::http::slurp_url(price_url).await?;
204204
let (status_code, body, _) = (status, std::str::from_utf8(&body)?.trim().into(), headers);
205205
if status_code != StatusCode::OK {
206206
return MmError::err(PriceServiceRequestError::HttpProcessError(body));

mm2src/coins/nft.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use web3::types::TransactionId;
4141
use mm2_net::native_http::send_request_to_uri;
4242

4343
#[cfg(target_arch = "wasm32")]
44-
use mm2_net::wasm_http::send_request_to_uri;
44+
use mm2_net::wasm::http::send_request_to_uri;
4545

4646
const MORALIS_API_ENDPOINT: &str = "api/v2";
4747
/// query parameters for moralis request: The format of the token ID

mm2src/coins/nft/nft_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use mm2_net::native_http::send_request_to_uri;
2727
common::cfg_wasm32! {
2828
use wasm_bindgen_test::*;
2929
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
30-
use mm2_net::wasm_http::send_request_to_uri;
30+
use mm2_net::wasm::http::send_request_to_uri;
3131
}
3232

3333
cross_test!(test_moralis_ipfs_bafy, {

mm2src/coins/nft/storage/wasm/wasm_storage.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,11 @@ impl NftListTable {
895895
}
896896

897897
impl TableSignature for NftListTable {
898-
fn table_name() -> &'static str { "nft_list_cache_table" }
898+
const TABLE_NAME: &'static str = "nft_list_cache_table";
899899

900900
fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
901901
if is_initial_upgrade(old_version, new_version) {
902-
let table = upgrader.create_table(Self::table_name())?;
902+
let table = upgrader.create_table(Self::TABLE_NAME)?;
903903
table.create_multi_index(
904904
CHAIN_TOKEN_ADD_TOKEN_ID_INDEX,
905905
&["chain", "token_address", "token_id"],
@@ -976,11 +976,11 @@ impl NftTransferHistoryTable {
976976
}
977977

978978
impl TableSignature for NftTransferHistoryTable {
979-
fn table_name() -> &'static str { "nft_transfer_history_cache_table" }
979+
const TABLE_NAME: &'static str = "nft_transfer_history_cache_table";
980980

981981
fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
982982
if is_initial_upgrade(old_version, new_version) {
983-
let table = upgrader.create_table(Self::table_name())?;
983+
let table = upgrader.create_table(Self::TABLE_NAME)?;
984984
table.create_multi_index(
985985
CHAIN_TOKEN_ADD_TOKEN_ID_INDEX,
986986
&["chain", "token_address", "token_id"],
@@ -1009,11 +1009,11 @@ pub(crate) struct LastScannedBlockTable {
10091009
}
10101010

10111011
impl TableSignature for LastScannedBlockTable {
1012-
fn table_name() -> &'static str { "last_scanned_block_table" }
1012+
const TABLE_NAME: &'static str = "last_scanned_block_table";
10131013

10141014
fn on_upgrade_needed(upgrader: &DbUpgrader, old_version: u32, new_version: u32) -> OnUpgradeResult<()> {
10151015
if is_initial_upgrade(old_version, new_version) {
1016-
let table = upgrader.create_table(Self::table_name())?;
1016+
let table = upgrader.create_table(Self::TABLE_NAME)?;
10171017
table.create_index("chain", true)?;
10181018
}
10191019
Ok(())

mm2src/coins/qrc20/qrc20_tests.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
use super::*;
2-
use crate::utxo::rpc_clients::UnspentInfo;
32
use crate::{DexFee, TxFeeDetails, WaitForHTLCTxSpendArgs};
4-
use chain::OutPoint;
53
use common::{block_on, wait_until_sec, DEX_FEE_ADDR_RAW_PUBKEY};
64
use crypto::Secp256k1Secret;
75
use itertools::Itertools;
86
use keys::{Address, AddressBuilder};
97
use mm2_core::mm_ctx::MmCtxBuilder;
108
use mm2_number::bigdecimal::Zero;
11-
use mocktopus::mocking::{MockResult, Mockable};
129
use rpc::v1::types::ToTxHash;
1310
use std::convert::TryFrom;
1411
use std::mem::discriminant;
1512

13+
cfg_native!(
14+
use crate::utxo::rpc_clients::UnspentInfo;
15+
16+
use mocktopus::mocking::{MockResult, Mockable};
17+
use chain::OutPoint;
18+
);
19+
1620
const EXPECTED_TX_FEE: i64 = 1000;
1721
const CONTRACT_CALL_GAS_FEE: i64 = (QRC20_GAS_LIMIT_DEFAULT * QRC20_GAS_PRICE_DEFAULT) as i64;
1822
const SWAP_PAYMENT_GAS_FEE: i64 = (QRC20_PAYMENT_GAS_LIMIT * QRC20_GAS_PRICE_DEFAULT) as i64;
@@ -58,6 +62,7 @@ fn check_tx_fee(coin: &Qrc20Coin, expected_tx_fee: ActualTxFee) {
5862
assert_eq!(actual_tx_fee, expected_tx_fee);
5963
}
6064

65+
#[cfg(not(target_arch = "wasm32"))]
6166
#[test]
6267
fn test_withdraw_to_p2sh_address_should_fail() {
6368
let priv_key = [
@@ -91,6 +96,7 @@ fn test_withdraw_to_p2sh_address_should_fail() {
9196
assert_eq!(err, expect);
9297
}
9398

99+
#[cfg(not(target_arch = "wasm32"))]
94100
#[test]
95101
fn test_withdraw_impl_fee_details() {
96102
Qrc20Coin::get_unspent_ordered_list.mock_safe(|coin, _| {

0 commit comments

Comments
 (0)