fix: make ethers-wasm workspace member (#642)

* fix: make ethers-wasm workspace member

* rustfmt

* chore: allow clippy all

* chore: make ethers-wasm non default member

* ci: only clippy default members
This commit is contained in:
Matthias Seitz 2021-12-03 18:27:55 +01:00 committed by GitHub
parent bccc7b9b5e
commit ad68337113
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 131 additions and 77 deletions

View File

@ -129,7 +129,7 @@ jobs:
- name: cargo fmt - name: cargo fmt
run: cargo +nightly fmt --all -- --check run: cargo +nightly fmt --all -- --check
- name: cargo clippy - name: cargo clippy
run: cargo +nightly clippy --all --all-features -- -D warnings run: cargo +nightly clippy --all-features -- -D warnings
wasm: wasm:
name: WASM name: WASM

118
Cargo.lock generated
View File

@ -78,9 +78,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.48" version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62e1f47f7dc0422027a4e370dd4548d4d66b26782e513e98dca1e689e058a80e" checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
[[package]] [[package]]
name = "arrayref" name = "arrayref"
@ -196,9 +196,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]] [[package]]
name = "base64ct" name = "base64ct"
version = "1.2.0" version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "392c772b012d685a640cdad68a5a21f4a45e696f85a2c2c907aab2fe49a91e19" checksum = "43a46022bae2c3bc5a17c2d45d59c1233ce0e2cca9ae9b92e92e9ce529874177"
[[package]] [[package]]
name = "bech32" name = "bech32"
@ -437,9 +437,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.3" version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"textwrap", "textwrap",
@ -575,6 +575,16 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen",
]
[[package]] [[package]]
name = "const-oid" name = "const-oid"
version = "0.6.2" version = "0.6.2"
@ -583,9 +593,9 @@ checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b"
[[package]] [[package]]
name = "const-oid" name = "const-oid"
version = "0.7.0" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d355758f44afa81c21e66e1301d47cbffbbcde4b405cbe46b8b19f213abf9f60" checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3"
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
@ -626,9 +636,9 @@ dependencies = [
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
version = "1.2.2" version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3825b1e8580894917dc4468cb634a1b4e9745fddc854edad72d9c04644c0319f" checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
@ -726,9 +736,9 @@ dependencies = [
[[package]] [[package]]
name = "der" name = "der"
version = "0.4.4" version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28e98c534e9c8a0483aa01d6f6913bc063de254311bd267c9cf535e9b70e15b2" checksum = "79b71cca7d95d7681a4b3b9cdf63c8dbc3730d0584c2c74e31416d64a90493f4"
dependencies = [ dependencies = [
"const-oid 0.6.2", "const-oid 0.6.2",
] ]
@ -739,7 +749,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c"
dependencies = [ dependencies = [
"const-oid 0.7.0", "const-oid 0.7.1",
] ]
[[package]] [[package]]
@ -799,7 +809,7 @@ version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43ee23aa5b4f68c7a092b5c3beb25f50c406adc75e2363634f242f28ab255372" checksum = "43ee23aa5b4f68c7a092b5c3beb25f50c406adc75e2363634f242f28ab255372"
dependencies = [ dependencies = [
"der 0.4.4", "der 0.4.5",
"elliptic-curve 0.10.6", "elliptic-curve 0.10.6",
"hmac", "hmac",
"signature", "signature",
@ -1179,6 +1189,7 @@ dependencies = [
"colored", "colored",
"ethers-core", "ethers-core",
"futures-util", "futures-util",
"getrandom 0.2.3",
"glob", "glob",
"hex", "hex",
"home", "home",
@ -1197,6 +1208,23 @@ dependencies = [
"walkdir", "walkdir",
] ]
[[package]]
name = "ethers-wasm"
version = "0.1.0"
dependencies = [
"console_error_panic_hook",
"ethers",
"hex",
"serde",
"serde_derive",
"serde_json",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test",
"web-sys",
"wee_alloc",
]
[[package]] [[package]]
name = "fake-simd" name = "fake-simd"
version = "0.1.2" version = "0.1.2"
@ -1801,6 +1829,12 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "memory_units"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.16" version = "0.3.16"
@ -2124,7 +2158,7 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447" checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447"
dependencies = [ dependencies = [
"der 0.4.4", "der 0.4.5",
"spki", "spki",
] ]
@ -2629,9 +2663,9 @@ dependencies = [
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.5" version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" checksum = "3c9613b5a66ab9ba26415184cfc41156594925a9cf3a2057e57f31ff145f6568"
[[package]] [[package]]
name = "salsa20" name = "salsa20"
@ -2661,6 +2695,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "scoped-tls"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
@ -2771,9 +2811,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.71" version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "063bf466a64011ac24040a49009724ee60a57da1b437617ceb32e53ad61bfb19" checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@ -2955,7 +2995,7 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32" checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32"
dependencies = [ dependencies = [
"der 0.4.4", "der 0.4.5",
] ]
[[package]] [[package]]
@ -3507,6 +3547,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"serde",
"serde_json",
"wasm-bindgen-macro", "wasm-bindgen-macro",
] ]
@ -3566,6 +3608,30 @@ version = "0.2.78"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc"
[[package]]
name = "wasm-bindgen-test"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96f1aa7971fdf61ef0f353602102dbea75a56e225ed036c1e3740564b91e6b7e"
dependencies = [
"console_error_panic_hook",
"js-sys",
"scoped-tls",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test-macro",
]
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6006f79628dfeb96a86d4db51fbf1344cd7fd8408f06fc9aa3c84913a4789688"
dependencies = [
"proc-macro2",
"quote",
]
[[package]] [[package]]
name = "wasm-timer" name = "wasm-timer"
version = "0.2.5" version = "0.2.5"
@ -3620,6 +3686,18 @@ dependencies = [
"webpki 0.21.4", "webpki 0.21.4",
] ]
[[package]]
name = "wee_alloc"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
dependencies = [
"cfg-if 0.1.10",
"libc",
"memory_units",
"winapi",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

View File

@ -20,7 +20,8 @@ members = [
"ethers-core", "ethers-core",
"ethers-middleware", "ethers-middleware",
"ethers-etherscan", "ethers-etherscan",
"ethers-solc" "ethers-solc",
"examples/ethers-wasm",
] ]
default-members = [ default-members = [
@ -30,11 +31,7 @@ default-members = [
"ethers-core", "ethers-core",
"ethers-middleware", "ethers-middleware",
"ethers-etherscan", "ethers-etherscan",
"ethers-solc" "ethers-solc",
]
exclude = [
"examples/ethers-wasm",
] ]
[package.metadata.docs.rs] [package.metadata.docs.rs]
@ -102,3 +99,9 @@ serde_json = "1.0.64"
tokio = { version = "1.5", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.5", features = ["macros", "rt-multi-thread"] }
hex = "0.4.3" hex = "0.4.3"
bytes = "1.1.0" 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"

View File

@ -31,12 +31,16 @@ svm = { package = "svm-rs", version = "0.2.0", optional = true }
glob = "0.3.0" glob = "0.3.0"
tracing = "0.1.29" tracing = "0.1.29"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(not(any(target_arch = "x86", target_arch = "x86_64")))'.dependencies]
sha2 = { version = "0.9.8" } 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" 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] [dev-dependencies]
tokio = { version = "1.12.0", features = ["full"] } tokio = { version = "1.12.0", features = ["full"] }

View File

@ -43,10 +43,4 @@ hex = "0.4.3"
web-sys = "0.3.51" web-sys = "0.3.51"
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3.24" 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"

View File

@ -1,3 +1,5 @@
#![allow(clippy::all)]
use std::sync::Arc; use std::sync::Arc;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
@ -51,12 +53,7 @@ pub async fn deploy() {
let factory = ContractFactory::new(SIMPLECONTRACT_ABI.clone(), bytecode.into(), client.clone()); let factory = ContractFactory::new(SIMPLECONTRACT_ABI.clone(), bytecode.into(), client.clone());
log!("Deploying contract..."); log!("Deploying contract...");
let contract = factory let contract = factory.deploy("hello WASM!".to_string()).unwrap().send().await.unwrap();
.deploy("hello WASM!".to_string())
.unwrap()
.send()
.await
.unwrap();
let addr = contract.address(); let addr = contract.address();
log!("Deployed contract with address: {:?}", addr); log!("Deployed contract with address: {:?}", addr);
@ -64,25 +61,11 @@ pub async fn deploy() {
let value = "bye from WASM!"; let value = "bye from WASM!";
log!("Setting value... `{}`", value); log!("Setting value... `{}`", value);
let receipt = contract let receipt = contract.set_value(value.to_owned()).send().await.unwrap().await.unwrap();
.set_value(value.to_owned()) console::log_2(&"Set value receipt: ".into(), &JsValue::from_serde(&receipt).unwrap());
.send()
.await
.unwrap()
.await
.unwrap();
console::log_2(
&"Set value receipt: ".into(),
&JsValue::from_serde(&receipt).unwrap(),
);
log!("Fetching logs..."); log!("Fetching logs...");
let logs = contract let logs = contract.value_changed_filter().from_block(0u64).query().await.unwrap();
.value_changed_filter()
.from_block(0u64)
.query()
.await
.unwrap();
let value = contract.get_value().call().await.unwrap(); let value = contract.get_value().call().await.unwrap();

View File

@ -1,5 +1,7 @@
use ethers::prelude::{LocalWallet, MnemonicBuilder}; use ethers::{
use ethers::signers::coins_bip39::English; prelude::{LocalWallet, MnemonicBuilder},
signers::coins_bip39::English,
};
pub fn set_panic_hook() { pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the // When the `console_error_panic_hook` feature is enabled, we can call the
@ -17,12 +19,7 @@ pub const PHRASE: &str =
"stuff inherit faith park genre spread huge knee ecology private marble supreme"; "stuff inherit faith park genre spread huge knee ecology private marble supreme";
pub fn key(index: u32) -> LocalWallet { pub fn key(index: u32) -> LocalWallet {
MnemonicBuilder::<English>::default() MnemonicBuilder::<English>::default().phrase(PHRASE).index(index).unwrap().build().unwrap()
.phrase(PHRASE)
.index(index)
.unwrap()
.build()
.unwrap()
} }
/// Bytecode of the `SimpleContract` /// Bytecode of the `SimpleContract`

View File

@ -6,8 +6,7 @@ use ethers::prelude::{
abigen, ContractFactory, Http, JsonRpcClient, LocalWallet, Provider, SignerMiddleware, Ws, abigen, ContractFactory, Http, JsonRpcClient, LocalWallet, Provider, SignerMiddleware, Ws,
}; };
use std::convert::TryFrom; use std::{convert::TryFrom, sync::Arc};
use std::sync::Arc;
wasm_bindgen_test_configure!(run_in_browser); wasm_bindgen_test_configure!(run_in_browser);
@ -38,12 +37,8 @@ async fn deploy<T: JsonRpcClient>(provider: Provider<T>, wallet: LocalWallet) {
let bytecode = hex::decode(ethers_wasm::utils::SIMPLECONTRACT_BIN).unwrap(); let bytecode = hex::decode(ethers_wasm::utils::SIMPLECONTRACT_BIN).unwrap();
let factory = ContractFactory::new(SIMPLECONTRACT_ABI.clone(), bytecode.into(), client.clone()); let factory = ContractFactory::new(SIMPLECONTRACT_ABI.clone(), bytecode.into(), client.clone());
let contract = factory let contract =
.deploy("Hello from Contract!".to_string()) factory.deploy("Hello from Contract!".to_string()).unwrap().send().await.unwrap();
.unwrap()
.send()
.await
.unwrap();
let addr = contract.address(); let addr = contract.address();
console_log!("deployed to {}", addr); console_log!("deployed to {}", addr);