diff --git a/bin/reth/src/db/mod.rs b/bin/reth/src/db/mod.rs index b6de7c7785..61cec948e8 100644 --- a/bin/reth/src/db/mod.rs +++ b/bin/reth/src/db/mod.rs @@ -85,6 +85,9 @@ pub struct ListArgs { /// How many items to take from the walker #[arg(long, short, default_value = DEFAULT_NUM_ITEMS)] len: usize, + /// Dump as JSON instead of using TUI. + #[arg(long, short)] + json: bool, } impl Command { @@ -177,9 +180,15 @@ impl Command { return Ok(()); } - tui::DbListTUI::<_, tables::$table>::new(|start, count| { - tool.list::(start, count).unwrap() - }, $start, $len, total_entries).run() + if args.json { + let list_result = tool.list::(args.start, args.len)?.into_iter().collect::>(); + println!("{}", serde_json::to_string_pretty(&list_result)?); + Ok(()) + } else { + tui::DbListTUI::<_, tables::$table>::new(|start, count| { + tool.list::(start, count).unwrap() + }, $start, $len, total_entries).run() + } })?? },)* _ => { diff --git a/crates/storage/db/src/tables/models/sharded_key.rs b/crates/storage/db/src/tables/models/sharded_key.rs index 5ea1c3aa8a..61a2a18565 100644 --- a/crates/storage/db/src/tables/models/sharded_key.rs +++ b/crates/storage/db/src/tables/models/sharded_key.rs @@ -5,6 +5,7 @@ use crate::{ Error, }; use reth_primitives::BlockNumber; +use serde::Serialize; /// Number of indices in one shard. pub const NUM_OF_INDICES_IN_SHARD: usize = 100; @@ -15,7 +16,7 @@ pub const NUM_OF_INDICES_IN_SHARD: usize = 100; /// `Address | 200` -> data is from block 0 to 200. /// /// `Address | 300` -> data is from block 201 to 300. -#[derive(Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize)] pub struct ShardedKey { /// The key for this type. pub key: T, diff --git a/crates/storage/db/src/tables/models/storage_sharded_key.rs b/crates/storage/db/src/tables/models/storage_sharded_key.rs index a27c90f969..0070c2212d 100644 --- a/crates/storage/db/src/tables/models/storage_sharded_key.rs +++ b/crates/storage/db/src/tables/models/storage_sharded_key.rs @@ -4,7 +4,9 @@ use crate::{ table::{Decode, Encode}, Error, }; + use reth_primitives::{BlockNumber, H160, H256}; +use serde::Serialize; use super::ShardedKey; @@ -17,7 +19,7 @@ pub const NUM_OF_INDICES_IN_SHARD: usize = 100; /// `Address | Storagekey | 200` -> data is from transition 0 to 200. /// /// `Address | StorageKey | 300` -> data is from transition 201 to 300. -#[derive(Debug, Default, Clone, Eq, Ord, PartialOrd, PartialEq)] +#[derive(Debug, Default, Clone, Eq, Ord, PartialOrd, PartialEq, Serialize)] pub struct StorageShardedKey { /// Storage account address. pub address: H160,