feat: A basic json dump extension to reth db list. (#2232)

Co-authored-by: andy-thomason <andy@atomicinrement.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Andy Thomson
2023-05-04 14:55:08 +01:00
committed by GitHub
parent 231d1f96bb
commit 7914d1cf76
3 changed files with 17 additions and 5 deletions

View File

@@ -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::<tables::$table>(start, count).unwrap()
}, $start, $len, total_entries).run()
if args.json {
let list_result = tool.list::<tables::$table>(args.start, args.len)?.into_iter().collect::<Vec<_>>();
println!("{}", serde_json::to_string_pretty(&list_result)?);
Ok(())
} else {
tui::DbListTUI::<_, tables::$table>::new(|start, count| {
tool.list::<tables::$table>(start, count).unwrap()
}, $start, $len, total_entries).run()
}
})??
},)*
_ => {

View File

@@ -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<T> {
/// The key for this type.
pub key: T,

View File

@@ -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,