Skip to content

Commit

Permalink
Added config RPC endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ElFantasma committed Feb 15, 2024
1 parent b5b5ee6 commit 702a587
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions node/tools/src/rpc/methods/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Peers method for RPC server.
use crate::{config::encode_json, decode_json, AppConfig};

use super::RPCMethod;
use jsonrpsee::types::{error::ErrorCode, Params};
use std::fs::{self};
use zksync_protobuf::serde::Serde;

/// Config method for RPC server.
pub(crate) struct ConfigInfo;

// RPCMethod trait should be more general to allow external parameters like this case
// TODO fix the trait and implement this code in it
impl ConfigInfo {
pub(crate) fn info(config: AppConfig) -> Result<serde_json::Value, ErrorCode> {
// This may change in the future since we are assuming that the executor binary is being run inside the config directory.
Ok(serde_json::json!({
"config": encode_json(&Serde(config))
}))
}
}

impl RPCMethod for ConfigInfo {
/// Config response for /config endpoint.
fn callback(_params: Params) -> Result<serde_json::Value, ErrorCode> {
// This may change in the future since we are assuming that the executor binary is being run inside the config directory.
let node_config =
fs::read_to_string("config.json").map_err(|_e| ErrorCode::InternalError)?;
let node_config = decode_json::<Serde<AppConfig>>(&node_config)
.map_err(|_e| ErrorCode::InternalError)?
.0;
let config = encode_json(&Serde(node_config));
Ok(serde_json::json!({
"config": config
}))
}

/// Config method name.
fn method() -> &'static str {
"config"
}

/// Method path for GET requests.
fn path() -> &'static str {
"/config"
}
}

0 comments on commit 702a587

Please sign in to comment.