Skip to content

Commit

Permalink
add v0.4.0 not connected to endpoint (#877)
Browse files Browse the repository at this point in the history
feat(JSON-RPC): add v0.4.0 not connected to endpoint
  • Loading branch information
nagmo-starkware authored Jul 27, 2023
1 parent e9f5ee1 commit fa68afc
Show file tree
Hide file tree
Showing 14 changed files with 6,100 additions and 1 deletion.
2,867 changes: 2,867 additions & 0 deletions crates/papyrus_gateway/resources/V0_4_0_starknet_api_openrpc.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/papyrus_gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod middleware;
mod test_utils;
mod transaction;
mod v0_3_0;
mod v0_4_0;
mod version_config;
#[cfg(test)]
mod version_config_test;
Expand Down
2 changes: 2 additions & 0 deletions crates/papyrus_gateway/src/v0_3_0/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ impl JsonRpcV0_3_0Server for JsonRpcServerV0_3_0Impl {

let output = TransactionOutput::from_thin_transaction_output(thin_tx_output, events);

// todo: nevo - check what the expected behavior is when the transaction is reverted
// todo: nevo - check the meaning of the rejected status
Ok(TransactionReceiptWithStatus {
receipt: TransactionReceipt { transaction_hash, block_hash, block_number, output },
status: status.into(),
Expand Down
450 changes: 450 additions & 0 deletions crates/papyrus_gateway/src/v0_4_0/api/api_impl.rs

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions crates/papyrus_gateway/src/v0_4_0/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
use papyrus_common::SyncingState;
use papyrus_proc_macros::versioned_rpc;
use serde::{Deserialize, Serialize};
use starknet_api::block::BlockNumber;
use starknet_api::core::{ClassHash, ContractAddress, Nonce};
use starknet_api::hash::StarkFelt;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{TransactionHash, TransactionOffsetInBlock};

use super::block::Block;
use super::deprecated_contract_class::ContractClass as DeprecatedContractClass;
use super::state::{ContractClass, StateUpdate};
use super::transaction::{Event, TransactionReceiptWithStatus, TransactionWithHash};
use crate::api::{BlockHashAndNumber, BlockId, ContinuationToken, EventFilter};

pub mod api_impl;
#[cfg(test)]
mod test;

#[versioned_rpc("V0_4_0")]
pub trait JsonRpc {
/// Gets the most recent accepted block number.
#[method(name = "blockNumber")]
fn block_number(&self) -> RpcResult<BlockNumber>;

/// Gets the most recent accepted block hash and number.
#[method(name = "blockHashAndNumber")]
fn block_hash_and_number(&self) -> RpcResult<BlockHashAndNumber>;

/// Gets block information with transaction hashes given a block identifier.
#[method(name = "getBlockWithTxHashes")]
fn get_block_w_transaction_hashes(&self, block_id: BlockId) -> RpcResult<Block>;

/// Gets block information with full transactions given a block identifier.
#[method(name = "getBlockWithTxs")]
fn get_block_w_full_transactions(&self, block_id: BlockId) -> RpcResult<Block>;

/// Gets the value of the storage at the given address, key, and block.
#[method(name = "getStorageAt")]
fn get_storage_at(
&self,
contract_address: ContractAddress,
key: StorageKey,
block_id: BlockId,
) -> RpcResult<StarkFelt>;

/// Gets the details of a submitted transaction.
#[method(name = "getTransactionByHash")]
fn get_transaction_by_hash(
&self,
transaction_hash: TransactionHash,
) -> RpcResult<TransactionWithHash>;

/// Gets the details of a transaction by a given block id and index.
#[method(name = "getTransactionByBlockIdAndIndex")]
fn get_transaction_by_block_id_and_index(
&self,
block_id: BlockId,
index: TransactionOffsetInBlock,
) -> RpcResult<TransactionWithHash>;

/// Gets the number of transactions in a block given a block id.
#[method(name = "getBlockTransactionCount")]
fn get_block_transaction_count(&self, block_id: BlockId) -> RpcResult<usize>;

/// Gets the information about the result of executing the requested block.
#[method(name = "getStateUpdate")]
fn get_state_update(&self, block_id: BlockId) -> RpcResult<StateUpdate>;

/// Gets the transaction receipt by the transaction hash.
#[method(name = "getTransactionReceipt")]
fn get_transaction_receipt(
&self,
transaction_hash: TransactionHash,
) -> RpcResult<TransactionReceiptWithStatus>;

/// Gets the contract class definition associated with the given hash.
#[method(name = "getClass")]
fn get_class(
&self,
block_id: BlockId,
class_hash: ClassHash,
) -> RpcResult<GatewayContractClass>;

/// Gets the contract class definition in the given block at the given address.
#[method(name = "getClassAt")]
fn get_class_at(
&self,
block_id: BlockId,
contract_address: ContractAddress,
) -> RpcResult<GatewayContractClass>;

/// Gets the contract class hash in the given block for the contract deployed at the given
/// address.
#[method(name = "getClassHashAt")]
fn get_class_hash_at(
&self,
block_id: BlockId,
contract_address: ContractAddress,
) -> RpcResult<ClassHash>;

/// Gets the nonce associated with the given address in the given block.
#[method(name = "getNonce")]
fn get_nonce(&self, block_id: BlockId, contract_address: ContractAddress) -> RpcResult<Nonce>;

/// Returns the currently configured StarkNet chain id.
#[method(name = "chainId")]
fn chain_id(&self) -> RpcResult<String>;

/// Returns all events matching the given filter.
#[method(name = "getEvents")]
fn get_events(&self, filter: EventFilter) -> RpcResult<EventsChunk>;

/// Returns the synching status of the node, or false if the node is not synching.
#[method(name = "syncing")]
fn syncing(&self) -> RpcResult<SyncingState>;
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum GatewayContractClass {
Cairo0(DeprecatedContractClass),
Sierra(ContractClass),
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct EventsChunk {
pub events: Vec<Event>,
pub continuation_token: Option<ContinuationToken>,
}
Loading

0 comments on commit fa68afc

Please sign in to comment.