Skip to content

Commit 085872d

Browse files
authored
Add index-unspendables CLI flag (#28)
1 parent c09bb05 commit 085872d

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ In addition to electrs's original configuration options, a few new options are a
6666
- `--lightmode` - enable light mode (see above)
6767
- `--cors <origins>` - origins allowed to make cross-site request (optional, defaults to none).
6868
- `--address-search` - enables the by-prefix address search index.
69+
- `--index-unspendables` - enables indexing of provably unspendable outputs.
6970
- `--utxos-limit <num>` - maximum number of utxos to return per address.
7071
- `--electrum-txs-limit <num>` - maximum number of txs to return per address in the electrum server (does not apply for the http api).
7172
- `--electrum-banner <text>` - welcome banner text for electrum server.

doc/schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ When the indexer is synced up to the tip of the chain, the hash of the tip is sa
4343

4444
### `history`
4545

46-
Each funding output (except for provably unspendable ones) results in the following new rows (`H` is for history, `F` is for funding):
46+
Each funding output (except for provably unspendable ones when `--index-unspendables` is not enabled) results in the following new rows (`H` is for history, `F` is for funding):
4747

4848
* `"H{funding-scripthash}{funding-height}F{funding-txid:vout}{value}" → ""`
4949
* `"a{funding-address-str}" → ""` (for prefix address search, only saved when `--address-search` is enabled)

src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct Config {
3131
pub jsonrpc_import: bool,
3232
pub light_mode: bool,
3333
pub address_search: bool,
34+
pub index_unspendables: bool,
3435
pub cors: Option<String>,
3536
pub precache_scripts: Option<String>,
3637
pub utxos_limit: usize,
@@ -148,6 +149,11 @@ impl Config {
148149
.long("address-search")
149150
.help("Enable prefix address search")
150151
)
152+
.arg(
153+
Arg::with_name("index_unspendables")
154+
.long("index-unspendables")
155+
.help("Enable indexing of provably unspendable outputs")
156+
)
151157
.arg(
152158
Arg::with_name("cors")
153159
.long("cors")
@@ -362,6 +368,7 @@ impl Config {
362368
jsonrpc_import: m.is_present("jsonrpc_import"),
363369
light_mode: m.is_present("light_mode"),
364370
address_search: m.is_present("address_search"),
371+
index_unspendables: m.is_present("index_unspendables"),
365372
cors: m.value_of("cors").map(|s| s.to_string()),
366373
precache_scripts: m.value_of("precache_scripts").map(|s| s.to_string()),
367374

src/new_index/mempool.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,14 @@ impl Mempool {
378378
)
379379
});
380380

381+
let config = &self.config;
382+
381383
// An iterator over (ScriptHash, TxHistoryInfo)
382384
let funding = tx
383385
.output
384386
.iter()
385387
.enumerate()
386-
.filter(|(_, txo)| is_spendable(txo))
388+
.filter(|(_, txo)| is_spendable(txo) || config.index_unspendables)
387389
.map(|(index, txo)| {
388390
(
389391
compute_script_hash(&txo.script_pubkey),

src/new_index/schema.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ pub struct Indexer {
169169
struct IndexerConfig {
170170
light_mode: bool,
171171
address_search: bool,
172+
index_unspendables: bool,
172173
network: Network,
173174
#[cfg(feature = "liquid")]
174175
parent_network: Network,
@@ -179,6 +180,7 @@ impl From<&Config> for IndexerConfig {
179180
IndexerConfig {
180181
light_mode: config.light_mode,
181182
address_search: config.address_search,
183+
index_unspendables: config.index_unspendables,
182184
network: config.network_type,
183185
#[cfg(feature = "liquid")]
184186
parent_network: config.parent_network,
@@ -1072,7 +1074,7 @@ fn index_transaction(
10721074
// S{funding-txid:vout}{spending-txid:vin} → ""
10731075
let txid = full_hash(&tx.txid()[..]);
10741076
for (txo_index, txo) in tx.output.iter().enumerate() {
1075-
if is_spendable(txo) {
1077+
if is_spendable(txo) || iconfig.index_unspendables {
10761078
let history = TxHistoryRow::new(
10771079
&txo.script_pubkey,
10781080
confirmed_height,

0 commit comments

Comments
 (0)