tx: &Transaction,
height: Option<u32>,
timestamp: u64,
- internal_max_deriv: &mut u32,
- external_max_deriv: &mut u32,
+ internal_max_deriv: &mut Option<u32>,
+ external_max_deriv: &mut Option<u32>,
) -> Result<(), Error> {
let mut updates = database.begin_batch();
})?;
incoming += output.value;
- if script_type == ScriptType::Internal && child > *internal_max_deriv {
- *internal_max_deriv = child;
- } else if script_type == ScriptType::External && child > *external_max_deriv {
- *external_max_deriv = child;
+ if script_type == ScriptType::Internal
+ && (internal_max_deriv.is_none() || child > internal_max_deriv.unwrap_or(0))
+ {
+ *internal_max_deriv = Some(child);
+ } else if script_type == ScriptType::External
+ && (external_max_deriv.is_none() || child > external_max_deriv.unwrap_or(0))
+ {
+ *external_max_deriv = Some(child);
}
}
}
first_peer.ask_for_mempool()?;
- let mut internal_max_deriv = 0;
- let mut external_max_deriv = 0;
+ let mut internal_max_deriv = None;
+ let mut external_max_deriv = None;
for (height, block) in inner.headers.iter_full_blocks()? {
for tx in &block.txdata {
}
let current_ext = database.get_last_index(ScriptType::External)?.unwrap_or(0);
- let first_ext_new = external_max_deriv as u32 + 1;
+ let first_ext_new = external_max_deriv.map(|x| x + 1).unwrap_or(0);
if first_ext_new > current_ext {
info!("Setting external index to {}", first_ext_new);
database.set_last_index(ScriptType::External, first_ext_new)?;
}
let current_int = database.get_last_index(ScriptType::Internal)?.unwrap_or(0);
- let first_int_new = internal_max_deriv + 1;
+ let first_int_new = internal_max_deriv.map(|x| x + 1).unwrap_or(0);
if first_int_new > current_int {
info!("Setting internal index to {}", first_int_new);
database.set_last_index(ScriptType::Internal, first_int_new)?;
database.commit_batch(del_batch)?;
// maximum derivation index for a change address that we've seen during sync
- let mut change_max_deriv = 0;
+ let mut change_max_deriv = None;
let mut already_checked: HashSet<Script> = HashSet::new();
let mut to_check_later = VecDeque::with_capacity(batch_query_size);
let mut iterating_external = true;
let mut index = 0;
- let mut last_found = 0;
+ let mut last_found = None;
while !to_check_later.is_empty() {
trace!("to_check_later size {}", to_check_later.len());
trace!("received history for {:?}, size {}", script, history.len());
if !history.is_empty() {
- last_found = index;
+ last_found = Some(index);
let mut check_later_scripts = maybe_await!(self.check_history(
database,
}
match iterating_external {
- true if index - last_found >= stop_gap => iterating_external = false,
+ true if index - last_found.unwrap_or(0) >= stop_gap => iterating_external = false,
true => {
- trace!("pushing one more batch from `iter_scriptpubkeys`. index = {}, last_found = {}, stop_gap = {}", index, last_found, stop_gap);
+ trace!("pushing one more batch from `iter_scriptpubkeys`. index = {}, last_found = {:?}, stop_gap = {}", index, last_found, stop_gap);
let chunk: Vec<Script> =
iter_scriptpubkeys.by_ref().take(batch_query_size).collect();
}
let current_ext = database.get_last_index(ScriptType::External)?.unwrap_or(0);
- let first_ext_new = last_found as u32 + 1;
+ let first_ext_new = last_found.map(|x| x + 1).unwrap_or(0) as u32;
if first_ext_new > current_ext {
info!("Setting external index to {}", first_ext_new);
database.set_last_index(ScriptType::External, first_ext_new)?;
}
let current_int = database.get_last_index(ScriptType::Internal)?.unwrap_or(0);
- let first_int_new = change_max_deriv + 1;
+ let first_int_new = change_max_deriv.map(|x| x + 1).unwrap_or(0);
if first_int_new > current_int {
info!("Setting internal index to {}", first_int_new);
database.set_last_index(ScriptType::Internal, first_int_new)?;
txid: &Txid,
height: Option<u32>,
cur_script: &Script,
- change_max_deriv: &mut u32,
+ change_max_deriv: &mut Option<u32>,
) -> Result<Vec<Script>, Error> {
debug!(
"check_tx_and_descendant of {}, height: {:?}, script: {}",
}
// derive as many change addrs as external addresses that we've seen
- if script_type == ScriptType::Internal && child > *change_max_deriv {
- *change_max_deriv = child;
+ if script_type == ScriptType::Internal
+ && (change_max_deriv.is_none() || child > change_max_deriv.unwrap_or(0))
+ {
+ *change_max_deriv = Some(child);
}
}
}
database: &mut D,
script_pubkey: Script,
txs: Vec<ELSGetHistoryRes>,
- change_max_deriv: &mut u32,
+ change_max_deriv: &mut Option<u32>,
) -> Result<Vec<Script>, Error> {
let mut to_check_later = Vec::new();