Skip to content

Commit

Permalink
WASM Electrum client (#946)
Browse files Browse the repository at this point in the history
* Refactor Wasm WebSocket transport
* Move boilerplate code from connection states to the WsContext
* Fix the bug when the WsIncomingReceiver is opened, but the transport closes

* Configure the Electrum client to work in the browser
* Remove host_electrum_connect, host_electrum_is_connected, host_electrum_request, host_electrum_reply from defined-in-js.js
* Implement the rpc_clients::connect_loop wasm version
* Add wasm_ws::ws_transport that filters and maps the incoming WebSocketEvent
* Extend the wasm_build's index.html example

* Fix electrum_request timeout on WASM
* Add the 'FutureTimeoutExt' trait that works on WASM

* Fix electrum metrics

* Roll back prices.rs portfolio.rs

* Add WS and WSS protocols to the electrum request

* Add the handling of the WS closure reason
* Add the 'reason' field to 'WebSocketEvent::Closing', 'WebSocketEvent::Closed'
* Add the 'ClosureReason' variant
  • Loading branch information
sergeyboyko0791 authored May 18, 2021
1 parent aefe61a commit 7773ae5
Show file tree
Hide file tree
Showing 17 changed files with 836 additions and 536 deletions.
17 changes: 3 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ enum-primitive-derive = "0.1"
fomat-macros = "0.2"
futures01 = { version = "0.1", package = "futures" }
futures-cpupool = "0.1"
# NB: tokio-timer 2+ is targeted at "Tokio runtime" and heavy load (spawns several timer threads there),
# whereas futures-timer works with any reactor and spawns one global timer thread (fits out load better).
futures-timer = "0.1"
futures = { version = "0.3.1", package = "futures", features = ["compat", "async-await"] }
gstuff = { version = "0.6", features = ["nightly"] }
hash256-std-hasher = "0.15.2"
Expand Down
20 changes: 0 additions & 20 deletions js/defined-in-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@
export function host_ensure_dir_is_writable(ptr, len) {
}

// fn host_electrum_connect(ptr: *const c_char, len: i32) -> i32;
export function host_electrum_connect(ptr, len) {
return 0;
}

// fn host_electrum_is_connected(ri: i32) -> i32;
export function host_electrum_is_connected(ri) {
return 0;
}

// fn host_electrum_request(ri: i32, ptr: *const c_char, len: i32) -> i32;
export function host_electrum_request(ri, ptr, len) {
return 0;
}

// fn host_electrum_reply(ri: i32, id: i32, rbuf: *mut c_char, rcap: i32) -> i32;
export function host_electrum_reply(ri, id, rbuf, rcap) {
return 0;
}

// pub fn host_env(name: *const c_char, nameˡ: i32, rbuf: *mut c_char, rcap: i32) -> i32;
export function host_env(name, name2, rbuf, rcap) {
return 0;
Expand Down
1 change: 0 additions & 1 deletion mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fomat-macros = "0.2"
futures01 = { version = "0.1", package = "futures" }
# using select macro requires the crate to be named futures, compilation failed with futures03 name
futures = { version = "0.3", package = "futures", features = ["compat", "async-await"] }
futures-timer = "0.1"
gstuff = { version = "0.6", features = ["nightly"] }
hex = "0.3.2"
http = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ use common::log::{error, warn};
use common::mm_ctx::MmArc;
use common::mm_error::prelude::*;
use common::mm_number::MmNumber;
use common::now_ms;
use derive_more::Display;
use ethabi::{Function, Token};
use ethereum_types::{H160, U256};
use futures::compat::Future01CompatExt;
use futures::lock::MutexGuard as AsyncMutexGuard;
use futures::{FutureExt, TryFutureExt};
use futures01::Future;
use gstuff::now_ms;
use keys::bytes::Bytes as ScriptBytes;
use keys::{Address as UtxoAddress, Address, Public};
#[cfg(test)] use mocktopus::macros::*;
Expand Down
1 change: 1 addition & 0 deletions mm2src/coins/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ use super::{BalanceError, BalanceFut, BalanceResult, CoinTransportMetrics, Coins
WithdrawError, WithdrawFee, WithdrawRequest};

#[cfg(test)] pub mod utxo_tests;
#[cfg(target_arch = "wasm32")] pub mod utxo_wasm_tests;

const SWAP_TX_SPEND_SIZE: u64 = 305;
const KILO_BYTE: u64 = 1000;
Expand Down
Loading

0 comments on commit 7773ae5

Please sign in to comment.