Skip to content

Commit

Permalink
Loading transactions from DB works.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Gorham committed Apr 13, 2021
1 parent 08d2a8a commit 3dac89e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# VSCode
.history
20 changes: 20 additions & 0 deletions Cargo.toml
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' }
45 changes: 45 additions & 0 deletions src/main.rs
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);
}

0 comments on commit 3dac89e

Please sign in to comment.