From 8eac1997f4cc09ff4343f94e492aa51f23e51e1f Mon Sep 17 00:00:00 2001 From: Luke Tchang Date: Tue, 16 Nov 2021 16:03:26 -0800 Subject: [PATCH] fix: remove const lag so it can be passed in as runtime variable (#587) --- ethers-middleware/src/timelag/mod.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ethers-middleware/src/timelag/mod.rs b/ethers-middleware/src/timelag/mod.rs index 133b6e3d..09541eab 100644 --- a/ethers-middleware/src/timelag/mod.rs +++ b/ethers-middleware/src/timelag/mod.rs @@ -33,21 +33,22 @@ impl FromErr for TimeLagError { /// TimeLag Provider #[derive(Debug)] -pub struct TimeLag { +pub struct TimeLag { inner: Arc, + lag: u8, } -impl TimeLag +impl TimeLag where M: Middleware, { /// Instantiates TimeLag provider - pub fn new(inner: M) -> Self { - Self { inner: inner.into() } + pub fn new(inner: M, lag: u8) -> Self { + Self { inner: inner.into(), lag } } } -impl TimeLag +impl TimeLag where M: Middleware, { @@ -93,7 +94,7 @@ where #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] -impl Middleware for TimeLag +impl Middleware for TimeLag where M: Middleware, { @@ -111,7 +112,7 @@ where self.inner() .get_block_number() .await - .map(|num| num - K) + .map(|num| num - self.lag) .map_err(ethers_providers::FromErr::from) }