diff --git a/src/index.rs b/src/index.rs index 0bfc0b588c..36a5fd72d5 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1986,6 +1986,55 @@ mod tests { } } + #[test] + fn inscriptions_are_not_indexed_if_no_index_inscriptions_flag_is_set() { + let inscription = inscription("text/plain;charset=utf-8", "hello"); + let template = TransactionTemplate { + inputs: &[(1, 0, 0, inscription.to_witness())], + ..Default::default() + }; + + { + let context = Context::builder().build(); + context.mine_blocks(1); + let txid = context.rpc_server.broadcast_tx(template.clone()); + let inscription_id = InscriptionId { txid, index: 0 }; + context.mine_blocks(1); + + assert_eq!( + context.index.get_inscription_by_id(inscription_id).unwrap(), + Some(inscription) + ); + + assert_eq!( + context + .index + .get_inscription_satpoint_by_id(inscription_id) + .unwrap(), + Some(SatPoint { + outpoint: OutPoint { txid, vout: 0 }, + offset: 0, + }) + ); + } + + { + let context = Context::builder().arg("--no-index-inscriptions").build(); + context.mine_blocks(1); + let txid = context.rpc_server.broadcast_tx(template); + let inscription_id = InscriptionId { txid, index: 0 }; + context.mine_blocks(1); + + assert_eq!( + context + .index + .get_inscription_satpoint_by_id(inscription_id) + .unwrap(), + None, + ); + } + } + #[test] fn list_first_coinbase_transaction() { let context = Context::builder().arg("--index-sats").build(); diff --git a/src/index/updater.rs b/src/index/updater.rs index c9f91b37cb..32ca04e377 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -340,7 +340,8 @@ impl<'index> Updater<'_> { let mut outpoint_to_value = wtx.open_table(OUTPOINT_TO_VALUE)?; - let index_inscriptions = self.height >= index.first_inscription_height; + let index_inscriptions = + self.height >= index.first_inscription_height && !index.options.no_index_inscriptions; if index_inscriptions { // Send all missing input outpoints to be fetched right away @@ -535,7 +536,7 @@ impl<'index> Updater<'_> { outpoint_to_sat_ranges.insert(&OutPoint::null().store(), lost_sat_ranges.as_slice())?; } - } else { + } else if index_inscriptions { for (tx, txid) in block.txdata.iter().skip(1).chain(block.txdata.first()) { inscription_updater.index_envelopes(tx, *txid, None)?; } diff --git a/src/options.rs b/src/options.rs index d34c9bf736..7be2e34100 100644 --- a/src/options.rs +++ b/src/options.rs @@ -49,6 +49,13 @@ pub(crate) struct Options { pub(crate) index_runes: bool, #[arg(long, help = "Track location of all satoshis.")] pub(crate) index_sats: bool, + #[arg( + long, + short, + alias = "noindex_inscriptions", + help = "Do not index inscriptions." + )] + pub(crate) no_index_inscriptions: bool, #[arg(long, short, help = "Use regtest. Equivalent to `--chain regtest`.")] pub(crate) regtest: bool, #[arg(long, help = "Connect to Bitcoin Core RPC at .")]