Skip to content

Commit

Permalink
Add option --index-transfers to have the index track which inscript…
Browse files Browse the repository at this point in the history
…ions are transferred in each block. Previously this was already enabled, using up space in the index whether it was needed or not.
  • Loading branch information
gmart7t2 committed Dec 11, 2023
1 parent 8d39d17 commit f888c24
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub(crate) struct Index {
genesis_block_coinbase_transaction: Transaction,
genesis_block_coinbase_txid: Txid,
height_limit: Option<u64>,
index_transfers: bool,
no_progress_bar: bool,
options: Options,
unrecoverably_reorged: AtomicBool,
Expand Down Expand Up @@ -274,6 +275,7 @@ impl Index {
first_inscription_height: options.first_inscription_height(),
genesis_block_coinbase_transaction,
height_limit: options.height_limit,
index_transfers: options.index_transfers,
no_progress_bar: options.no_progress_bar,
options: options.clone(),
unrecoverably_reorged: AtomicBool::new(false),
Expand Down
6 changes: 5 additions & 1 deletion src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ impl<'index> Updater<'_> {
}

let mut height_to_block_hash = wtx.open_table(HEIGHT_TO_BLOCK_HASH)?;
let mut height_to_inscription_id = wtx.open_multimap_table(HEIGHT_TO_INSCRIPTION_ID)?;
let mut height_to_inscription_id = if index.index_transfers {
Some(wtx.open_multimap_table(HEIGHT_TO_INSCRIPTION_ID)?)
} else {
None
};
let mut inscription_id_to_inscription_entry =
wtx.open_table(INSCRIPTION_ID_TO_INSCRIPTION_ENTRY)?;
let mut inscription_id_to_satpoint = wtx.open_table(INSCRIPTION_ID_TO_SATPOINT)?;
Expand Down
10 changes: 5 additions & 5 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum Origin {
pub(super) struct InscriptionUpdater<'a, 'db, 'tx> {
flotsam: Vec<Flotsam>,
height: u64,
height_to_inscription_id: &'a mut MultimapTable<'db, 'tx, u64, &'static InscriptionIdValue>,
height_to_inscription_id: &'a mut Option<MultimapTable<'db, 'tx, u64, &'static InscriptionIdValue>>,
id_to_satpoint: &'a mut Table<'db, 'tx, &'static InscriptionIdValue, &'static SatPointValue>,
value_receiver: &'a mut Receiver<u64>,
id_to_entry: &'a mut Table<'db, 'tx, &'static InscriptionIdValue, InscriptionEntryValue>,
Expand All @@ -44,7 +44,7 @@ pub(super) struct InscriptionUpdater<'a, 'db, 'tx> {
impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
pub(super) fn new(
height: u64,
height_to_inscription_id: &'a mut MultimapTable<'db, 'tx, u64, &'static InscriptionIdValue>,
height_to_inscription_id: &'a mut Option<MultimapTable<'db, 'tx, u64, &'static InscriptionIdValue>>,
id_to_satpoint: &'a mut Table<'db, 'tx, &'static InscriptionIdValue, &'static SatPointValue>,
value_receiver: &'a mut Receiver<u64>,
id_to_entry: &'a mut Table<'db, 'tx, &'static InscriptionIdValue, InscriptionEntryValue>,
Expand Down Expand Up @@ -377,9 +377,9 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
old_satpoint,
new_satpoint
);
self
.height_to_inscription_id
.insert(&self.height, &inscription_id)?;
if let Some(height_to_inscription_id) = &mut self.height_to_inscription_id {
height_to_inscription_id.insert(&self.height, &inscription_id)?;
}
self.satpoint_to_id.remove_all(&old_satpoint.store())?;

false
Expand Down
2 changes: 2 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub(crate) struct Options {
pub(crate) index: Option<PathBuf>,
#[clap(long, help = "Track location of all satoshis.")]
pub(crate) index_sats: bool,
#[clap(long, help = "Track transfers of inscriptions.")]
pub(crate) index_transfers: bool,
#[clap(
long,
help = "Track location of all satoshis and the utxos that own them. Implies --index-sats."
Expand Down

0 comments on commit f888c24

Please sign in to comment.