Skip to content

Commit 2bab9a0

Browse files
apollo_gateway: add get_nonce function to StatefulValidator trait
1 parent 64b5d27 commit 2bab9a0

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

crates/apollo_gateway/src/stateful_transaction_validator.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use blockifier::transaction::account_transaction::{AccountTransaction, Execution
2222
use blockifier::transaction::transactions::enforce_fee;
2323
use num_rational::Ratio;
2424
use starknet_api::block::{BlockInfo, NonzeroGasPrice};
25-
use starknet_api::core::Nonce;
25+
use starknet_api::core::{ContractAddress, Nonce};
2626
use starknet_api::executable_transaction::{
2727
AccountTransaction as ExecutableTransaction,
2828
InvokeTransaction as ExecutableInvokeTransaction,
@@ -148,6 +148,11 @@ pub trait StatefulTransactionValidatorTrait: Send {
148148
mempool_client: SharedMempoolClient,
149149
runtime: tokio::runtime::Handle,
150150
) -> StatefulTransactionValidatorResult<Nonce>;
151+
152+
fn get_nonce(
153+
&mut self,
154+
account_address: ContractAddress,
155+
) -> StatefulTransactionValidatorResult<Nonce>;
151156
}
152157

153158
pub struct StatefulTransactionValidator<B: BlockifierStatefulValidatorTrait + Send> {
@@ -165,18 +170,19 @@ impl<B: BlockifierStatefulValidatorTrait + Send> StatefulTransactionValidatorTra
165170
runtime: tokio::runtime::Handle,
166171
) -> StatefulTransactionValidatorResult<Nonce> {
167172
let address = executable_tx.contract_address();
168-
let account_nonce =
169-
self.blockifier_stateful_tx_validator.get_nonce(address).map_err(|e| {
170-
// TODO(noamsp): Fix this. Need to map the errors better.
171-
StarknetError::internal_with_signature_logging(
172-
format!("Failed to get nonce for sender address {address}"),
173-
&executable_tx.signature(),
174-
e,
175-
)
176-
})?;
173+
let account_nonce = self.get_nonce(address)?;
177174
self.run_transaction_validations(executable_tx, account_nonce, mempool_client, runtime)?;
178175
Ok(account_nonce)
179176
}
177+
178+
fn get_nonce(
179+
&mut self,
180+
account_address: ContractAddress,
181+
) -> StatefulTransactionValidatorResult<Nonce> {
182+
self.blockifier_stateful_tx_validator
183+
.get_nonce(account_address)
184+
.map_err(|e| StarknetError::internal_with_logging("Failed to get nonce", e))
185+
}
180186
}
181187

182188
impl<B: BlockifierStatefulValidatorTrait + Send> StatefulTransactionValidator<B> {

0 commit comments

Comments
 (0)