Skip to content

Commit

Permalink
feat: bootstrap v0.4 rpc support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko-von-Leipzig committed Jul 20, 2023
1 parent 8506d75 commit d9da499
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/rpc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum RpcVersion {
V01,
V02,
V03,
V04,
}

impl RpcVersion {
Expand All @@ -23,6 +24,7 @@ impl RpcVersion {
"v0.1" => Self::V01,
"v0.2" => Self::V02,
"v0.3" => Self::V03,
"v0.4" => Self::V04,
_ => Self::default(),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod pathfinder;
pub mod test_client;
pub mod v02;
pub mod v03;
pub mod v04;
pub mod websocket;

use crate::metrics::logger::{MaybeRpcMetricsLogger, RpcMetricsLogger};
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/src/middleware/versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub(crate) async fn prefix_rpc_method_names_with_version(
// that's why we have to account for those separately.
"/rpc/v0.2" | "/rpc/v0.2/" => &[("starknet_", "v0.2_"), ("pathfinder_", "v0.2_")][..],
"/" | "/rpc/v0.3" | "/rpc/v0.3/" => &[("starknet_", "v0.3_"), ("pathfinder_", "v0.3_")][..],
"/rpc/v0.4" | "/rpc/v0.4/" => &[("starknet_", "v0.4_"), ("pathfinder_", "v0.4_")][..],
"/rpc/pathfinder/v0.1" | "/rpc/pathfinder/v0.1/" => &[("pathfinder_", "v0.1_")][..],
_ => {
return Err(BoxError::from(VersioningError::InvalidPath));
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/src/v03/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ mod get_events;
mod get_state_update;
pub(crate) mod simulate_transaction;

pub(super) use estimate_fee::estimate_fee;
pub(crate) use estimate_fee::estimate_fee;
pub(crate) use estimate_message_fee::estimate_message_fee;
pub(super) use get_events::get_events;
pub(super) use get_state_update::get_state_update;
pub(crate) use get_events::get_events;
pub(crate) use get_state_update::get_state_update;
pub(crate) use simulate_transaction::simulate_transaction;

pub(crate) mod common {
Expand Down
88 changes: 88 additions & 0 deletions crates/rpc/src/v04.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use crate::module::Module;

use crate::v02::method as v02_method;
use crate::v03::method as v03_method;

/// Registers all methods for the v0.3 RPC API
pub fn register_methods(module: Module) -> anyhow::Result<Module> {
let module = module
// Reused from v0.2
.register_method(
"v0.4_starknet_addDeclareTransaction",
v02_method::add_declare_transaction,
)?
.register_method(
"v0.4_starknet_addDeployAccountTransaction",
v02_method::add_deploy_account_transaction,
)?
.register_method(
"v0.4_starknet_addInvokeTransaction",
v02_method::add_invoke_transaction,
)?
.register_method_with_no_input(
"v0.4_starknet_blockHashAndNumber",
v02_method::block_hash_and_number,
)?
.register_method_with_no_input("v0.4_starknet_blockNumber", v02_method::block_number)?
.register_method("v0.4_starknet_call", v02_method::call)?
.register_method_with_no_input("v0.4_starknet_chainId", v02_method::chain_id)?
.register_method("v0.4_starknet_estimateFee", v03_method::estimate_fee)?
.register_method(
"v0.4_starknet_getBlockWithTxHashes",
v02_method::get_block_with_tx_hashes,
)?
.register_method(
"v0.4_starknet_getBlockWithTxs",
v02_method::get_block_with_txs,
)?
.register_method(
"v0.4_starknet_getBlockTransactionCount",
v02_method::get_block_transaction_count,
)?
.register_method("v0.4_starknet_getClass", v02_method::get_class)?
.register_method("v0.4_starknet_getClassAt", v02_method::get_class_at)?
.register_method(
"v0.4_starknet_getClassHashAt",
v02_method::get_class_hash_at,
)?
.register_method("v0.4_starknet_getNonce", v02_method::get_nonce)?
.register_method("v0.4_starknet_getStorageAt", v02_method::get_storage_at)?
.register_method(
"v0.4_starknet_getTransactionByBlockIdAndIndex",
v02_method::get_transaction_by_block_id_and_index,
)?
.register_method(
"v0.4_starknet_getTransactionByHash",
v02_method::get_transaction_by_hash,
)?
.register_method(
"v0.4_starknet_getTransactionReceipt",
v02_method::get_transaction_receipt,
)?
.register_method_with_no_input(
"v0.4_starknet_pendingTransactions",
v02_method::pending_transactions,
)?
.register_method_with_no_input("v0.4_starknet_syncing", v02_method::syncing)?
// Specific implementations for v0.3
.register_method("v0.4_starknet_getEvents", v03_method::get_events)?
.register_method("v0.4_starknet_getStateUpdate", v03_method::get_state_update)?
.register_method(
"v0.4_starknet_simulateTransaction",
v03_method::simulate_transaction,
)?
.register_method(
"v0.4_starknet_estimateMessageFee",
v03_method::estimate_message_fee,
)?
.register_method(
"v0.4_pathfinder_getProof",
crate::pathfinder::methods::get_proof,
)?
.register_method(
"v0.4_pathfinder_getTransactionStatus",
crate::pathfinder::methods::get_transaction_status,
)?;

Ok(module)
}

0 comments on commit d9da499

Please sign in to comment.