Skip to content

Commit

Permalink
fix call
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Feb 23, 2024
1 parent f02e1b9 commit 9041b25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
15 changes: 1 addition & 14 deletions crates/katana/core/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::slice::Iter;
use std::sync::Arc;

use anyhow::Result;
use katana_executor::{EntryPointCall, ExecutorFactory};
use katana_executor::ExecutorFactory;
use katana_primitives::block::{BlockHash, BlockHashOrNumber, BlockIdOrTag, BlockNumber};
use katana_primitives::chain::ChainId;
use katana_primitives::class::{ClassHash, CompiledClass};
Expand Down Expand Up @@ -303,19 +303,6 @@ impl<EF: ExecutorFactory> KatanaSequencer<EF> {
Ok(nonce)
}

pub fn call(
&self,
request: EntryPointCall,
block_id: BlockIdOrTag,
) -> SequencerResult<Vec<FieldElement>> {
let state = self.state(&block_id)?;
let env = self.block_env_at(block_id)?.ok_or(SequencerError::BlockNotFound(block_id))?;
let executor = self.backend.executor_factory.with_state_and_block_env(state, env);

let retdata = executor.call(request, 1_000_000).unwrap();
Ok(retdata)
}

pub fn transaction(&self, hash: &TxHash) -> SequencerResult<Option<TxWithHash>> {
let tx =
TransactionProvider::transaction_by_hash(self.backend.blockchain.provider(), *hash)?;
Expand Down
20 changes: 17 additions & 3 deletions crates/katana/rpc/rpc/src/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,23 @@ impl<EF: ExecutorFactory> StarknetApiServer for StarknetApi<EF> {
entry_point_selector: request.entry_point_selector,
};

let res =
this.inner.sequencer.call(request, block_id).map_err(StarknetApiError::from)?;
Ok(res.into_iter().map(|v| v.into()).collect())
let sequencer = &this.inner.sequencer;

// get the state and block env at the specified block for function call execution
let state = sequencer.state(&block_id).map_err(StarknetApiError::from)?;
let env = sequencer
.block_env_at(block_id)
.map_err(StarknetApiError::from)?
.ok_or(StarknetApiError::BlockNotFound)?;

let executor = sequencer.backend.executor_factory.with_state_and_block_env(state, env);

match executor.call(request, 1_000_000_000) {
Ok(retdata) => Ok(retdata.into_iter().map(|v| v.into()).collect()),
Err(err) => Err(Error::from(StarknetApiError::ContractError {
revert_error: err.to_string(),
})),

Check warning on line 449 in crates/katana/rpc/rpc/src/starknet.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/rpc/rpc/src/starknet.rs#L447-L449

Added lines #L447 - L449 were not covered by tests
}
})
.await
}
Expand Down

0 comments on commit 9041b25

Please sign in to comment.