Skip to content
Draft
Show file tree
Hide file tree
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
19 changes: 15 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ name = "zmigrate"
path = "src/main.rs"

[dependencies]
zewif = { path = "../zewif" }
zewif-zcashd = { path = "../zewif-zcashd" }
zewif-zingo = { path = "../zewif-zingo" }
zewif = "0.1.0"
zewif-zcashd = { version = "0.1.0", optional = true }
zewif-zingo = { version = "0.1.0", optional = true }

anyhow = "1.0.95"
hex = "0.4.3"
Expand All @@ -25,5 +25,16 @@ anstyle = "^1.0.1"
regex = "1.10.2"

[features]
default = []
default = ["zcashd"]
zcashd = ["dep:zewif-zcashd"]
zingo = ["dep:zewif-zingo"]
with-context = []

[patch.crates-io]
zewif = { path = "../zewif/" }
zewif-zcashd = { path = "../zewif-zcashd/" }
zewif-zingo = { path = "../zewif-zingo/" }

#zewif = { git = "https://github.com/nuttycom/zewif", rev = "61c988fbfb6c3e74c5b98ba3da1cbc521b3967bd" }
#zewif-zcashd = { git = "https://github.com/nuttycom/zewif-zcashd", rev = "dc7825b03e413596fcf301d9918df24dc012c22c", optional = true }
#zewif-zingo = { git = "https://github.com/nuttycom/zewif-zingo", rev = "9e647c9e5bfc9b795fdd6421d02a522f86093420", optional = true }
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod zcashd_cmd;
pub mod zingo_cmd;
pub mod exec;
pub mod file_args;
pub mod zcashd_cmd;
#[cfg(feature = "zingo")]
pub mod zingo_cmd;
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

mod styles;

use clap::{Parser as ClapParser, Subcommand};
use zmigrate::{exec::Exec, zcashd_cmd, zingo_cmd};
use zmigrate::exec::Exec;
#[cfg(feature = "zcashd")]
use zmigrate::zcashd_cmd;
#[cfg(feature = "zingo")]
use zmigrate::zingo_cmd;

/// A tool for migrating Zcash wallets
#[derive(Debug, clap::Parser)]
Expand All @@ -18,7 +21,9 @@ struct Cli {
#[derive(Debug, Subcommand)]
#[doc(hidden)]
enum MainCommands {
#[cfg(feature = "zcashd")]
Zcashd(zcashd_cmd::CommandArgs),
#[cfg(feature = "zingo")]
Zingo(zingo_cmd::CommandArgs),
}

Expand All @@ -40,7 +45,9 @@ fn inner_main() -> anyhow::Result<()> {
let cli = Cli::parse();

let output = match cli.command {
#[cfg(feature = "zcashd")]
MainCommands::Zcashd(args) => args.exec(),
#[cfg(feature = "zingo")]
MainCommands::Zingo(args) => args.exec(),
};
let output = output?;
Expand Down
35 changes: 25 additions & 10 deletions src/zcashd_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ use std::fmt::Write;

use crate::file_args::{FileArgs, FileArgsLike};

use zewif_zcashd::{BDBDump, ZcashdDump, ZcashdParser};
use zewif_zcashd::{BDBDump, ZcashdDump, ZcashdParser, migrate::migrate_to_zewif};

/// Process a zcashd wallet file
#[derive(Debug, Args)]
#[group(skip)]
pub struct CommandArgs {
#[command(flatten)]
file_args: FileArgs,

/// Flag indicating whether lenient parsing is allowed.
///
/// Defaults to `false`. If set to `true`, parse errors will be reported to `stderr` but will
/// not halt execution.
#[arg(long, default_value = "false")]
lenient: bool
}

impl FileArgsLike for CommandArgs {
Expand All @@ -24,17 +31,17 @@ impl FileArgsLike for CommandArgs {

impl crate::exec::Exec for CommandArgs {
fn exec(&self) -> Result<String> {
dump_wallet(self.file())
dump_wallet(self.file(), !self.lenient)
}
}

pub fn dump_wallet(file: &Path) -> Result<String> {
pub fn dump_wallet(file: &Path, strict: bool) -> Result<String> {
let db_dump = BDBDump::from_file(file).context("Parsing BerkeleyDB file")?;

let zcashd_dump = ZcashdDump::from_bdb_dump(&db_dump).context("Parsing Zcashd dump")?;
let zcashd_dump = ZcashdDump::from_bdb_dump(&db_dump, strict).context("Parsing Zcashd dump")?;

let (zcashd_wallet, unparsed_keys) =
ZcashdParser::parse_dump(&zcashd_dump).context("Parsing Zcashd dump")?;
ZcashdParser::parse_dump(&zcashd_dump, strict).context("Parsing Zcashd wallet")?;

let mut output = String::new();

Expand Down Expand Up @@ -63,8 +70,7 @@ pub fn dump_wallet(file: &Path) -> Result<String> {
return Ok(output);
}

let zewif_wallet = zewif_zcashd::migrate_to_zewif(&zcashd_wallet)
.context("Migrating to Zewif")?;
let zewif_wallet = migrate_to_zewif(&zcashd_wallet).context("Migrating to Zewif")?;
writeln!(output, "---")?;
writeln!(output, "Migrated wallet:\n{:#?}", zewif_wallet)?;

Expand All @@ -79,18 +85,27 @@ pub fn dump_wallet(file: &Path) -> Result<String> {
let zcashd_address_count = zcashd_wallet.address_names().len();

// Count addresses in zewif wallet - all accounts combined
let zewif_address_count = zewif_wallet.wallets()
let zewif_address_count = zewif_wallet
.wallets()
.values()
.flat_map(|w| w.accounts().values())
.flat_map(|a| a.addresses())
.count();

writeln!(report, "- Addresses: {}/{} preserved", zewif_address_count, zcashd_address_count)?;
writeln!(
report,
"- Addresses: {}/{} preserved",
zewif_address_count, zcashd_address_count
)?;

// Check transaction preservation
let zcashd_tx_count = zcashd_wallet.transactions().len();
let zewif_tx_count = zewif_wallet.transactions().len();
writeln!(report, "- Transactions: {}/{} preserved", zewif_tx_count, zcashd_tx_count)?;
writeln!(
report,
"- Transactions: {}/{} preserved",
zewif_tx_count, zcashd_tx_count
)?;

// Add the report to the output
writeln!(output, "{}", report)?;
Expand Down
Loading