Remove async, upgrade electrum-client
This commit is contained in:
@@ -27,23 +27,22 @@ pub struct ELSListUnspentRes {
|
||||
}
|
||||
|
||||
/// Implements the synchronization logic for an Electrum-like client.
|
||||
#[async_trait(?Send)]
|
||||
pub trait ElectrumLikeSync {
|
||||
async fn els_batch_script_get_history<'s, I: IntoIterator<Item = &'s Script>>(
|
||||
fn els_batch_script_get_history<'s, I: IntoIterator<Item = &'s Script>>(
|
||||
&mut self,
|
||||
scripts: I,
|
||||
) -> Result<Vec<Vec<ELSGetHistoryRes>>, Error>;
|
||||
|
||||
async fn els_batch_script_list_unspent<'s, I: IntoIterator<Item = &'s Script>>(
|
||||
fn els_batch_script_list_unspent<'s, I: IntoIterator<Item = &'s Script>>(
|
||||
&mut self,
|
||||
scripts: I,
|
||||
) -> Result<Vec<Vec<ELSListUnspentRes>>, Error>;
|
||||
|
||||
async fn els_transaction_get(&mut self, txid: &Txid) -> Result<Transaction, Error>;
|
||||
fn els_transaction_get(&mut self, txid: &Txid) -> Result<Transaction, Error>;
|
||||
|
||||
// Provided methods down here...
|
||||
|
||||
async fn electrum_like_setup<D: BatchDatabase + DatabaseUtils, P: Progress>(
|
||||
fn electrum_like_setup<D: BatchDatabase + DatabaseUtils, P: Progress>(
|
||||
&mut self,
|
||||
stop_gap: Option<usize>,
|
||||
database: &mut D,
|
||||
@@ -86,7 +85,7 @@ pub trait ElectrumLikeSync {
|
||||
|
||||
let until = cmp::min(to_check_later.len(), batch_query_size);
|
||||
let chunk: Vec<Script> = to_check_later.drain(..until).collect();
|
||||
let call_result = self.els_batch_script_get_history(chunk.iter()).await?;
|
||||
let call_result = self.els_batch_script_get_history(chunk.iter())?;
|
||||
|
||||
for (script, history) in chunk.into_iter().zip(call_result.into_iter()) {
|
||||
trace!("received history for {:?}, size {}", script, history.len());
|
||||
@@ -95,8 +94,7 @@ pub trait ElectrumLikeSync {
|
||||
last_found = index;
|
||||
|
||||
let mut check_later_scripts = self
|
||||
.check_history(database, script, history, &mut change_max_deriv)
|
||||
.await?
|
||||
.check_history(database, script, history, &mut change_max_deriv)?
|
||||
.into_iter()
|
||||
.filter(|x| already_checked.insert(x.clone()))
|
||||
.collect();
|
||||
@@ -126,7 +124,7 @@ pub trait ElectrumLikeSync {
|
||||
let mut batch = database.begin_batch();
|
||||
for chunk in ChunksIterator::new(database.iter_utxos()?.into_iter(), batch_query_size) {
|
||||
let scripts: Vec<_> = chunk.iter().map(|u| &u.txout.script_pubkey).collect();
|
||||
let call_result = self.els_batch_script_list_unspent(scripts).await?;
|
||||
let call_result = self.els_batch_script_list_unspent(scripts)?;
|
||||
|
||||
// check which utxos are actually still unspent
|
||||
for (utxo, list_unspent) in chunk.into_iter().zip(call_result.iter()) {
|
||||
@@ -169,7 +167,7 @@ pub trait ElectrumLikeSync {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn check_tx_and_descendant<D: DatabaseUtils + BatchDatabase>(
|
||||
fn check_tx_and_descendant<D: DatabaseUtils + BatchDatabase>(
|
||||
&mut self,
|
||||
database: &mut D,
|
||||
txid: &Txid,
|
||||
@@ -201,7 +199,7 @@ pub trait ElectrumLikeSync {
|
||||
// went wrong
|
||||
saved_tx.transaction.unwrap()
|
||||
}
|
||||
None => self.els_transaction_get(&txid).await?,
|
||||
None => self.els_transaction_get(&txid)?,
|
||||
};
|
||||
|
||||
let mut incoming: u64 = 0;
|
||||
@@ -264,7 +262,7 @@ pub trait ElectrumLikeSync {
|
||||
Ok(to_check_later)
|
||||
}
|
||||
|
||||
async fn check_history<D: DatabaseUtils + BatchDatabase>(
|
||||
fn check_history<D: DatabaseUtils + BatchDatabase>(
|
||||
&mut self,
|
||||
database: &mut D,
|
||||
script_pubkey: Script,
|
||||
@@ -286,17 +284,13 @@ pub trait ElectrumLikeSync {
|
||||
x => u32::try_from(x).ok(),
|
||||
};
|
||||
|
||||
to_check_later.extend_from_slice(
|
||||
&self
|
||||
.check_tx_and_descendant(
|
||||
database,
|
||||
&tx.tx_hash,
|
||||
height,
|
||||
&script_pubkey,
|
||||
change_max_deriv,
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
to_check_later.extend_from_slice(&self.check_tx_and_descendant(
|
||||
database,
|
||||
&tx.tx_hash,
|
||||
height,
|
||||
&script_pubkey,
|
||||
change_max_deriv,
|
||||
)?);
|
||||
}
|
||||
|
||||
Ok(to_check_later)
|
||||
|
||||
Reference in New Issue
Block a user