-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move rpc state reader to state reader crate
commit-id:c590a350
- Loading branch information
1 parent
c806208
commit 760c94c
Showing
17 changed files
with
126 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use papyrus_config::dumping::{ser_param, SerializeConfig}; | ||
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; | ||
use serde::{Deserialize, Serialize}; | ||
use validator::Validate; | ||
|
||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)] | ||
pub struct RpcStateReaderConfig { | ||
pub url: String, | ||
pub json_rpc_version: String, | ||
} | ||
|
||
#[cfg(any(feature = "testing", test))] | ||
impl RpcStateReaderConfig { | ||
pub fn create_for_testing() -> Self { | ||
Self { url: "http://localhost:8080".to_string(), json_rpc_version: "2.0".to_string() } | ||
} | ||
} | ||
|
||
impl SerializeConfig for RpcStateReaderConfig { | ||
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> { | ||
BTreeMap::from_iter([ | ||
ser_param("url", &self.url, "The url of the rpc server.", ParamPrivacyInput::Public), | ||
ser_param( | ||
"json_rpc_version", | ||
&self.json_rpc_version, | ||
"The json rpc version.", | ||
ParamPrivacyInput::Public, | ||
), | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use axum::http::StatusCode; | ||
use blockifier::state::errors::StateError; | ||
use serde_json::{Error as SerdeError, Value}; | ||
use starknet_api::block::GasPrice; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum RPCStateReaderError { | ||
#[error("Block not found for request {0}")] | ||
BlockNotFound(Value), | ||
#[error("Class hash not found for request {0}")] | ||
ClassHashNotFound(Value), | ||
#[error("Failed to parse gas price {:?}", 0)] | ||
GasPriceParsingFailure(GasPrice), | ||
#[error("Contract address not found for request {0}")] | ||
ContractAddressNotFound(Value), | ||
#[error(transparent)] | ||
ReqwestError(#[from] reqwest::Error), | ||
#[error("RPC error: {0}")] | ||
RPCError(StatusCode), | ||
#[error("Unexpected error code: {0}")] | ||
UnexpectedErrorCode(u16), | ||
} | ||
|
||
pub type RPCStateReaderResult<T> = Result<T, RPCStateReaderError>; | ||
|
||
impl From<RPCStateReaderError> for StateError { | ||
fn from(err: RPCStateReaderError) -> Self { | ||
match err { | ||
RPCStateReaderError::ClassHashNotFound(request) => { | ||
match serde_json::from_value(request["params"]["class_hash"].clone()) { | ||
Ok(class_hash) => StateError::UndeclaredClassHash(class_hash), | ||
Err(e) => serde_err_to_state_err(e), | ||
} | ||
} | ||
_ => StateError::StateReadError(err.to_string()), | ||
} | ||
} | ||
} | ||
|
||
// Converts a serde error to the error type of the state reader. | ||
pub fn serde_err_to_state_err(err: SerdeError) -> StateError { | ||
StateError::StateReadError(format!("Failed to parse rpc result {:?}", err.to_string())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters