use std::cmp; use std::collections::{HashSet, VecDeque}; use std::convert::TryFrom; use std::io::{Read, Write}; #[allow(unused_imports)] use log::{debug, error, info, trace}; use bitcoin::{Address, Network, OutPoint, Script, Transaction, Txid}; use electrum_client::types::*; use electrum_client::Client; use super::*; use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils}; use crate::error::Error; use crate::types::{ScriptType, TransactionDetails, UTXO}; use crate::wallet::utils::ChunksIterator; pub struct ElectrumBlockchain(Option>); impl std::convert::From> for ElectrumBlockchain { fn from(client: Client) -> Self { ElectrumBlockchain(Some(client)) } } impl Blockchain for ElectrumBlockchain { fn offline() -> Self { ElectrumBlockchain(None) } } impl OnlineBlockchain for ElectrumBlockchain { fn get_capabilities(&self) -> HashSet { vec![Capability::FullHistory, Capability::GetAnyTx] .into_iter() .collect() } fn setup( &mut self, stop_gap: Option, database: &mut D, _progress_update: P, ) -> Result<(), Error> { // TODO: progress let stop_gap = stop_gap.unwrap_or(20); let batch_query_size = 20; // check unconfirmed tx, delete so they are retrieved later let mut del_batch = database.begin_batch(); for tx in database.iter_txs(false)? { if tx.height.is_none() { del_batch.del_tx(&tx.txid, false)?; } } 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 already_checked: HashSet