Skip to content

Commit

Permalink
Add Account::set_nonce() function (#466)
Browse files Browse the repository at this point in the history
* set_nonce

* Modify function above to use set_nonce()
  • Loading branch information
phklive authored Feb 14, 2024
1 parent 9918bd9 commit c393ddd
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions objects/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,31 @@ impl Account {

// update nonce
if let Some(nonce) = delta.nonce() {
if self.nonce.as_int() >= nonce.as_int() {
return Err(AccountError::NonceNotMonotonicallyIncreasing {
current: self.nonce.as_int(),
new: nonce.as_int(),
});
}
self.nonce = nonce;
self.set_nonce(nonce)?;
}

Ok(())
}

/// Sets the nonce of this account to the specified nonce value.
///
/// # Errors
/// Returns an error if:
/// - The new nonce is smaller than the actual account nonce
/// - The new nonce is equal to the actual account nonce
pub fn set_nonce(&mut self, nonce: Felt) -> Result<(), AccountError> {
if self.nonce.as_int() >= nonce.as_int() {
return Err(AccountError::NonceNotMonotonicallyIncreasing {
current: self.nonce.as_int(),
new: nonce.as_int(),
});
}

self.nonce = nonce;

Ok(())
}

// TEST HELPERS
// --------------------------------------------------------------------------------------------

Expand Down

0 comments on commit c393ddd

Please sign in to comment.