Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix: make ethers-wasm workspace member (#642)
Browse files Browse the repository at this point in the history
* fix: make ethers-wasm workspace member

* rustfmt

* chore: allow clippy all

* chore: make ethers-wasm non default member

* ci: only clippy default members
  • Loading branch information
mattsse authored Dec 3, 2021
1 parent bccc7b9 commit ad68337
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
- name: cargo fmt
run: cargo +nightly fmt --all -- --check
- name: cargo clippy
run: cargo +nightly clippy --all --all-features -- -D warnings
run: cargo +nightly clippy --all-features -- -D warnings

wasm:
name: WASM
Expand Down
118 changes: 98 additions & 20 deletions Cargo.lock

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

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ members = [
"ethers-core",
"ethers-middleware",
"ethers-etherscan",
"ethers-solc"
"ethers-solc",
"examples/ethers-wasm",
]

default-members = [
Expand All @@ -30,11 +31,7 @@ default-members = [
"ethers-core",
"ethers-middleware",
"ethers-etherscan",
"ethers-solc"
]

exclude = [
"examples/ethers-wasm",
"ethers-solc",
]

[package.metadata.docs.rs]
Expand Down Expand Up @@ -102,3 +99,9 @@ serde_json = "1.0.64"
tokio = { version = "1.5", features = ["macros", "rt-multi-thread"] }
hex = "0.4.3"
bytes = "1.1.0"


# profile for the wasm example
[profile.release.package.ethers-wasm]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
12 changes: 8 additions & 4 deletions ethers-solc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ svm = { package = "svm-rs", version = "0.2.0", optional = true }
glob = "0.3.0"
tracing = "0.1.29"

[target.'cfg(target_arch = "wasm32")'.dependencies]
sha2 = { version = "0.9.8" }
[target.'cfg(not(any(target_arch = "x86", target_arch = "x86_64")))'.dependencies]
sha2 = { version = "0.9.8", default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
home = "0.5.3"
sha2 = { version = "0.9.8", features = ["asm"] }
sha2 = { version = "0.9.8", default-features = false, features = ["asm"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
# NOTE: this enables wasm compatibility for getrandom indirectly
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
tokio = { version = "1.12.0", features = ["full"] }
Expand Down
8 changes: 1 addition & 7 deletions examples/ethers-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,4 @@ hex = "0.4.3"
web-sys = "0.3.51"

[dev-dependencies]
wasm-bindgen-test = "0.3.24"

# profile for the wasm example
[profile.release.package.ethers-wasm]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

wasm-bindgen-test = "0.3.24"
29 changes: 6 additions & 23 deletions examples/ethers-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::all)]

use std::sync::Arc;

use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -51,38 +53,19 @@ pub async fn deploy() {
let factory = ContractFactory::new(SIMPLECONTRACT_ABI.clone(), bytecode.into(), client.clone());

log!("Deploying contract...");
let contract = factory
.deploy("hello WASM!".to_string())
.unwrap()
.send()
.await
.unwrap();
let contract = factory.deploy("hello WASM!".to_string()).unwrap().send().await.unwrap();
let addr = contract.address();
log!("Deployed contract with address: {:?}", addr);

let contract = SimpleContract::new(addr, client.clone());

let value = "bye from WASM!";
log!("Setting value... `{}`", value);
let receipt = contract
.set_value(value.to_owned())
.send()
.await
.unwrap()
.await
.unwrap();
console::log_2(
&"Set value receipt: ".into(),
&JsValue::from_serde(&receipt).unwrap(),
);
let receipt = contract.set_value(value.to_owned()).send().await.unwrap().await.unwrap();
console::log_2(&"Set value receipt: ".into(), &JsValue::from_serde(&receipt).unwrap());

log!("Fetching logs...");
let logs = contract
.value_changed_filter()
.from_block(0u64)
.query()
.await
.unwrap();
let logs = contract.value_changed_filter().from_block(0u64).query().await.unwrap();

let value = contract.get_value().call().await.unwrap();

Expand Down
Loading

0 comments on commit ad68337

Please sign in to comment.