Remove seed argument from JniConverter.scanBlocks()
The API now scans cached CompactBlocks using the ExtendedFullViewingKeys for the internally-tracked accounts.
This commit is contained in:
parent
d9232c885d
commit
b608b026ed
|
@ -19,7 +19,7 @@ class JniConverter {
|
||||||
|
|
||||||
external fun getBalance(dbData: String, account: Int): Long
|
external fun getBalance(dbData: String, account: Int): Long
|
||||||
|
|
||||||
external fun scanBlocks(db_cache: String, db_data: String, seed: ByteArray): Boolean
|
external fun scanBlocks(db_cache: String, db_data: String): Boolean
|
||||||
|
|
||||||
external fun sendToAddress(
|
external fun sendToAddress(
|
||||||
dbData: String,
|
dbData: String,
|
||||||
|
|
|
@ -23,7 +23,9 @@ use sapling_crypto::{
|
||||||
};
|
};
|
||||||
use zcash_client_backend::{
|
use zcash_client_backend::{
|
||||||
constants::{HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY_TEST, HRP_SAPLING_PAYMENT_ADDRESS_TEST},
|
constants::{HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY_TEST, HRP_SAPLING_PAYMENT_ADDRESS_TEST},
|
||||||
encoding::{encode_extended_full_viewing_key, encode_payment_address},
|
encoding::{
|
||||||
|
decode_extended_full_viewing_key, encode_extended_full_viewing_key, encode_payment_address,
|
||||||
|
},
|
||||||
note_encryption::Memo,
|
note_encryption::Memo,
|
||||||
proto::compact_formats::CompactBlock,
|
proto::compact_formats::CompactBlock,
|
||||||
prover::TxProver,
|
prover::TxProver,
|
||||||
|
@ -213,15 +215,11 @@ fn get_balance(db_data: &str, account: u32) -> Result<Amount, Error> {
|
||||||
Ok(Amount(balance))
|
Ok(Amount(balance))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scans new blocks added to the cache for any transactions received by the given
|
/// Scans new blocks added to the cache for any transactions received by the
|
||||||
/// ExtendedFullViewingKeys.
|
/// tracked accounts.
|
||||||
///
|
///
|
||||||
/// Assumes that the caller is handling rollbacks.
|
/// Assumes that the caller is handling rollbacks.
|
||||||
fn scan_cached_blocks(
|
fn scan_cached_blocks(db_cache: &str, db_data: &str) -> Result<(), Error> {
|
||||||
db_cache: &str,
|
|
||||||
db_data: &str,
|
|
||||||
extfvks: &[ExtendedFullViewingKey],
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let cache = Connection::open(db_cache)?;
|
let cache = Connection::open(db_cache)?;
|
||||||
let data = Connection::open(db_data)?;
|
let data = Connection::open(db_data)?;
|
||||||
|
|
||||||
|
@ -276,6 +274,16 @@ fn scan_cached_blocks(
|
||||||
data: row.get(1),
|
data: row.get(1),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
// Fetch the ExtendedFullViewingKeys we are tracking
|
||||||
|
let mut stmt_fetch_accounts =
|
||||||
|
data.prepare("SELECT extfvk FROM accounts ORDER BY account ASC")?;
|
||||||
|
let extfvks = stmt_fetch_accounts.query_map(NO_PARAMS, |row| {
|
||||||
|
let extfvk: String = row.get(0);
|
||||||
|
decode_extended_full_viewing_key(HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY_TEST, &extfvk)
|
||||||
|
})?;
|
||||||
|
// Raise SQL errors from the query, and IO errors from parsing.
|
||||||
|
let extfvks: Vec<_> = extfvks.collect::<Result<Result<_, _>, _>>()??;
|
||||||
|
|
||||||
// Get the most recent CommitmentTree
|
// Get the most recent CommitmentTree
|
||||||
let mut tree = match stmt_fetch_tree.query_row(&[last_height], |row| match row.get_checked(0) {
|
let mut tree = match stmt_fetch_tree.query_row(&[last_height], |row| match row.get_checked(0) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
|
@ -331,7 +339,13 @@ fn scan_cached_blocks(
|
||||||
let txs = {
|
let txs = {
|
||||||
let nf_refs: Vec<_> = nullifiers.iter().map(|(nf, acc)| (&nf[..], *acc)).collect();
|
let nf_refs: Vec<_> = nullifiers.iter().map(|(nf, acc)| (&nf[..], *acc)).collect();
|
||||||
let mut witness_refs: Vec<_> = witnesses.iter_mut().map(|w| &mut w.witness).collect();
|
let mut witness_refs: Vec<_> = witnesses.iter_mut().map(|w| &mut w.witness).collect();
|
||||||
scan_block(block, &extfvks, &nf_refs, &mut tree, &mut witness_refs[..])
|
scan_block(
|
||||||
|
block,
|
||||||
|
&extfvks[..],
|
||||||
|
&nf_refs,
|
||||||
|
&mut tree,
|
||||||
|
&mut witness_refs[..],
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Insert the block into the database.
|
// Insert the block into the database.
|
||||||
|
@ -833,7 +847,6 @@ pub mod android {
|
||||||
_: JClass,
|
_: JClass,
|
||||||
db_cache: JString,
|
db_cache: JString,
|
||||||
db_data: JString,
|
db_data: JString,
|
||||||
seed: jbyteArray,
|
|
||||||
) -> jboolean {
|
) -> jboolean {
|
||||||
let db_cache: String = env
|
let db_cache: String = env
|
||||||
.get_string(db_cache)
|
.get_string(db_cache)
|
||||||
|
@ -843,9 +856,8 @@ pub mod android {
|
||||||
.get_string(db_data)
|
.get_string(db_data)
|
||||||
.expect("Couldn't get Java string!")
|
.expect("Couldn't get Java string!")
|
||||||
.into();
|
.into();
|
||||||
let seed = env.convert_byte_array(seed).unwrap();
|
|
||||||
|
|
||||||
match scan_cached_blocks(&db_cache, &db_data, &[extfvk_from_seed(&seed)]) {
|
match scan_cached_blocks(&db_cache, &db_data) {
|
||||||
Ok(()) => JNI_TRUE,
|
Ok(()) => JNI_TRUE,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Error while scanning blocks: {}", e);
|
error!("Error while scanning blocks: {}", e);
|
||||||
|
|
Loading…
Reference in New Issue