Loading transactions from DB works.

This commit is contained in:
Kevin Gorham 2021-04-13 08:12:16 -04:00
parent 08d2a8ab7b
commit 3dac89ef26
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
3 changed files with 68 additions and 0 deletions

3
.gitignore vendored
View File

@ -8,3 +8,6 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# VSCode
.history

20
Cargo.toml Normal file
View File

@ -0,0 +1,20 @@
[package]
name = "zcash-devtools"
version = "0.1.0"
authors = ["Kevin Gorham <kevin.gorham@electriccoin.co>"]
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
src/main.rs Normal file
View File

@ -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);
}