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(rpc/v0.7): configuration and skeleton #1779

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/pathfinder/src/bin/pathfinder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ impl Color {
pub enum RpcVersion {
V05,
V06,
V07,
}

#[derive(clap::Args)]
Expand Down
1 change: 1 addition & 0 deletions crates/pathfinder/src/bin/pathfinder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Hint: This is usually caused by exceeding the file descriptor limit of your syst
let default_version = match config.rpc_root_version {
config::RpcVersion::V05 => pathfinder_rpc::DefaultVersion::V05,
config::RpcVersion::V06 => pathfinder_rpc::DefaultVersion::V06,
config::RpcVersion::V07 => pathfinder_rpc::DefaultVersion::V07,
};

let rpc_server = pathfinder_rpc::RpcServer::new(config.rpc_address, context, default_version);
Expand Down
43 changes: 43 additions & 0 deletions crates/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod v03;
pub mod v04;
pub mod v05;
pub mod v06;
pub mod v07;

pub use executor::compose_executor_transaction;
pub use pending::PendingData;
Expand Down Expand Up @@ -43,6 +44,7 @@ const DEFAULT_MAX_CONNECTIONS: usize = 1024;
pub enum DefaultVersion {
V05,
V06,
V07,
}

pub struct RpcServer {
Expand Down Expand Up @@ -143,11 +145,13 @@ impl RpcServer {

let v05_routes = v05::register_routes().build(self.context.clone());
let v06_routes = v06::register_routes().build(self.context.clone());
let v07_routes = v07::register_routes().build(self.context.clone());
let pathfinder_routes = pathfinder::register_routes().build(self.context.clone());

let default_router = match self.default_version {
DefaultVersion::V05 => v05_routes.clone(),
DefaultVersion::V06 => v06_routes.clone(),
DefaultVersion::V07 => v07_routes.clone(),
};

let router = axum::Router::new()
Expand All @@ -160,6 +164,8 @@ impl RpcServer {
.with_state(v05_routes)
.route("/rpc/v0_6", post(rpc_handler))
.with_state(v06_routes)
.route("/rpc/v0_7", post(rpc_handler))
.with_state(v07_routes)
.route("/rpc/pathfinder/v0.1", post(rpc_handler))
.with_state(pathfinder_routes);

Expand Down Expand Up @@ -806,6 +812,43 @@ mod tests {
#[case::root_write("/", "v05/starknet_write_api.json", &[])]
#[case::root_pathfinder("/", "pathfinder_rpc_api.json", &["pathfinder_version"])]

#[case::v0_7_api ("/rpc/v0_7", "v07/starknet_api_openrpc.json", &[
"starknet_blockHashAndNumber",
"starknet_blockNumber",
"starknet_chainId",
"starknet_getBlockTransactionCount",
"starknet_getClass",
"starknet_getClassAt",
"starknet_getClassHashAt",
"starknet_getNonce",
"starknet_getStorageAt",
"starknet_getEvents",
"starknet_getStateUpdate",
"starknet_syncing",
"starknet_call",
"starknet_getTransactionStatus",
"starknet_estimateFee",
"starknet_estimateMessageFee",
"starknet_getBlockWithTxHashes",
"starknet_getBlockWithTxs",
"starknet_getTransactionByBlockIdAndIndex",
"starknet_getTransactionByHash",
"starknet_getTransactionReceipt",
"starknet_getBlockWithReceipts",
])]
#[case::v0_7_trace("/rpc/v0_7", "v07/starknet_trace_api_openrpc.json", &[
"starknet_simulateTransactions",
"starknet_traceBlockTransactions",
"starknet_traceTransaction",
])]
#[case::v0_7_write("/rpc/v0_7", "v07/starknet_write_api.json", &[
"starknet_addDeclareTransaction",
"starknet_addDeployAccountTransaction",
"starknet_addInvokeTransaction",
])]
// get_transaction_status is now part of the official spec, so we are phasing it out.
#[case::v0_7_pathfinder("/rpc/v0_7", "pathfinder_rpc_api.json", &["pathfinder_version", "pathfinder_getTransactionStatus"])]

#[case::v0_6_api ("/rpc/v0_6", "v06/starknet_api_openrpc.json", &[])]
#[case::v0_6_trace("/rpc/v0_6", "v06/starknet_trace_api_openrpc.json", &[])]
#[case::v0_6_write("/rpc/v0_6", "v06/starknet_write_api.json", &[])]
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/src/v06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::v05::method as v05_method;

#[rustfmt::skip]
pub fn register_routes() -> RpcRouterBuilder {
RpcRouter::builder("v0.5")
RpcRouter::builder("v0.6")
.register("starknet_blockHashAndNumber" , v02_method::block_hash_and_number)
.register("starknet_blockNumber" , v02_method::block_number)
.register("starknet_chainId" , v02_method::chain_id)
Expand Down
40 changes: 40 additions & 0 deletions crates/rpc/src/v07.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::jsonrpc::{RpcRouter, RpcRouterBuilder};

#[rustfmt::skip]
pub fn register_routes() -> RpcRouterBuilder {
RpcRouter::builder("v0.7")
// .register("starknet_blockHashAndNumber" , v02_method::block_hash_and_number)
// .register("starknet_blockNumber" , v02_method::block_number)
// .register("starknet_chainId" , v02_method::chain_id)
// .register("starknet_getBlockTransactionCount" , v02_method::get_block_transaction_count)
// .register("starknet_getClass" , v02_method::get_class)
// .register("starknet_getClassAt" , v02_method::get_class_at)
// .register("starknet_getClassHashAt" , v02_method::get_class_hash_at)
// .register("starknet_getNonce" , v02_method::get_nonce)
// .register("starknet_getStorageAt" , v02_method::get_storage_at)

// .register("starknet_getEvents" , v03_method::get_events)
// .register("starknet_getStateUpdate" , v03_method::get_state_update)

// .register("starknet_syncing" , v04_method::syncing)

// .register("starknet_call" , v05_method::call)
// .register("starknet_getTransactionStatus" , v05_method::get_transaction_status)

// .register("starknet_addDeclareTransaction" , method::add_declare_transaction)
// .register("starknet_addDeployAccountTransaction" , method::add_deploy_account_transaction)
// .register("starknet_addInvokeTransaction" , method::add_invoke_transaction)
// .register("starknet_estimateFee" , method::estimate_fee)
// .register("starknet_estimateMessageFee" , method::estimate_message_fee)
// .register("starknet_getBlockWithTxHashes" , method::get_block_with_tx_hashes)
// .register("starknet_getBlockWithTxs" , method::get_block_with_txs)
// .register("starknet_getTransactionByBlockIdAndIndex" , method::get_transaction_by_block_id_and_index)
// .register("starknet_getTransactionByHash" , method::get_transaction_by_hash)
// .register("starknet_getTransactionReceipt" , method::get_transaction_receipt)
// .register("starknet_simulateTransactions" , method::simulate_transactions)
.register("starknet_specVersion" , || "0.7.0-rc0")
// .register("starknet_traceBlockTransactions" , method::trace_block_transactions)
// .register("starknet_traceTransaction" , method::trace_transaction)

.register("pathfinder_getProof" , crate::pathfinder::methods::get_proof)
}
Loading
Loading