Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug: esplora negative balance #35

Merged
merged 1 commit into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/indexers/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use std::collections::BTreeMap;
use std::num::NonZeroU32;

use bpstd::{Address, LockTime, Outpoint, SeqNo, Witness};
use bpstd::{Address, LockTime, Outpoint, ScriptPubkey, SeqNo, Witness};
use descriptors::Descriptor;
use esplora::{BlockingClient, Error};

Expand Down Expand Up @@ -97,6 +97,29 @@ impl From<esplora::Tx> for WalletTx {
}
}

fn get_scripthash_txs_all(
client: &BlockingClient,
script: &ScriptPubkey,
) -> Result<Vec<esplora::Tx>, Error> {
const PAGE_SIZE: usize = 25;
let mut res = Vec::new();
let mut last_seen = None;
loop {
let r = client.scripthash_txs(script, last_seen)?;
match &r[..] {
[a @ .., esplora::Tx { txid, .. }] if a.len() >= PAGE_SIZE - 1 => {
last_seen = Some(*txid);
res.extend(r);
}
_ => {
res.extend(r);
break;
}
}
}
Ok(res)
}

impl Indexer for BlockingClient {
type Error = Error;

Expand All @@ -116,7 +139,7 @@ impl Indexer for BlockingClient {

eprint!(".");
let mut txids = Vec::new();
match self.scripthash_txs(&script, None) {
match get_scripthash_txs_all(self, &script) {
Err(err) => {
errors.push(err);
break;
Expand Down
Loading