-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Gorham
committed
Apr 13, 2021
1 parent
08d2a8a
commit 3dac89e
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ Cargo.lock | |
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# VSCode | ||
.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "zcash-devtools" | ||
version = "0.1.0" | ||
authors = ["Kevin Gorham <[email protected]>"] | ||
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' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<P: Parameters>(db_path: &str, params: P) -> Result<WalletDB<P>, 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<MainNetwork>, id_tx: i64) -> Result<Transaction, failure::Error> { | ||
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); | ||
} |