Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
chore: split starknetRPC in two traits to follow openRPC spec definit…
Browse files Browse the repository at this point in the history
…ion (#1274)
  • Loading branch information
tdelabro authored Nov 23, 2023
1 parent 315f70b commit 647965a
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 185 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- chore: split StarknetRpcApi trait in two, like in openRPC specs
- refacto: move starknet runtime api in it's own crate
- chore: update README.md and getting-started.md
- chore: remove crates that have been copy-pasted from plkdtSDK
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

48 changes: 26 additions & 22 deletions crates/client/rpc-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,34 @@ use starknet_core::types::{
#[derive(Serialize, Deserialize)]
pub struct Felt(#[serde_as(as = "UfeHex")] pub FieldElement);

/// Starknet write rpc interface.
#[rpc(server, namespace = "starknet")]
pub trait StarknetWriteRpcApi {
/// Submit a new transaction to be added to the chain
#[method(name = "addInvokeTransaction")]
async fn add_invoke_transaction(
&self,
invoke_transaction: BroadcastedInvokeTransaction,
) -> RpcResult<InvokeTransactionResult>;

/// Submit a new class declaration transaction
#[method(name = "addDeployAccountTransaction")]
async fn add_deploy_account_transaction(
&self,
deploy_account_transaction: BroadcastedDeployAccountTransaction,
) -> RpcResult<DeployAccountTransactionResult>;

/// Submit a new deploy account transaction
#[method(name = "addDeclareTransaction")]
async fn add_declare_transaction(
&self,
declare_transaction: BroadcastedDeclareTransaction,
) -> RpcResult<DeclareTransactionResult>;
}

/// Starknet rpc interface.
#[rpc(server, namespace = "starknet")]
pub trait StarknetRpcApi {
pub trait StarknetReadRpcApi {
/// Get the most recent accepted block number
#[method(name = "blockNumber")]
fn block_number(&self) -> RpcResult<u64>;
Expand Down Expand Up @@ -83,20 +108,6 @@ pub trait StarknetRpcApi {
#[method(name = "chainId")]
fn chain_id(&self) -> RpcResult<Felt>;

/// Add an Invoke Transaction to invoke a contract function
#[method(name = "addInvokeTransaction")]
async fn add_invoke_transaction(
&self,
invoke_transaction: BroadcastedInvokeTransaction,
) -> RpcResult<InvokeTransactionResult>;

/// Add a Deploy Account Transaction
#[method(name = "addDeployAccountTransaction")]
async fn add_deploy_account_transaction(
&self,
deploy_account_transaction: BroadcastedDeployAccountTransaction,
) -> RpcResult<DeployAccountTransactionResult>;

/// Estimate the fee associated with transaction
#[method(name = "estimateFee")]
async fn estimate_fee(
Expand All @@ -121,13 +132,6 @@ pub trait StarknetRpcApi {
#[method(name = "getEvents")]
async fn get_events(&self, filter: EventFilterWithPage) -> RpcResult<EventsPage>;

/// Submit a new transaction to be added to the chain
#[method(name = "addDeclareTransaction")]
async fn add_declare_transaction(
&self,
declare_transaction: BroadcastedDeclareTransaction,
) -> RpcResult<DeclareTransactionResult>;

/// Returns the information about a transaction by transaction hash.
#[method(name = "getTransactionByHash")]
fn get_transaction_by_hash(&self, transaction_hash: FieldElement) -> RpcResult<Transaction>;
Expand Down
1 change: 1 addition & 0 deletions crates/client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ starknet-core = { workspace = true }
starknet-ff = { workspace = true }
starknet_api = { workspace = true, default-features = false }
# Others
anyhow = { workspace = true }
hex = { workspace = true, default-features = true }
jsonrpsee = { workspace = true, default-features = true, features = [
"server",
Expand Down
Loading

0 comments on commit 647965a

Please sign in to comment.