From af825363b60056e2e5bd865cdc052249a445f73e Mon Sep 17 00:00:00 2001 From: James Date: Mon, 13 Dec 2021 12:24:47 -0800 Subject: [PATCH 1/4] feature: set nonce in fill transaction --- ethers-middleware/src/nonce_manager.rs | 12 ++++++++++++ ethers-providers/src/lib.rs | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/ethers-middleware/src/nonce_manager.rs b/ethers-middleware/src/nonce_manager.rs index 0ebc3f196..1ff15405f 100644 --- a/ethers-middleware/src/nonce_manager.rs +++ b/ethers-middleware/src/nonce_manager.rs @@ -77,6 +77,18 @@ where &self.inner } + async fn fill_transaction( + &self, + tx: &mut TypedTransaction, + block: Option, + ) -> Result<(), Self::Error> { + if tx.nonce().is_none() { + tx.set_nonce(self.get_transaction_count_with_manager(block).await?); + } + + Ok(self.inner().fill_transaction(tx, block).await.map_err(FromErr::from)?) + } + /// Signs and broadcasts the transaction. The optional parameter `block` can be passed so that /// gas cost and nonce calculations take it into account. For simple transactions this can be /// left to `None`. diff --git a/ethers-providers/src/lib.rs b/ethers-providers/src/lib.rs index ba538a8ad..92bf9b605 100644 --- a/ethers-providers/src/lib.rs +++ b/ethers-providers/src/lib.rs @@ -171,6 +171,13 @@ pub trait Middleware: Sync + Send + Debug { } } + // set the nonce, if no nonce is found + if tx.nonce().is_none() { + let nonce = + self.get_transaction_count(tx.from().copied().unwrap_or_default(), block).await?; + tx.set_nonce(nonce); + } + // TODO: Can we poll the futures below at the same time? // Access List + Name resolution and then Gas price + Gas From 2abcbfdbb8f5e885c871f4ea3367b44ee044d528 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 13 Dec 2021 12:26:45 -0800 Subject: [PATCH 2/4] chore: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1099c2944..18d653847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ [#624](https://github.com/gakonst/ethers-rs/pull/624). - Fix `fee_history` to first try with `block_count` encoded as a hex `QUANTITY`. [#668](https://github.com/gakonst/ethers-rs/pull/668) +- Fix `fill_transaction` to set nonces in transactions, if the sender is known + and no nonce is specified ## ethers-contract-abigen From c51cfd81b42d0af23c89e630817e639a539e060a Mon Sep 17 00:00:00 2001 From: James Date: Mon, 13 Dec 2021 13:03:16 -0800 Subject: [PATCH 3/4] refactor: remove nonce_setting in fill_transaction --- ethers-providers/src/lib.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ethers-providers/src/lib.rs b/ethers-providers/src/lib.rs index 92bf9b605..ba538a8ad 100644 --- a/ethers-providers/src/lib.rs +++ b/ethers-providers/src/lib.rs @@ -171,13 +171,6 @@ pub trait Middleware: Sync + Send + Debug { } } - // set the nonce, if no nonce is found - if tx.nonce().is_none() { - let nonce = - self.get_transaction_count(tx.from().copied().unwrap_or_default(), block).await?; - tx.set_nonce(nonce); - } - // TODO: Can we poll the futures below at the same time? // Access List + Name resolution and then Gas price + Gas From 37d94e5a210f110426894bb43b6883ec0dc37f0b Mon Sep 17 00:00:00 2001 From: James Date: Mon, 13 Dec 2021 13:45:14 -0800 Subject: [PATCH 4/4] refactor: set nonce in send_escalating --- ethers-providers/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ethers-providers/src/lib.rs b/ethers-providers/src/lib.rs index ba538a8ad..2a256feac 100644 --- a/ethers-providers/src/lib.rs +++ b/ethers-providers/src/lib.rs @@ -248,6 +248,14 @@ pub trait Middleware: Sync + Send + Debug { ) -> Result, Self::Error> { let mut original = tx.clone(); self.fill_transaction(&mut original, None).await?; + + // set the nonce, if no nonce is found + if original.nonce().is_none() { + let nonce = + self.get_transaction_count(tx.from().copied().unwrap_or_default(), None).await?; + original.set_nonce(nonce); + } + let gas_price = original.gas_price().expect("filled"); let chain_id = self.get_chainid().await?.low_u64(); let sign_futs: Vec<_> = (0..escalations)