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
This commit is contained in:
James Prestwich 2021-12-13 14:50:13 -08:00 committed by GitHub
parent 47e9e7d3c7
commit 3338cdead1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -77,6 +77,18 @@ where
&self.inner
}
async fn fill_transaction(
&self,
tx: &mut TypedTransaction,
block: Option<BlockId>,
) -> 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`.

View File

@ -248,6 +248,14 @@ pub trait Middleware: Sync + Send + Debug {
) -> Result<EscalatingPending<'a, Self::Provider>, 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)