Skip to content
Draft
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct Config {
pub rest_default_max_address_summary_txs: usize,
pub rest_max_mempool_page_size: usize,
pub rest_max_mempool_txid_page_size: usize,
pub rest_max_address_txs_filter_scan: usize,
pub electrum_max_line_size: usize,
pub electrum_max_subscriptions: usize,
pub electrum_max_clients: usize,
Expand Down Expand Up @@ -273,6 +274,12 @@ impl Config {
.help("The maximum number of transactions returned by the paginated /mempool/txids/page endpoint.")
.default_value("10000")
)
.arg(
Arg::with_name("rest_max_address_txs_filter_scan")
.long("rest-max-address-txs-filter-scan")
.help("The maximum number of address history transactions examined per request when the address/[address]/txs endpoint is called with the direction, amount or time filters.")
.default_value("10000")
)
.arg(
Arg::with_name("electrum_txs_limit")
.long("electrum-txs-limit")
Expand Down Expand Up @@ -584,6 +591,11 @@ impl Config {
"rest_max_mempool_txid_page_size",
usize
),
rest_max_address_txs_filter_scan: value_t_or_exit!(
m,
"rest_max_address_txs_filter_scan",
usize
),
electrum_max_line_size: value_t_or_exit!(m, "electrum_max_line_size", usize),
electrum_max_subscriptions: value_t_or_exit!(m, "electrum_max_subscriptions", usize),
electrum_max_clients: value_t_or_exit!(m, "electrum_max_clients", usize),
Expand Down
43 changes: 42 additions & 1 deletion src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use crate::new_index::{
SpendingInput, TxHistoryInfo, Utxo,
};
use crate::util::fees::{make_fee_histogram, TxFeeInfo};
use crate::util::{extract_tx_prevouts, full_hash, has_prevout, is_spendable, Bytes};
use crate::util::{
extract_tx_prevouts, full_hash, has_prevout, is_spendable, Bytes, TxHistoryFilter,
};

#[cfg(feature = "liquid")]
use crate::elements::asset;
Expand Down Expand Up @@ -145,6 +147,45 @@ impl Mempool {
})
}

pub fn history_filtered(
&self,
scripthash: &[u8],
last_seen_txid: Option<&Txid>,
limit: usize,
filter: &TxHistoryFilter,
) -> Vec<Transaction> {
let _timer = self
.latency
.with_label_values(&["history_filtered"])
.start_timer();

let entries = match self.history.get(scripthash) {
Some(entries) => entries,
None => return vec![],
};

let mut net_values: HashMap<Txid, i64> = HashMap::new();
for entry in entries {
let value = net_values.entry(entry.get_txid()).or_insert(0);
*value = value.saturating_add(entry.net_delta());
}

entries
.iter()
.map(|e| e.get_txid())
.unique()
.skip_while(|txid| last_seen_txid.is_some_and(|last_seen_txid| last_seen_txid != txid))
.skip(match last_seen_txid {
Some(_) => 1,
None => 0,
})
.filter(|txid| filter.matches(net_values[txid], None))
.take(limit)
.map(|txid| self.txstore.get(&txid).expect("missing mempool tx"))
.cloned()
.collect()
}

pub fn history_txids_iter<'a>(&'a self, scripthash: &[u8]) -> impl Iterator<Item = Txid> + 'a {
self.history
.get(scripthash)
Expand Down
4 changes: 2 additions & 2 deletions src/new_index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pub use self::fetch::{BlockEntry, FetchFrom};
pub use self::mempool::Mempool;
pub use self::query::Query;
pub use self::schema::{
compute_script_hash, parse_hash, ChainQuery, FundingInfo, Indexer, ScriptStats, SpendingInfo,
SpendingInput, Store, TxHistoryInfo, TxHistoryKey, TxHistoryRow, Utxo,
compute_script_hash, parse_hash, ChainQuery, FundingInfo, Indexer, ScanOutcome, ScriptStats,
SpendingInfo, SpendingInput, Store, TxHistoryInfo, TxHistoryKey, TxHistoryRow, Utxo,
};
Loading
Loading