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

RPC version 0.4.0 #157

Merged
merged 65 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
dab7e6d
Merge branch 'main' into cases/rpc/0.4.0-main
Aug 17, 2023
dd7a36d
Merge branch 'cases/rpc/0.4.0-main' into cases/rpc/get_transaction_by…
Aug 17, 2023
f8f718c
Types defined by rpc spec - moved to rpc submodule
Aug 17, 2023
ea43ffa
Follow up. Forgot to stage file
Aug 17, 2023
01b55fb
Moved Result definitions to error module + renamings
Aug 17, 2023
fb87a7f
formatting applied
Aug 17, 2023
745198f
reimported rpc::felt
Aug 17, 2023
79b91e5
fmt applied
Aug 17, 2023
fc77076
Merge branch 'cases/refactoring/rpc-types' into cases/rpc/get_transac…
Aug 17, 2023
d443d78
Moved transactions into types/rpc
Aug 17, 2023
c3e31d7
starknet/DeclareTransaction replaced
Aug 18, 2023
fdba2e6
Using types/rpc transactions
Aug 19, 2023
172b39d
Test compile
Aug 19, 2023
fadf7dd
Uncommented tests. 1 not passing
Aug 21, 2023
42f4b92
Resolve conflicts + some refactoring
Aug 22, 2023
4251fc8
deploy_transaction_receipt fix
Aug 22, 2023
0832600
Fix estimate_fee test
Aug 22, 2023
8334ec7
Pre deletes
Aug 22, 2023
c012a52
Some file removals
Aug 22, 2023
8bba4f6
Unused code removed + rmt applied
Aug 22, 2023
40b929f
Warnings + tests fixed
Aug 22, 2023
e03356c
Fmt + clippy applied
Aug 22, 2023
57d2d65
Merge branch 'main' into cases/refactoring/rpc-types
Aug 22, 2023
9eb8a6f
Merge branch 'main' into cases/merge/rpc-tx-refactoring
Aug 22, 2023
a3e7be6
Merge branch 'cases/refactoring/rpc-types' into cases/merge/rpc-tx-re…
Aug 22, 2023
1cc9925
Merge branch 'main' into cases/merge/rpc-tx-refactoring
Aug 22, 2023
608824a
Removed dir
Aug 22, 2023
5cf2b72
revert test changes
Aug 23, 2023
bb2a7d2
Renamings + pr fixes
Aug 24, 2023
a1be99b
Some of todos
Aug 24, 2023
6c086fb
Todo's removed
Aug 26, 2023
8972646
Raised version to 0.4.0
Aug 26, 2023
159a15f
Version raised, transaction status fixes + compilation fixed
Aug 28, 2023
a5388f1
New files
Aug 29, 2023
a380100
PendingTransaction fixes
Aug 29, 2023
0701750
clippy checks fixes + tests, removed TxReceipWithType
Aug 30, 2023
840ebbf
BROADCASTED_INVOKE_TX_V0 removed
Aug 30, 2023
a7472a0
BROADCASTED_INVOKE_TX_V0 removed
Aug 30, 2023
c522f0e
Used serde::tag instead of r#type
Aug 31, 2023
41d4821
Merge branch 'cases/merge/rpc-tx-refactoring' into cases/rpc-0.4.0/sr…
Aug 31, 2023
c4c275a
Merge fixes
Aug 31, 2023
bf1dd96
Fix ci/cd
Aug 31, 2023
349d549
Merge branch 'cases/merge/rpc-tx-refactoring' into cases/rpc-0.4.0/sr…
Aug 31, 2023
c86f01a
upd cargo lock
Aug 31, 2023
b5552db
Added estimate_message_fee
Sep 2, 2023
87602f3
Pre FeeEstimate refactoring
Sep 2, 2023
f68ab1a
estimate_message_fee without tests + some refactoring
Sep 2, 2023
058ab2f
Implement macro for wrappers
Sep 2, 2023
3097e9f
macro utils
Sep 2, 2023
53694d2
Added test for estimate_message_fee + tests refactoring example
Sep 4, 2023
e368575
Added some conversions
Sep 4, 2023
1c7cc00
BlockNotFound test
Sep 4, 2023
2cbb9ad
Error code fixed
Sep 4, 2023
42223fb
Merge branch 'cases/rpc-0.4.0/broadcasted-invoke-tx' into cases/rpc-0…
Sep 4, 2023
1a89965
Some fixes
Sep 4, 2023
b3c17b9
Merge branch 'main' into cases/rpc-0.4.0/sr-version-raised
Sep 5, 2023
3247e8b
Update crates/starknet-server/tests/get_transaction_receipt_by_hash.rs
ivpavici Sep 6, 2023
6dfc909
Update crates/starknet/src/starknet/add_invoke_transaction.rs
ivpavici Sep 6, 2023
2cf0d83
Changed starknet-rs versions + fixes
Sep 6, 2023
735d9a1
Merge branch 'cases/rpc-0.4.0/sr-version-raised' of github.com:0xSpac…
Sep 6, 2023
35f4d37
PR fixes
Sep 6, 2023
12480d0
Test changes reverted
Sep 6, 2023
c897e0d
Merge branch 'main' into cases/rpc-0.4.0/sr-version-raised
Sep 6, 2023
784a4a7
Compilation fix
Sep 6, 2023
b5b50e6
Extract l1 handler to constant [skip ci]
FabijanC Sep 6, 2023
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
127 changes: 105 additions & 22 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ anyhow = "1"
# Starknet dependencies
starknet_api = { version = "0.3.0", features = ["testing"] }
starknet-in-rust = { git = "https://github.com/lambdaclass/starknet_in_rust", rev = "f05da40", package="starknet_in_rust" }
starknet-rs-signers = { version = "0.3.0", package = "starknet-signers" }
starknet-rs-signers = { version = "0.4.0", package="starknet-signers" }
starknet-rs-ff = { version = "0.3.4", package = "starknet-ff" }
starknet-rs-core = { version = "0.5.1", package = "starknet-core" }
starknet-rs-providers = { version = "0.5.0", package = "starknet-providers" }
starknet-rs-accounts = { version = "0.4.0", package = "starknet-accounts" }
starknet-rs-contract = { version = "0.4.0", package = "starknet-contract" }
starknet-rs-core = { version = "0.6.0", package = "starknet-core" }
starknet-rs-providers = { version = "0.6.0", package = "starknet-providers" }
starknet-rs-accounts = { version = "0.5.0", package = "starknet-accounts" }
starknet-rs-contract = { version = "0.5.0", package = "starknet-contract" }
cairo-felt = { version = "0.8.5", package = "cairo-felt" }
url = "2.4"

Expand Down
1 change: 1 addition & 0 deletions crates/starknet-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ lazy_static = { workspace = true }
starknet-rs-accounts = { workspace = true }
starknet-rs-contract = { workspace = true }
starknet-rs-signers = { workspace = true }
starknet-core = { workspace = true, features = ["test_utils"] }
42 changes: 25 additions & 17 deletions crates/starknet-server/src/api/json_rpc/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ use starknet_core::error::Error;
use starknet_in_rust::core::errors::state_errors::StateError;
use starknet_in_rust::transaction::error::TransactionError;
use starknet_in_rust::utils::Address;
use starknet_rs_core::types::ContractClass as CodegenContractClass;
use starknet_rs_core::types::{ContractClass as CodegenContractClass, MsgFromL1};
use starknet_types::contract_address::ContractAddress;
use starknet_types::felt::{ClassHash, Felt, TransactionHash};
use starknet_types::rpc::block::{Block, BlockHeader};
use starknet_types::rpc::block::{Block, BlockHeader, BlockId};
use starknet_types::rpc::estimate_message_fee::FeeEstimateWrapper;
use starknet_types::rpc::transaction_receipt::TransactionReceipt;
use starknet_types::rpc::transactions::{
BroadcastedTransaction, EventFilter, EventsChunk, FunctionCall, Transaction,
TransactionReceiptWithStatus,
};
use starknet_types::starknet_api::block::BlockNumber;
use starknet_types::traits::ToHexString;

use super::error::ApiError;
use super::models::{BlockHashAndNumberOutput, EstimateFeeOutput, SyncingOutput};
use super::models::{BlockHashAndNumberOutput, SyncingOutput};
use super::JsonRpcHandler;
use crate::api::json_rpc::error::RpcResult;
use crate::api::models::state::{
ClassHashes, ContractNonce, DeployedContract, StateUpdate, StorageDiff, StorageEntry,
ThinStateDiff,
};
use crate::api::models::{BlockId, PatriciaKeyHex};
use crate::api::models::PatriciaKeyHex;

const DEFAULT_CONTINUATION_TOKEN: &str = "0";

Expand Down Expand Up @@ -168,7 +169,7 @@ impl JsonRpcHandler {
pub(crate) async fn get_transaction_receipt_by_hash(
&self,
transaction_hash: TransactionHash,
) -> RpcResult<TransactionReceiptWithStatus> {
) -> RpcResult<TransactionReceipt> {
match self.api.starknet.read().await.get_transaction_receipt_by_hash(transaction_hash) {
Ok(receipt) => Ok(receipt),
Err(Error::NoTransaction) => Err(ApiError::TransactionNotFound),
Expand Down Expand Up @@ -266,18 +267,25 @@ impl JsonRpcHandler {
&self,
block_id: BlockId,
request: Vec<BroadcastedTransaction>,
) -> RpcResult<Vec<EstimateFeeOutput>> {
// TODO: move EstimateFeeOutput to types
) -> RpcResult<Vec<FeeEstimateWrapper>> {
let starknet = self.api.starknet.read().await;
match starknet.estimate_gas_usage(block_id.into(), &request) {
Ok(result) => Ok(result
.iter()
.map(|gas_consumed| EstimateFeeOutput {
gas_consumed: format!("0x{gas_consumed:x}"),
gas_price: format!("0x{:x}", starknet.config.gas_price),
overall_fee: format!("0x{:x}", starknet.config.gas_price * gas_consumed),
})
.collect()),
match starknet.estimate_fee(block_id.into(), &request) {
Ok(result) => Ok(result),
Err(Error::ContractNotFound) => Err(ApiError::ContractNotFound),
Err(Error::NoBlock) => Err(ApiError::BlockNotFound),
Err(err) => Err(ApiError::ContractError { msg: err.to_string() }),
FabijanC marked this conversation as resolved.
Show resolved Hide resolved
}
}

pub(crate) async fn estimate_message_fee(
&self,
block_id: BlockId,
message: MsgFromL1,
) -> RpcResult<FeeEstimateWrapper> {
match self.api.starknet.read().await.estimate_message_fee(block_id.into(), message) {
Ok(result) => Ok(result),
Err(Error::ContractNotFound) => Err(ApiError::ContractNotFound),
Err(Error::NoBlock) => Err(ApiError::BlockNotFound),
Err(err) => Err(ApiError::ContractError { msg: err.to_string() }),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-server/src/api/json_rpc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests {
fn transaction_not_found_error() {
error_expected_code_and_message(
ApiError::TransactionNotFound,
25,
29,
"Transaction hash not found",
);
}
Expand Down
12 changes: 10 additions & 2 deletions crates/starknet-server/src/api/json_rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
use server::rpc_core::error::RpcError;
use server::rpc_core::response::ResponseResult;
use server::rpc_handler::RpcHandler;
use starknet_types::rpc::estimate_message_fee::EstimateMessageFeeRequestWrapper;
use tracing::{error, info, trace};

use self::error::ApiError;
Expand Down Expand Up @@ -58,7 +59,7 @@ impl<T: Serialize> ToRpcResponseResult for RpcResult<T> {
data: None,
},
err @ ApiError::TransactionNotFound => RpcError {
code: server::rpc_core::error::ErrorCode::ServerError(25),
code: server::rpc_core::error::ErrorCode::ServerError(29),
message: err.to_string().into(),
data: None,
},
Expand Down Expand Up @@ -226,11 +227,15 @@ impl JsonRpcHandler {
StarknetRequest::AddInvokeTransaction(BroadcastedInvokeTransactionInput {
invoke_transaction,
}) => self.add_invoke_transaction(invoke_transaction).await.to_rpc_result(),
StarknetRequest::EstimateMessageFee(request) => self
.estimate_message_fee(request.get_block_id(), request.get_raw_message().clone())
.await
.to_rpc_result(),
}
}
}

#[derive(Clone, Debug, PartialEq, Deserialize, Eq)]
#[derive(Clone, Debug, Deserialize)]
#[serde(tag = "method", content = "params")]
pub enum StarknetRequest {
#[serde(rename = "starknet_getBlockWithTxHashes")]
Expand Down Expand Up @@ -279,6 +284,8 @@ pub enum StarknetRequest {
AddDeployAccountTransaction(BroadcastedDeployAccountTransactionInput),
#[serde(rename = "starknet_addInvokeTransaction")]
AddInvokeTransaction(BroadcastedInvokeTransactionInput),
#[serde(rename = "starknet_estimateMessageFee")]
EstimateMessageFee(EstimateMessageFeeRequestWrapper),
}

impl std::fmt::Display for StarknetRequest {
Expand Down Expand Up @@ -319,6 +326,7 @@ impl std::fmt::Display for StarknetRequest {
write!(f, "starknet_addDeployAccountTransaction")
}
StarknetRequest::AddInvokeTransaction(_) => write!(f, "starknet_addInvokeTransaction"),
StarknetRequest::EstimateMessageFee(_) => write!(f, "starknet_estimateMessageFee"),
}
}
}
Expand Down
Loading