-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(katana): move the rpc address log (#2518)
* move rpc address log out of the startup log * include ci binaries at PATH
- Loading branch information
Showing
7 changed files
with
139 additions
and
72 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,71 @@ | ||
#![allow(dead_code)] | ||
|
||
//! Utilities for parsing the logs in JSON format. This is when katana is run with `--json-log`. | ||
//! | ||
//! When JSON log is enabled, the startup details are all printed in a single log message. | ||
//! Example startup log in JSON format: | ||
//! | ||
//! ```json | ||
//! {"timestamp":"2024-07-06T03:35:00.410846Z","level":"INFO","fields":{"message":"{\"accounts\":[[\ | ||
//! "318027405971194400117186968443431282813445578359155272415686954645506762954\",{\"balance\":\" | ||
//! 0x21e19e0c9bab2400000\",\"class_hash\":\" | ||
//! 0x5400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c\",\"private_key\":\" | ||
//! 0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a\",\"public_key\":\" | ||
//! 0x640466ebd2ce505209d3e5c4494b4276ed8f1cde764d757eb48831961f7cdea\"}]],\"address\":\"0.0.0.0: | ||
//! 5050\",\"seed\":\"0\"}"},"target":"katana::cli"} | ||
//! ``` | ||
#![allow(dead_code)] | ||
use std::net::SocketAddr; | ||
|
||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct JsonLogMessage { | ||
#[derive(Deserialize, Debug)] | ||
pub struct JsonLog<T = serde_json::Value> { | ||
pub timestamp: String, | ||
pub level: String, | ||
pub fields: JsonLogFields, | ||
pub fields: Fields<T>, | ||
pub target: String, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct JsonLogFields { | ||
#[serde(deserialize_with = "deserialize_katana_info")] | ||
pub message: KatanaInfo, | ||
} | ||
|
||
fn deserialize_katana_info<'de, D>(deserializer: D) -> Result<KatanaInfo, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let s = String::deserialize(deserializer)?; | ||
serde_json::from_str(&s).map_err(serde::de::Error::custom) | ||
#[derive(Deserialize, Debug)] | ||
pub struct Fields<T = serde_json::Value> { | ||
pub message: String, | ||
#[serde(flatten)] | ||
pub other: T, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
/// Katana startup log message. The object is included as a string in the `message` field. Hence we | ||
/// have to parse it separately unlike the [`RpcAddr`] where we can directly deserialize using the | ||
/// Fields generic parameter. | ||
/// | ||
/// Example: | ||
/// | ||
/// ```json | ||
/// { | ||
/// "timestamp": "2024-10-10T14:55:04.452924Z", | ||
/// "level": "INFO", | ||
/// "fields": { | ||
/// "message": "{\"accounts\":[[\"0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03\",{\"balance\":\"0x21e19e0c9bab2400000\",\"class_hash\":\"0x5400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c\",\"private_key\":\"0x1800000000300000180000000000030000000000003006001800006600\",\"public_key\":\"0x2b191c2f3ecf685a91af7cf72a43e7b90e2e41220175de5c4f7498981b10053\"}]],\"seed\":\"0\"}" | ||
/// }, | ||
/// "target": "katana::cli" | ||
/// } | ||
/// ``` | ||
#[derive(Deserialize, Debug)] | ||
pub struct KatanaInfo { | ||
pub seed: String, | ||
pub address: String, | ||
pub accounts: Vec<(String, AccountInfo)>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
impl TryFrom<String> for KatanaInfo { | ||
type Error = serde_json::Error; | ||
|
||
fn try_from(value: String) -> Result<Self, Self::Error> { | ||
serde_json::from_str(&value) | ||
} | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub struct AccountInfo { | ||
pub balance: String, | ||
pub class_hash: String, | ||
pub private_key: String, | ||
pub public_key: String, | ||
} | ||
|
||
/// { | ||
/// "message": "RPC server started.", | ||
/// "addr": "127.0.0.1:5050" | ||
/// } | ||
#[derive(Deserialize, Debug)] | ||
pub struct RpcAddr { | ||
pub addr: SocketAddr, | ||
} |
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