diff --git a/.gitignore b/.gitignore index 088ba6b..756e7da 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + +# VSCode +.history \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3d13fdc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "zcash-devtools" +version = "0.1.0" +authors = ["Kevin Gorham "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +failure = "0.1" +tiny-bip39 = "0.8.0" +zcash_primitives = "0.5" +zcash_client_sqlite = "0.3" +zcash_client_backend = "0.5" + + +[patch.crates-io] +zcash_primitives = { path = '../../clones/librustzcash/zcash_primitives' } +zcash_client_sqlite = { path = '../../clones/librustzcash/zcash_client_sqlite' } +zcash_client_backend = { path = '../../clones/librustzcash/zcash_client_backend' } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..b03c273 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,45 @@ + +use bip39::{Mnemonic, Language, Seed}; +use failure::format_err; +use std::path::Path; + +use zcash_primitives::{consensus::{MainNetwork, Parameters}, transaction::Transaction}; +use zcash_client_backend::data_api::WalletRead; +use zcash_client_sqlite::WalletDB; + +fn main() { + // TODO: get this path from CLI args + let db_path = "/home/gmale/kg/work/clones/librustzcash/ZcashSdk_mainnet_Data.db"; + let db_data = wallet_db(db_path, MainNetwork).unwrap(); + + let phrase = "chat error pigeon main parade window scene breeze scene frog inherit enforce wise resist rotate van pistol coral tide faint arm elegant velvet anxiety"; + + show_seed(phrase); + let tx = load_tx(&db_data, 3); + println!("loaded tx: {:?}", &tx.unwrap()); +} + +fn wallet_db(db_path: &str, params: P) -> Result, failure::Error> { + if !Path::new(db_path).exists() { + Err(format_err!("Path {} did not exist", db_path)) + } else { + WalletDB::for_path(db_path, params) + .map_err(|e| format_err!("Error opening wallet database connection: {}", e)) + } +} + +fn load_tx(db_data: &WalletDB, id_tx: i64) -> Result { + return (&db_data).get_transaction(id_tx).map_err(|_| format_err!("Invalid amount, out of range")); +} + + + + + +// seed things + +fn show_seed(phrase: &str) { + let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap(); + let seed = Seed::new(&mnemonic, ""); + println!("{:X}", seed); +} \ No newline at end of file