Add pub fn initialize_nonce in NonceMiddleManager (#840)

* Public function added "initialize_nonce"

Initialize the nonce manager with the current nonce

* Update CHANGELOG.md

* return generic

* Added current nonce as return value
Will now compile.

* Load nonce to return, fixes compile.

* chore: fmt

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
teebaumcrypto 2022-01-31 20:04:26 +01:00 committed by GitHub
parent dd915c99f6
commit 2b178e9cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -182,6 +182,7 @@
[#568](https://github.com/gakonst/ethers-rs/pull/568) [#568](https://github.com/gakonst/ethers-rs/pull/568)
- Removes GasNow as a gas price oracle - Removes GasNow as a gas price oracle
[#508](https://github.com/gakonst/ethers-rs/pull/508) [#508](https://github.com/gakonst/ethers-rs/pull/508)
- add initialize_nonce public function to initialize NonceMiddleManager
### 0.5.3 ### 0.5.3

View File

@ -30,6 +30,24 @@ where
nonce.into() nonce.into()
} }
pub async fn initialize_nonce(
&self,
block: Option<BlockId>,
) -> Result<U256, NonceManagerError<M>> {
// initialize the nonce the first time the manager is called
if !self.initialized.load(Ordering::SeqCst) {
let nonce = self
.inner
.get_transaction_count(self.address, block)
.await
.map_err(FromErr::from)?;
self.nonce.store(nonce.as_u64(), Ordering::SeqCst);
self.initialized.store(true, Ordering::SeqCst);
}
// return current nonce
Ok(self.nonce.load(Ordering::SeqCst).into())
}
async fn get_transaction_count_with_manager( async fn get_transaction_count_with_manager(
&self, &self,
block: Option<BlockId>, block: Option<BlockId>,