Skip to content

Commit

Permalink
Allow skpping indexing inscriptions (ordinals#2900)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Dec 24, 2023
1 parent e532b24 commit 66493ce
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)?;
}
Expand Down
7 changes: 7 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <RPC_URL>.")]
Expand Down

0 comments on commit 66493ce

Please sign in to comment.