Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/bin/neptune-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use itertools::Itertools;
use neptune_cash::api::tx_initiation::builder::tx_output_list_builder::OutputFormat;
use neptune_cash::config_models::data_directory::DataDirectory;
use neptune_cash::config_models::network::Network;
use neptune_cash::database::storage::storage_schema::RustyKey;
use neptune_cash::database::NeptuneLevelDb;
use neptune_cash::models::blockchain::block::block_selector::BlockSelector;
use neptune_cash::models::blockchain::type_scripts::native_currency_amount::NativeCurrencyAmount;
use neptune_cash::models::state::wallet::address::KeyType;
Expand All @@ -37,6 +39,8 @@ use neptune_cash::models::state::wallet::wallet_status::WalletStatusExportFormat
use neptune_cash::rpc_auth;
use neptune_cash::rpc_server::error::RpcError;
use neptune_cash::rpc_server::RPCClient;

use neptune_cash::database::storage::storage_schema::RustyValue;
use rand::Rng;
use regex::Regex;
use serde::Deserialize;
Expand Down Expand Up @@ -124,6 +128,27 @@ impl TransactionOutput {
}
}

#[derive(Debug, Clone, Parser, strum::EnumIs, clap::ValueEnum)]
enum LevelDbStore {
ArchivalBlockMmr,
BannedIps,
BlockIndex,
MutatorSet,
Wallet,
}

impl LevelDbStore {
pub fn dir(&self, data_dir: &DataDirectory) -> PathBuf {
match *self {
Self::ArchivalBlockMmr => data_dir.archival_block_mmr_dir_path(),
Self::BannedIps => data_dir.banned_ips_database_dir_path(),
Self::BlockIndex => data_dir.block_index_database_dir_path(),
Self::MutatorSet => data_dir.mutator_set_database_dir_path(),
Self::Wallet => data_dir.wallet_database_dir_path(),
}
}
}

#[derive(Debug, Clone, Parser)]
enum Command {
/// Dump shell completions.
Expand Down Expand Up @@ -159,6 +184,12 @@ enum Command {
/// retrieve info about peers
PeerInfo,

/// dump all key/val pairs in the indicated database
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// dump all key/val pairs in the indicated database
/// Dump all key/val pairs in the indicated database.
///
/// Note that the resulting data dump contains private information that would
/// enable the reader to deanonymize transactions. Only share this information
/// if the privacy risk is acceptable. This dump does not contain information
/// that would enable the reader to spend UTXOs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the wallet DB, this is correct. I think the other DBs don't leak anything money-related when dumped.

DumpDb {
network: Network,
db_store: LevelDbStore,
},

/// retrieve list of punished peers
AllPunishedPeers,

Expand Down Expand Up @@ -723,6 +754,22 @@ async fn main() -> Result<()> {

return Ok(());
}

Command::DumpDb { network, db_store } => {
let data_dir = DataDirectory::get(args.data_dir.clone(), *network)?;
let dir_path = db_store.dir(&data_dir);

match NeptuneLevelDb::<RustyKey, RustyValue>::new(
&dir_path,
&leveldb::options::Options::new(),
)
.await
{
Ok(db) => db.dump_database().await,
Err(e) => eprintln!("Unable to open database. {}", e),
}
return Ok(());
}
_ => {}
}

Expand Down Expand Up @@ -768,6 +815,7 @@ async fn main() -> Result<()> {
| Command::ShamirCombine { .. }
| Command::ShamirShare { .. }
| Command::NthReceivingAddress { .. }
| Command::DumpDb { .. }
| Command::PremineReceivingAddress { .. } => {
unreachable!("Case should be handled earlier.")
}
Expand Down
Loading