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

Commit 3338cde

Browse files
authored
feature: set nonce in fill transaction (#687)
* feature: set nonce in fill transaction * chore: update changelog * refactor: remove nonce_setting in fill_transaction * refactor: set nonce in send_escalating
1 parent 47e9e7d commit 3338cde

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
[#624](https://github.com/gakonst/ethers-rs/pull/624).
1515
- Fix `fee_history` to first try with `block_count` encoded as a hex `QUANTITY`.
1616
[#668](https://github.com/gakonst/ethers-rs/pull/668)
17+
- Fix `fill_transaction` to set nonces in transactions, if the sender is known
18+
and no nonce is specified
1719

1820
## ethers-contract-abigen
1921

Diff for: ethers-middleware/src/nonce_manager.rs

+12
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ where
7777
&self.inner
7878
}
7979

80+
async fn fill_transaction(
81+
&self,
82+
tx: &mut TypedTransaction,
83+
block: Option<BlockId>,
84+
) -> Result<(), Self::Error> {
85+
if tx.nonce().is_none() {
86+
tx.set_nonce(self.get_transaction_count_with_manager(block).await?);
87+
}
88+
89+
Ok(self.inner().fill_transaction(tx, block).await.map_err(FromErr::from)?)
90+
}
91+
8092
/// Signs and broadcasts the transaction. The optional parameter `block` can be passed so that
8193
/// gas cost and nonce calculations take it into account. For simple transactions this can be
8294
/// left to `None`.

Diff for: ethers-providers/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ pub trait Middleware: Sync + Send + Debug {
248248
) -> Result<EscalatingPending<'a, Self::Provider>, Self::Error> {
249249
let mut original = tx.clone();
250250
self.fill_transaction(&mut original, None).await?;
251+
252+
// set the nonce, if no nonce is found
253+
if original.nonce().is_none() {
254+
let nonce =
255+
self.get_transaction_count(tx.from().copied().unwrap_or_default(), None).await?;
256+
original.set_nonce(nonce);
257+
}
258+
251259
let gas_price = original.gas_price().expect("filled");
252260
let chain_id = self.get_chainid().await?.low_u64();
253261
let sign_futs: Vec<_> = (0..escalations)

0 commit comments

Comments
 (0)