Skip to content

Commit b2e3e18

Browse files
apollo_gateway: add get_nonce function to StatefulValidator trait
1 parent 1fcf56b commit b2e3e18

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
@@ -20,7 +20,7 @@ use blockifier::transaction::account_transaction::{AccountTransaction, Execution
2020
use blockifier::transaction::transactions::enforce_fee;
2121
use num_rational::Ratio;
2222
use starknet_api::block::{BlockInfo, NonzeroGasPrice};
23-
use starknet_api::core::Nonce;
23+
use starknet_api::core::{ContractAddress, Nonce};
2424
use starknet_api::executable_transaction::{
2525
AccountTransaction as ExecutableTransaction,
2626
InvokeTransaction as ExecutableInvokeTransaction,
@@ -135,6 +135,11 @@ pub trait StatefulTransactionValidatorTrait: Send {
135135
mempool_client: SharedMempoolClient,
136136
runtime: tokio::runtime::Handle,
137137
) -> StatefulTransactionValidatorResult<Nonce>;
138+
139+
fn get_nonce(
140+
&mut self,
141+
account_address: ContractAddress,
142+
) -> StatefulTransactionValidatorResult<Nonce>;
138143
}
139144

140145
pub struct StatefulTransactionValidator<B: BlockifierStatefulValidatorTrait + Send> {
@@ -152,18 +157,19 @@ impl<B: BlockifierStatefulValidatorTrait + Send> StatefulTransactionValidatorTra
152157
runtime: tokio::runtime::Handle,
153158
) -> StatefulTransactionValidatorResult<Nonce> {
154159
let address = executable_tx.contract_address();
155-
let account_nonce =
156-
self.blockifier_stateful_tx_validator.get_nonce(address).map_err(|e| {
157-
// TODO(noamsp): Fix this. Need to map the errors better.
158-
StarknetError::internal_with_signature_logging(
159-
format!("Failed to get nonce for sender address {address}"),
160-
&executable_tx.signature(),
161-
e,
162-
)
163-
})?;
160+
let account_nonce = self.get_nonce(address)?;
164161
self.run_transaction_validations(executable_tx, account_nonce, mempool_client, runtime)?;
165162
Ok(account_nonce)
166163
}
164+
165+
fn get_nonce(
166+
&mut self,
167+
account_address: ContractAddress,
168+
) -> StatefulTransactionValidatorResult<Nonce> {
169+
self.blockifier_stateful_tx_validator
170+
.get_nonce(account_address)
171+
.map_err(|e| StarknetError::internal_with_logging("Failed to get nonce", e))
172+
}
167173
}
168174

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

0 commit comments

Comments
 (0)