Skip to content

Commit

Permalink
Refactor katana RPC components into smaller crates (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Jan 22, 2024
1 parent 1d86e11 commit 30b900b
Show file tree
Hide file tree
Showing 30 changed files with 487 additions and 296 deletions.
136 changes: 132 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ members = [
"crates/katana/core",
"crates/katana/executor",
"crates/katana/primitives",
"crates/katana/rpc",
"crates/katana/rpc/rpc",
"crates/katana/rpc/rpc-api",
"crates/katana/rpc/rpc-types",
"crates/katana/rpc/rpc-types-builder",
"crates/katana/runner",
Expand Down Expand Up @@ -89,6 +90,7 @@ futures = "0.3.28"
hex = "0.4.3"
indoc = "1.0.7"
itertools = "0.10.3"
jsonrpsee = { version = "0.16.2", default-features = false }
lazy_static = "1.4.0"
metrics-process = "1.0.9"
num-bigint = "0.4"
Expand Down
3 changes: 2 additions & 1 deletion crates/dojo-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ dojo-world = { path = "../dojo-world", features = [ "manifest", "migration" ] }
jsonrpsee = { version = "0.16.2", features = [ "server" ] }
katana-core = { path = "../katana/core" }
katana-primitives = { path = "../katana/primitives" }
katana-rpc = { path = "../katana/rpc" }
katana-rpc = { path = "../katana/rpc/rpc" }
katana-rpc-api = { path = "../katana/rpc/rpc-api" }
scarb-ui.workspace = true
scarb.workspace = true
serde.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo-test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ pub use katana_core::backend::config::{Environment, StarknetConfig};
use katana_core::sequencer::KatanaSequencer;
pub use katana_core::sequencer::SequencerConfig;
use katana_primitives::chain::ChainId;
use katana_rpc::api::ApiKind;
use katana_rpc::config::ServerConfig;
use katana_rpc::{spawn, NodeHandle};
use katana_rpc_api::ApiKind;
use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount};
use starknet::core::chain_id;
use starknet::core::types::FieldElement;
Expand Down
3 changes: 2 additions & 1 deletion crates/katana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ clap_complete.workspace = true
console.workspace = true
katana-core = { path = "core" }
katana-primitives = { path = "primitives" }
katana-rpc = { path = "rpc" }
katana-rpc = { path = "rpc/rpc" }
katana-rpc-api = { path = "rpc/rpc-api" }
metrics = { path = "../metrics" }
metrics-process.workspace = true
serde_json.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/core/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use katana_primitives::FieldElement;
use katana_provider::traits::state::StateWriter;
use rand::rngs::SmallRng;
use rand::{RngCore, SeedableRng};
use serde::Serialize;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet::core::utils::{get_contract_address, get_storage_var_address};
Expand All @@ -15,7 +15,7 @@ use starknet::signers::SigningKey;
use crate::constants::{FEE_TOKEN_ADDRESS, OZ_V1_ACCOUNT_CONTRACT_CLASS_HASH};

#[serde_as]
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Account {
#[serde_as(as = "UfeHex")]
pub balance: FieldElement,
Expand Down
18 changes: 18 additions & 0 deletions crates/katana/rpc/rpc-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
description = "Katana RPC APIs"
edition.workspace = true
name = "katana-rpc-api"
version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
katana-core = { path = "../../core" }
katana-primitives = { path = "../../primitives" }
katana-rpc-types = { path = "../rpc-types" }

jsonrpsee = { workspace = true, features = [ "macros", "server" ] }
starknet.workspace = true

[features]
client = [ "jsonrpsee/client" ]
31 changes: 31 additions & 0 deletions crates/katana/rpc/rpc-api/src/katana.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
use katana_core::accounts::Account;
use katana_primitives::FieldElement;

#[cfg_attr(not(feature = "client"), rpc(server, namespace = "katana"))]
#[cfg_attr(feature = "client", rpc(client, server, namespace = "katana"))]
pub trait KatanaApi {
#[method(name = "generateBlock")]
async fn generate_block(&self) -> RpcResult<()>;

#[method(name = "nextBlockTimestamp")]
async fn next_block_timestamp(&self) -> RpcResult<u64>;

#[method(name = "setNextBlockTimestamp")]
async fn set_next_block_timestamp(&self, timestamp: u64) -> RpcResult<()>;

#[method(name = "increaseNextBlockTimestamp")]
async fn increase_next_block_timestamp(&self, timestamp: u64) -> RpcResult<()>;

#[method(name = "predeployedAccounts")]
async fn predeployed_accounts(&self) -> RpcResult<Vec<Account>>;

#[method(name = "setStorageAt")]
async fn set_storage_at(
&self,
contract_address: FieldElement,
key: FieldElement,
value: FieldElement,
) -> RpcResult<()>;
}
File renamed without changes.
Loading

0 comments on commit 30b900b

Please sign in to comment.