impl WalletSync for AnyBlockchain {
fn wallet_sync<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
maybe_await!(impl_inner_method!(
fn wallet_setup<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
maybe_await!(impl_inner_method!(
use std::collections::HashSet;
use std::fmt;
+use std::ops::DerefMut;
use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
#[allow(clippy::mutex_atomic)] // Mutex is easier to understand than a CAS loop.
fn wallet_setup<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
let first_peer = &self.peers[0];
cf_sync.prepare_sync(Arc::clone(first_peer))?;
+ let mut database = database.borrow_mut();
+ let database = database.deref_mut();
+
let all_scripts = Arc::new(
database
.iter_script_pubkeys(None)?
batch.put_cf(
cf_handle,
StoreEntry::BlockHeaderIndex(Some(genesis.block_hash())).get_key(),
- &0usize.to_be_bytes(),
+ 0usize.to_be_bytes(),
);
store.write(batch)?;
}
batch.put_cf(
new_cf_handle,
StoreEntry::BlockHeaderIndex(Some(header.block_hash())).get_key(),
- &from.to_be_bytes(),
+ from.to_be_bytes(),
);
batch.put_cf(
new_cf_handle,
batch.put_cf(
cf_handle,
StoreEntry::BlockHeaderIndex(Some(header.block_hash())).get_key(),
- &(height).to_be_bytes(),
+ (height).to_be_bytes(),
);
batch.put_cf(
cf_handle,
//! ```
use std::collections::{HashMap, HashSet};
-use std::ops::Deref;
+use std::ops::{Deref, DerefMut};
#[allow(unused_imports)]
use log::{debug, error, info, trace};
impl WalletSync for ElectrumBlockchain {
fn wallet_setup<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
_progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
+ let mut database = database.borrow_mut();
+ let database = database.deref_mut();
let mut request = script_sync::start(database, self.stop_gap)?;
let mut block_times = HashMap::<u32, u32>::new();
let mut txid_to_height = HashMap::<Txid, u32>::new();
//! Esplora by way of `reqwest` HTTP client.
use std::collections::{HashMap, HashSet};
-use std::ops::Deref;
+use std::ops::{Deref, DerefMut};
use bitcoin::{Transaction, Txid};
impl WalletSync for EsploraBlockchain {
fn wallet_setup<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
_progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
use crate::blockchain::script_sync::Request;
+ let mut database = database.borrow_mut();
+ let database = database.deref_mut();
let mut request = script_sync::start(database, self.stop_gap)?;
let mut tx_index: HashMap<Txid, Tx> = HashMap::new();
//! Esplora by way of `ureq` HTTP client.
use std::collections::{HashMap, HashSet};
+use std::ops::DerefMut;
#[allow(unused_imports)]
use log::{debug, error, info, trace};
impl WalletSync for EsploraBlockchain {
fn wallet_setup<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
_progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
use crate::blockchain::script_sync::Request;
+ let mut database = database.borrow_mut();
+ let database = database.deref_mut();
let mut request = script_sync::start(database, self.stop_gap)?;
let mut tx_index: HashMap<Txid, Tx> = HashMap::new();
let batch_update = loop {
//! [Compact Filters/Neutrino](crate::blockchain::compact_filters), along with a generalized trait
//! [`Blockchain`] that can be implemented to build customized backends.
+use std::cell::RefCell;
use std::collections::HashSet;
use std::ops::Deref;
use std::sync::mpsc::{channel, Receiver, Sender};
/// Populate the internal database with transactions and UTXOs
fn wallet_setup<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
progress_update: Box<dyn Progress>,
) -> Result<(), Error>;
/// [`BatchOperations::del_utxo`]: crate::database::BatchOperations::del_utxo
fn wallet_sync<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
maybe_await!(self.wallet_setup(database, progress_update))
impl<T: WalletSync> WalletSync for Arc<T> {
fn wallet_setup<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
maybe_await!(self.deref().wallet_setup(database, progress_update))
fn wallet_sync<D: BatchDatabase>(
&self,
- database: &mut D,
+ database: &RefCell<D>,
progress_update: Box<dyn Progress>,
) -> Result<(), Error> {
maybe_await!(self.deref().wallet_sync(database, progress_update))
use bitcoincore_rpc::{Client, RpcApi};
use log::{debug, info};
use serde::{Deserialize, Serialize};
+use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
-use std::ops::Deref;
+use std::ops::{Deref, DerefMut};
use std::path::PathBuf;
use std::thread;
use std::time::Duration;
}
impl WalletSync for RpcBlockchain {
- fn wallet_setup<D>(&self, db: &mut D, prog: Box<dyn Progress>) -> Result<(), Error>
+ fn wallet_setup<D>(&self, db: &RefCell<D>, prog: Box<dyn Progress>) -> Result<(), Error>
where
D: BatchDatabase,
{
+ let mut db = db.borrow_mut();
+ let db = db.deref_mut();
let batch = DbState::new(db, &self.sync_params, &*prog)?
.sync_with_core(&self.client, self.is_descriptors)?
.as_db_batch()?;
.unwrap();
assert_matches!(&policy.item, EcdsaSignature(PkOrF::Fingerprint(f)) if f == &fingerprint);
- assert_matches!(&policy.contribution, Satisfaction::Complete {condition} if condition.csv == None && condition.timelock == None);
+ assert_matches!(&policy.contribution, Satisfaction::Complete {condition} if condition.csv.is_none() && condition.timelock.is_none());
}
// 2 pub keys descriptor, required 2 prv keys
.unwrap();
assert_matches!(policy.item, EcdsaSignature(PkOrF::Fingerprint(f)) if f == fingerprint);
- assert_matches!(policy.contribution, Satisfaction::Complete {condition} if condition.csv == None && condition.timelock == None);
+ assert_matches!(policy.contribution, Satisfaction::Complete {condition} if condition.csv.is_none() && condition.timelock.is_none());
}
// single key, 1 prv and 1 pub key descriptor, required 1 prv keys
use std::collections::HashMap;
use std::collections::{BTreeMap, HashSet};
use std::fmt;
-use std::ops::{Deref, DerefMut};
+use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;
let max_rounds = if has_wildcard { 100 } else { 1 };
for _ in 0..max_rounds {
- let sync_res =
- if run_setup {
- maybe_await!(blockchain
- .wallet_setup(self.database.borrow_mut().deref_mut(), new_progress()))
- } else {
- maybe_await!(blockchain
- .wallet_sync(self.database.borrow_mut().deref_mut(), new_progress()))
- };
+ let sync_res = if run_setup {
+ maybe_await!(blockchain.wallet_setup(&self.database, new_progress()))
+ } else {
+ maybe_await!(blockchain.wallet_sync(&self.database, new_progress()))
+ };
// If the error is the special `MissingCachedScripts` error, we return the number of
// scripts we should ensure cached.