feat: derives &, Arc and Box for Middleware (#109)

* test: can stack Middlewares with Arcs

* feat: derive &, Box and Arc impls for Middleware

* chore: fix spacing
This commit is contained in:
Georgios Konstantopoulos 2020-12-18 13:15:19 +02:00 committed by GitHub
parent 3a2fd3e814
commit d9db40402b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 6 deletions

37
Cargo.lock generated
View File

@ -266,6 +266,18 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
[[package]]
name = "auto_impl"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42cbf586c80ada5e5ccdecae80d3ef0854f224e2dd74435f8d87e6831b8d0a38"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "autocfg"
version = "1.0.1"
@ -874,6 +886,7 @@ dependencies = [
"async-tls",
"async-trait",
"async-tungstenite",
"auto_impl",
"ethers",
"ethers-core",
"futures-channel",
@ -1884,6 +1897,30 @@ dependencies = [
"uint",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"

View File

@ -387,10 +387,7 @@ mod celo_tests {
let call = contract
.method::<_, H256>("setValue", "hi".to_owned())
.unwrap();
let pending_tx = call
.send()
.await
.unwrap();
let pending_tx = call.send().await.unwrap();
let _receipt = pending_tx.await.unwrap();
let value: String = contract

View File

@ -57,7 +57,7 @@ mod tests {
let address = signer.address();
// the base provider
let provider = Provider::<Http>::try_from(ganache.endpoint()).unwrap();
let provider = Arc::new(Provider::<Http>::try_from(ganache.endpoint()).unwrap());
// the Gas Price escalator middleware is the first middleware above the provider,
// so that it receives the transaction last, after all the other middleware
@ -69,7 +69,8 @@ mod tests {
let provider = GasOracleMiddleware::new(provider, gas_oracle);
// The signing middleware signs txs
let provider = SignerMiddleware::new(provider, signer);
use std::sync::Arc;
let provider = Arc::new(SignerMiddleware::new(provider, signer));
// The nonce manager middleware MUST be above the signing middleware so that it overrides
// the nonce and the signer does not make any eth_getTransaction count calls

View File

@ -41,6 +41,7 @@ async-tls = { version = "0.7.0", optional = true }
# needed for parsing while deserialization in gas oracles
serde-aux = "0.6.1"
auto_impl = "0.4.1"
[dev-dependencies]
ethers = { version = "0.1.3", path = "../ethers" }

View File

@ -118,6 +118,7 @@ mod pubsub;
pub use pubsub::{PubsubClient, SubscriptionStream};
use async_trait::async_trait;
use auto_impl::auto_impl;
use serde::{de::DeserializeOwned, Serialize};
use std::{error::Error, fmt::Debug, future::Future, pin::Pin};
@ -128,6 +129,7 @@ pub(crate) type PinBoxFut<'a, T> =
Pin<Box<dyn Future<Output = Result<T, ProviderError>> + Send + 'a>>;
#[async_trait]
#[auto_impl(&, Box, Arc)]
/// Trait which must be implemented by data transports to be used with the Ethereum
/// JSON-RPC provider.
pub trait JsonRpcClient: Debug + Send + Sync {
@ -147,6 +149,7 @@ pub trait FromErr<T> {
}
#[async_trait]
#[auto_impl(&, Box, Arc)]
pub trait Middleware: Sync + Send + Debug {
type Error: Sync + Send + Error + FromErr<<Self::Inner as Middleware>::Error>;
type Provider: JsonRpcClient;