mempool / electrs

An efficient re-implementation of Electrum Server in Rust
MIT License
74 stars 35 forks source link

Add recent utxos rest API endpoint #97

Open mononaut opened 4 months ago

mononaut commented 4 months ago

Draft PR to add a new /address/:address/utxo/recent REST API endpoint, which returns the most recent utxos_limit confirmed utxos for the given address, plus all unconfirmed utxos, sorted in descending order of confirmation status & block height.

Motivation

Unlike the existing /address/:address/utxo endpoint, this new API retrieves UTXOs by scanning address history in reverse chronological order, which means it can return early with useful data once it hits one of the resource limits, rather than throwing errors on addresses with excessive activity.

This makes it more suitable for e.g. utxo charts and visualizations.

Implementation

The PR also adds a new config parameter utxos_history_limit, which defines the maximum number of transaction history entries to process while looking up utxos. If an address's utxos are buried beneath more than this number of history entries, the API may return early with fewer than utxos_limit confirmed utxos.

Results are cached under a new cache_db key prefix b'R'.

Todo