Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(katana): implement more feeder gateway types #2744

Merged
merged 15 commits into from
Dec 2, 2024
21 changes: 20 additions & 1 deletion crates/katana/executor/src/implementation/blockifier/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use katana_cairo::cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use katana_cairo::starknet_api::block::{BlockNumber, BlockTimestamp};
use katana_cairo::starknet_api::core::{
self, ChainId, ClassHash, CompiledClassHash, ContractAddress, Nonce,
self, ChainId, ClassHash, CompiledClassHash, ContractAddress, EntryPointSelector, Nonce,
};
use katana_cairo::starknet_api::data_availability::DataAvailabilityMode;
use katana_cairo::starknet_api::deprecated_contract_class::EntryPointType;
Expand Down Expand Up @@ -184,6 +184,25 @@

match tx.transaction {
ExecutableTx::Invoke(tx) => match tx {
InvokeTx::V0(tx) => {
let calldata = tx.calldata;
let signature = tx.signature;

Transaction::AccountTransaction(AccountTransaction::Invoke(InvokeTransaction {
tx: ApiInvokeTransaction::V0(
katana_cairo::starknet_api::transaction::InvokeTransactionV0 {
entry_point_selector: EntryPointSelector(tx.entry_point_selector),
contract_address: to_blk_address(tx.contract_address),
signature: TransactionSignature(signature),
calldata: Calldata(Arc::new(calldata)),
max_fee: Fee(tx.max_fee),
},
),
tx_hash: TransactionHash(hash),
only_query: false,
}))

Check warning on line 203 in crates/katana/executor/src/implementation/blockifier/utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/executor/src/implementation/blockifier/utils.rs#L187-L203

Added lines #L187 - L203 were not covered by tests
}

InvokeTx::V1(tx) => {
let calldata = tx.calldata;
let signature = tx.signature;
Expand Down
21 changes: 11 additions & 10 deletions crates/katana/feeder-gateway/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
block_id: BlockIdOrTag,
) -> Result<StateUpdateWithBlock, Error> {
self.feeder_gateway("get_state_update")
.with_query_param("includeBlock", "true")
.add_query_param("includeBlock", "true")

Check warning on line 60 in crates/katana/feeder-gateway/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/feeder-gateway/src/client.rs#L60

Added line #L60 was not covered by tests
.with_block_id(block_id)
.send()
.await
Expand All @@ -69,7 +69,7 @@
block_id: BlockIdOrTag,
) -> Result<ContractClass, Error> {
self.feeder_gateway("get_class_by_hash")
.with_query_param("classHash", &format!("{hash:#x}"))
.add_query_param("classHash", &format!("{hash:#x}"))

Check warning on line 72 in crates/katana/feeder-gateway/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/feeder-gateway/src/client.rs#L72

Added line #L72 was not covered by tests
.with_block_id(block_id)
.send()
.await
Expand All @@ -81,7 +81,7 @@
block_id: BlockIdOrTag,
) -> Result<CasmContractClass, Error> {
self.feeder_gateway("get_compiled_class_by_class_hash")
.with_query_param("classHash", &format!("{hash:#x}"))
.add_query_param("classHash", &format!("{hash:#x}"))

Check warning on line 84 in crates/katana/feeder-gateway/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/feeder-gateway/src/client.rs#L84

Added line #L84 was not covered by tests
.with_block_id(block_id)
.send()
.await
Expand Down Expand Up @@ -112,13 +112,13 @@
match block_id {
// latest block is implied, if no block id specified
BlockIdOrTag::Tag(BlockTag::Latest) => self,
BlockIdOrTag::Tag(BlockTag::Pending) => self.with_query_param("blockNumber", "pending"),
BlockIdOrTag::Hash(hash) => self.with_query_param("blockHash", &format!("{hash:#x}")),
BlockIdOrTag::Number(num) => self.with_query_param("blockNumber", &num.to_string()),
BlockIdOrTag::Tag(BlockTag::Pending) => self.add_query_param("blockNumber", "pending"),
BlockIdOrTag::Hash(hash) => self.add_query_param("blockHash", &format!("{hash:#x}")),
BlockIdOrTag::Number(num) => self.add_query_param("blockNumber", &num.to_string()),
}
}

fn with_query_param(mut self, key: &str, value: &str) -> Self {
fn add_query_param(mut self, key: &str, value: &str) -> Self {
self.url.query_pairs_mut().append_pair(key, value);
self
}
Expand Down Expand Up @@ -181,6 +181,7 @@

#[cfg(test)]
mod tests {

use super::*;

#[test]
Expand Down Expand Up @@ -214,9 +215,9 @@
let req = RequestBuilder { client: &client, url: base_url };

let url = req
.with_query_param("param1", "value1")
.with_query_param("param2", "value2")
.with_query_param("param3", "value3")
.add_query_param("param1", "value1")
.add_query_param("param2", "value2")
.add_query_param("param3", "value3")
.url;

let query = url.query().unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
use std::collections::{BTreeMap, BTreeSet};

use katana_primitives::block::{BlockHash, BlockNumber};
pub use katana_primitives::class::CasmContractClass;
use katana_primitives::class::{
ClassHash, CompiledClassHash, LegacyContractClass, SierraContractClass,
};
use katana_primitives::contract::{Nonce, StorageKey, StorageValue};
use katana_primitives::da::L1DataAvailabilityMode;
use katana_primitives::version::ProtocolVersion;
use katana_primitives::{ContractAddress, Felt};
use katana_rpc_types::class::ConversionError;
pub use katana_rpc_types::class::RpcSierraContractClass;
use serde::Deserialize;
use starknet::providers::sequencer::models::Block;
use starknet::core::types::ResourcePrice;
use starknet::providers::sequencer::models::BlockStatus;

mod receipt;
mod transaction;

pub use receipt::*;
pub use transaction::*;

/// The contract class type returns by `/get_class_by_hash` endpoint.
#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -63,6 +73,35 @@
pub block: Block,
}

// The reason why we're not using the GasPrices from the `katana_primitives` crate is because
// the serde impl is different. So for now, lets just use starknet-rs types. The type isn't
// that complex anyway so the conversion is simple. But if we can use the primitive types, we
// should.
#[derive(Debug, Deserialize)]

Check warning on line 80 in crates/katana/feeder-gateway/src/types/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/feeder-gateway/src/types/mod.rs#L80

Added line #L80 was not covered by tests
pub struct Block {
#[serde(default)]
pub block_hash: Option<BlockHash>,
#[serde(default)]
pub block_number: Option<BlockNumber>,
pub parent_block_hash: BlockHash,
pub timestamp: u64,
pub sequencer_address: Option<ContractAddress>,
#[serde(default)]
pub state_root: Option<Felt>,
#[serde(default)]
pub transaction_commitment: Option<Felt>,
#[serde(default)]
pub event_commitment: Option<Felt>,
pub status: BlockStatus,
pub l1_da_mode: L1DataAvailabilityMode,
pub l1_gas_price: ResourcePrice,
pub l1_data_gas_price: ResourcePrice,
pub transactions: Vec<ConfirmedTransaction>,
pub transaction_receipts: Vec<ConfirmedReceipt>,
#[serde(default)]
pub starknet_version: Option<ProtocolVersion>,
}

// -- Conversion to Katana primitive types.

impl TryFrom<ContractClass> for katana_primitives::class::ContractClass {
Expand Down
22 changes: 22 additions & 0 deletions crates/katana/feeder-gateway/src/types/receipt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use katana_primitives::receipt::{Event, MessageToL1};
use katana_primitives::Felt;
use serde::Deserialize;
use starknet::providers::sequencer::models::{
ExecutionResources, L1ToL2Message, TransactionExecutionStatus,
};

#[derive(Debug, Deserialize)]

Check warning on line 8 in crates/katana/feeder-gateway/src/types/receipt.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/feeder-gateway/src/types/receipt.rs#L8

Added line #L8 was not covered by tests
pub struct ConfirmedReceipt {
pub transaction_hash: Felt,
pub transaction_index: u64,
#[serde(default)]
pub execution_status: Option<TransactionExecutionStatus>,
#[serde(default)]
pub revert_error: Option<String>,
#[serde(default)]
pub execution_resources: Option<ExecutionResources>,
pub l1_to_l2_consumed_message: Option<L1ToL2Message>,
pub l2_to_l1_messages: Vec<MessageToL1>,
pub events: Vec<Event>,
pub actual_fee: Felt,
}
Loading
Loading