Skip to content

Commit

Permalink
wallet: remove required resolver for RgbWallet construction
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 1, 2023
1 parent 0c22d86 commit a17c0b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ impl Runtime {
.wallets
.get(name)
.ok_or(RuntimeError::WalletUnknown(name.clone()))?;
RgbWallet::with(descr.clone(), &mut self.resolver).map_err(RuntimeError::from)
let mut wallet = RgbWallet::new(descr.clone());
wallet.update(&mut self.resolver)?;
Ok(wallet)
}

pub fn import_contract(
Expand Down
15 changes: 10 additions & 5 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,31 @@ pub struct RgbWallet {
}

impl RgbWallet {
pub fn with(descr: RgbDescr, resolver: &mut impl Resolver) -> Result<Self, String> {
let mut utxos = BTreeSet::new();
pub fn new(descr: RgbDescr) -> Self {
Self {
descr,
utxos: empty!(),
}
}

pub fn update(&mut self, resolver: &mut impl Resolver) -> Result<(), String> {
const STEP: u32 = 20;
for app in [0, 1, 9, 10] {
let mut index = 0;
loop {
debug!("Requesting {STEP} scripts from the Electrum server");
let scripts = descr.derive(app, index..(index + STEP));
let scripts = self.descr.derive(app, index..(index + STEP));
let set = resolver.resolve_utxo(scripts)?;
if set.is_empty() {
break;
}
debug!("Electrum server returned {} UTXOs", set.len());
utxos.extend(set);
self.utxos.extend(set);
index += STEP;
}
}

Ok(Self { descr, utxos })
Ok(())
}

pub fn utxo(&self, outpoint: Outpoint) -> Option<&Utxo> {
Expand Down

0 comments on commit a17c0b1

Please sign in to comment.