MCPcopy Create free account
hub / github.com/ddimaria/rust-blockchain-tutorial / update_nonce

Method update_nonce

chain/src/account.rs:90–107  ·  view source on GitHub ↗

TODO(ddimaria): remove

(&mut self, key: &Account, nonce: U256)

Source from the content-addressed store, hash-verified

88
89 // TODO(ddimaria): remove
90 pub(crate) fn update_nonce(&mut self, key: &Account, nonce: U256) -> Result<U256> {
91 let mut account_data = self.get_account(key)?;
92
93 // the passed in nonce is lower than the current nonce + 1
94 if nonce < account_data.nonce + 1 {
95 return Err(ChainError::NonceTooLow(nonce.to_string(), key.to_string()));
96 }
97
98 // the passed in nonce is higher than the current nonce + 1
99 if nonce > account_data.nonce + 1 {
100 return Err(ChainError::NonceTooHigh(nonce.to_string(), key.to_string()));
101 }
102
103 account_data.nonce = nonce;
104 self.upsert(key, &account_data)?;
105
106 Ok(account_data.nonce)
107 }
108
109 pub(crate) fn get_account_balance_by_block(
110 &self,

Callers 2

it_increments_a_nonceFunction · 0.80
process_transactionMethod · 0.80

Calls 2

get_accountMethod · 0.80
upsertMethod · 0.80

Tested by 1

it_increments_a_nonceFunction · 0.64