Skip to content

Commit d6c6618

Browse files
kstepanovdevarmyhaylenko
authored andcommitted
Replace the identical methods with parse_json (#428)
1 parent d1b370c commit d6c6618

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

nft_ingester/src/bin/slot_persister/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use interface::{signature_persistence::BlockProducer, slot_getter::FinalizedSlot
88
use metrics_utils::{utils::start_metrics, MetricState, MetricsTrait};
99
use nft_ingester::{
1010
backfiller::BackfillSource,
11-
config::{parse_json_to_big_table_config, BigTableConfig},
11+
config::{parse_json, BigTableConfig},
1212
inmemory_slots_dumper::InMemorySlotsDumper,
1313
};
1414
use rocks_db::{column::TypedColumn, SlotStorage};
@@ -47,7 +47,7 @@ struct Args {
4747
start_slot: Option<u64>,
4848

4949
/// Big table config (best passed from env)
50-
#[arg(short, long, env, value_parser = parse_json_to_big_table_config)]
50+
#[arg(short, long, env, value_parser = parse_json::<Result<BigTableConfig, String>>)]
5151
big_table_config: Option<BigTableConfig>,
5252

5353
/// Metrics port

nft_ingester/src/config.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct IngesterClapArgs {
4646
#[clap(long, env = "INGESTER_PG_MAX_QUERY_TIMEOUT_SECS", default_value = "120")]
4747
pub pg_max_query_statement_timeout_secs: u32,
4848

49-
#[clap(short('r'), long, env, help="example: {redis_connection_str=\"redis://127.0.0.1:6379/0\"}", value_parser = parse_json_to_dict)]
49+
#[clap(short('r'), long, env, help="example: {redis_connection_str=\"redis://127.0.0.1:6379/0\"}", value_parser = parse_json::<Result<Dict, String>>)]
5050
pub redis_connection_config: Dict,
5151

5252
#[clap(long, env, default_value = "5")]
@@ -106,7 +106,7 @@ pub struct IngesterClapArgs {
106106
)]
107107
pub run_profiling: bool,
108108

109-
#[clap(long, env, value_parser = parse_json_to_json_middleware_config, help = "Example: {'is_enabled':true, 'max_urls_to_parse':10} ",)]
109+
#[clap(long, env, value_parser = parse_json::<Result<JsonMiddlewareConfig, String>>, help = "Example: {'is_enabled':true, 'max_urls_to_parse':10} ",)]
110110
pub json_middleware_config: Option<JsonMiddlewareConfig>,
111111

112112
// Group: Rocks DB Configuration
@@ -221,7 +221,7 @@ pub struct IngesterClapArgs {
221221
pub backfill_rpc_address: Option<String>,
222222
#[clap(long, env, default_value = "rpc", help = "#backfiller Backfill source mode.")]
223223
pub backfiller_source_mode: BackfillerSourceMode,
224-
#[clap(long, env, value_parser = parse_json_to_big_table_config, help ="#backfiller Big table config")]
224+
#[clap(long, env, value_parser = parse_json::<Result<BigTableConfig, String>>, help ="#backfiller Big table config")]
225225
pub big_table_config: Option<BigTableConfig>,
226226

227227
#[clap(
@@ -510,7 +510,7 @@ pub struct ApiClapArgs {
510510
#[clap(long, env, help = "#api Storage service base url")]
511511
pub storage_service_base_url: Option<String>,
512512

513-
#[clap(long, env, value_parser = parse_json_to_json_middleware_config, help = "Example: {'is_enabled':true, 'max_urls_to_parse':10} ",)]
513+
#[clap(long, env, value_parser = parse_json::<Result<JsonMiddlewareConfig, String>>, help = "Example: {'is_enabled':true, 'max_urls_to_parse':10} ",)]
514514
pub json_middleware_config: Option<JsonMiddlewareConfig>,
515515
#[clap(long, env, default_value = "100")]
516516
pub parallel_json_downloaders: i32,
@@ -525,19 +525,7 @@ pub struct ApiClapArgs {
525525
pub log_level: String,
526526
}
527527

528-
fn parse_json_to_dict(s: &str) -> Result<Dict, String> {
529-
parse_json(s)
530-
}
531-
532-
fn parse_json_to_json_middleware_config(s: &str) -> Result<JsonMiddlewareConfig, String> {
533-
parse_json(s)
534-
}
535-
536-
pub fn parse_json_to_big_table_config(s: &str) -> Result<BigTableConfig, String> {
537-
parse_json(s)
538-
}
539-
540-
fn parse_json<T: serde::de::DeserializeOwned>(s: &str) -> Result<T, String> {
528+
pub fn parse_json<T: serde::de::DeserializeOwned>(s: &str) -> Result<T, String> {
541529
serde_json::from_str(s).map_err(|e| format!("Failed to parse JSON: {}", e))
542530
}
543531

0 commit comments

Comments
 (0)