Skip to content

Commit

Permalink
feat(zcoin): implement zcoin/pirate transport layer for WASM (#1996)
Browse files Browse the repository at this point in the history
This commit implements a zcoin transport layer that adheres to a common interface shared with the native transport. Additionally, It introduces some helper functions within FetchRequest and performs some refactoring in the mm2_net module. zcash params fetching and saving to indexedDB is also part of this commit.
  • Loading branch information
borngraced authored Dec 22, 2023
1 parent 1a64a9c commit 3d80b3a
Show file tree
Hide file tree
Showing 39 changed files with 1,423 additions and 472 deletions.
274 changes: 142 additions & 132 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ spl-token = { version = "3", optional = true }
spl-associated-token-account = { version = "1", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
blake2b_simd = "0.5"
ff = "0.8"
futures-util = "0.3"
jubjub = "0.5.1"
js-sys = { version = "0.3.27" }
mm2_db = { path = "../mm2_db" }
mm2_metamask = { path = "../mm2_metamask" }
mm2_test_helpers = { path = "../mm2_test_helpers" }
time = { version = "0.3.20" }
time = { version = "0.3.20", features = ["wasm-bindgen"] }
tonic = { version = "0.7", default-features = false, features = ["prost", "codegen"] }
tower-service = "0.3"
wasm-bindgen = "0.2.86"
wasm-bindgen-futures = { version = "0.4.1" }
wasm-bindgen-test = { version = "0.3.2" }
Expand Down Expand Up @@ -165,4 +169,4 @@ mm2_test_helpers = { path = "../mm2_test_helpers" }

[build-dependencies]
prost-build = { version = "0.10.4", default-features = false }
tonic-build = { version = "0.7", features = ["prost", "compression"] }
tonic-build = { version = "0.7", default-features = false, features = ["prost", "compression"] }
2 changes: 1 addition & 1 deletion mm2src/coins/eth/web3_transport/http_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ async fn send_request_once(
event_handlers: &Vec<RpcTransportEventHandlerShared>,
) -> Result<Json, Error> {
use http::header::ACCEPT;
use mm2_net::wasm_http::FetchRequest;
use mm2_net::wasm::http::FetchRequest;

// account for outgoing traffic
event_handlers.on_outgoing_request(request_payload.as_bytes());
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 @@ -200,7 +200,7 @@ async fn process_price_request(price_url: &str) -> Result<TickerInfosRegistry, M
#[cfg(target_arch = "wasm32")]
async fn process_price_request(price_url: &str) -> Result<TickerInfosRegistry, MmError<PriceServiceRequestError>> {
debug!("Fetching price from: {}", price_url);
let (status, headers, body) = mm2_net::wasm_http::slurp_url(price_url).await?;
let (status, headers, body) = mm2_net::wasm::http::slurp_url(price_url).await?;
let (status_code, body, _) = (status, std::str::from_utf8(&body)?.trim().into(), headers);
if status_code != StatusCode::OK {
return MmError::err(PriceServiceRequestError::HttpProcessError(body));
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use web3::types::TransactionId;
use mm2_net::native_http::send_request_to_uri;

#[cfg(target_arch = "wasm32")]
use mm2_net::wasm_http::send_request_to_uri;
use mm2_net::wasm::http::send_request_to_uri;

const MORALIS_API_ENDPOINT: &str = "api/v2";
/// query parameters for moralis request: The format of the token ID
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/nft/nft_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use mm2_net::native_http::send_request_to_uri;
common::cfg_wasm32! {
use wasm_bindgen_test::*;
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
use mm2_net::wasm_http::send_request_to_uri;
use mm2_net::wasm::http::send_request_to_uri;
}

cross_test!(test_moralis_ipfs_bafy, {
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/tendermint/rpc/tendermint_wasm_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use http::header::{ACCEPT, CONTENT_TYPE};
use http::uri::InvalidUri;
use http::{StatusCode, Uri};
use mm2_net::transport::SlurpError;
use mm2_net::wasm_http::FetchRequest;
use mm2_net::wasm::http::FetchRequest;
use std::str::FromStr;
use tendermint_rpc::endpoint::{abci_info, broadcast};
pub use tendermint_rpc::endpoint::{abci_query::{AbciQuery, Request as AbciRequest},
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/test_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ impl SwapOps for TestCoin {

async fn search_for_swap_tx_spend_my(
&self,
_: SearchForSwapTxSpendInput<'_>,
_input: SearchForSwapTxSpendInput<'_>,
) -> Result<Option<FoundSwapTxSpend>, String> {
unimplemented!()
}

async fn search_for_swap_tx_spend_other(
&self,
_: SearchForSwapTxSpendInput<'_>,
_input: SearchForSwapTxSpendInput<'_>,
) -> Result<Option<FoundSwapTxSpend>, String> {
unimplemented!()
}
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/rpc_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ async fn connect_loop<Spawner: SpawnFuture>(
static ref CONN_IDX: Arc<AtomicUsize> = Arc::new(AtomicUsize::new(0));
}

use mm2_net::wasm_ws::ws_transport;
use mm2_net::wasm::wasm_ws::ws_transport;

let delay = Arc::new(AtomicU64::new(0));
loop {
Expand Down
Loading

0 comments on commit 3d80b3a

Please sign in to comment.