diff --git a/deploy/ord.service b/deploy/ord.service
index e04b8dd803..c068bde8af 100644
--- a/deploy/ord.service
+++ b/deploy/ord.service
@@ -15,6 +15,7 @@ ExecStart=/usr/local/bin/ord \
--data-dir /var/lib/ord \
--index-runes \
--index-sats \
+ --index-transactions \
server \
--acme-contact mailto:casey@rodarmor.com \
--csp-origin https://ordinals.com \
diff --git a/src/index.rs b/src/index.rs
index 99c66f5b98..b2611b3ec0 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -20,8 +20,8 @@ use {
log::log_enabled,
redb::{
Database, DatabaseError, MultimapTable, MultimapTableDefinition, MultimapTableHandle,
- ReadableMultimapTable, ReadableTable, RedbKey, RedbValue, StorageError, Table, TableDefinition,
- TableHandle, WriteTransaction,
+ ReadOnlyTable, ReadableMultimapTable, ReadableTable, RedbKey, RedbValue, StorageError, Table,
+ TableDefinition, TableHandle, WriteTransaction,
},
std::{
collections::{BTreeSet, HashMap},
@@ -41,7 +41,7 @@ mod updater;
#[cfg(test)]
pub(crate) mod testing;
-const SCHEMA_VERSION: u64 = 15;
+const SCHEMA_VERSION: u64 = 16;
macro_rules! define_table {
($name:ident, $key:ty, $value:ty) => {
@@ -75,6 +75,7 @@ define_table! { SEQUENCE_NUMBER_TO_RUNE_ID, u32, RuneIdValue }
define_table! { SEQUENCE_NUMBER_TO_SATPOINT, u32, &SatPointValue }
define_table! { STATISTIC_TO_COUNT, u64, u64 }
define_table! { TRANSACTION_ID_TO_RUNE, &TxidValue, u128 }
+define_table! { TRANSACTION_ID_TO_TRANSACTION, &TxidValue, &[u8] }
define_table! { WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP, u32, u128 }
#[derive(Debug, PartialEq)]
@@ -97,6 +98,7 @@ pub(crate) enum Statistic {
Runes,
SatRanges,
UnboundInscriptions,
+ IndexTransactions,
}
impl Statistic {
@@ -195,6 +197,7 @@ pub struct Index {
height_limit: Option,
index_runes: bool,
index_sats: bool,
+ index_transactions: bool,
options: Options,
path: PathBuf,
started: DateTime,
@@ -236,6 +239,7 @@ impl Index {
let index_runes;
let index_sats;
+ let index_transactions;
let index_path = path.clone();
let once = Once::new();
@@ -251,40 +255,32 @@ impl Index {
Ok(database) => {
{
let tx = database.begin_read()?;
- let schema_version = tx
- .open_table(STATISTIC_TO_COUNT)?
+ let statistics = tx.open_table(STATISTIC_TO_COUNT)?;
+
+ let schema_version = statistics
.get(&Statistic::Schema.key())?
.map(|x| x.value())
.unwrap_or(0);
match schema_version.cmp(&SCHEMA_VERSION) {
- cmp::Ordering::Less =>
- bail!(
- "index at `{}` appears to have been built with an older, incompatible version of ord, consider deleting and rebuilding the index: index schema {schema_version}, ord schema {SCHEMA_VERSION}",
- path.display()
- ),
- cmp::Ordering::Greater =>
- bail!(
- "index at `{}` appears to have been built with a newer, incompatible version of ord, consider updating ord: index schema {schema_version}, ord schema {SCHEMA_VERSION}",
- path.display()
- ),
- cmp::Ordering::Equal => {
+ cmp::Ordering::Less =>
+ bail!(
+ "index at `{}` appears to have been built with an older, incompatible version of ord, consider deleting and rebuilding the index: index schema {schema_version}, ord schema {SCHEMA_VERSION}",
+ path.display()
+ ),
+ cmp::Ordering::Greater =>
+ bail!(
+ "index at `{}` appears to have been built with a newer, incompatible version of ord, consider updating ord: index schema {schema_version}, ord schema {SCHEMA_VERSION}",
+ path.display()
+ ),
+ cmp::Ordering::Equal => {
+ }
}
- }
- let statistics = tx.open_table(STATISTIC_TO_COUNT)?;
- index_runes = statistics
- .get(&Statistic::IndexRunes.key())?
- .unwrap()
- .value()
- != 0;
-
- index_sats = statistics
- .get(&Statistic::IndexSats.key())?
- .unwrap()
- .value()
- != 0;
+ index_runes = Self::is_statistic_set(&statistics, Statistic::IndexRunes)?;
+ index_sats = Self::is_statistic_set(&statistics, Statistic::IndexSats)?;
+ index_transactions = Self::is_statistic_set(&statistics, Statistic::IndexTransactions)?;
}
database
@@ -329,15 +325,12 @@ impl Index {
index_runes = options.index_runes();
index_sats = options.index_sats;
+ index_transactions = options.index_transactions;
- statistics.insert(
- &Statistic::IndexRunes.key(),
- &u64::from(index_runes),
- )?;
-
- statistics.insert(&Statistic::IndexSats.key(), &u64::from(index_sats))?;
-
- statistics.insert(&Statistic::Schema.key(), &SCHEMA_VERSION)?;
+ Self::set_statistic(&mut statistics, Statistic::IndexRunes, u64::from(index_runes))?;
+ Self::set_statistic(&mut statistics, Statistic::IndexSats, u64::from(index_sats))?;
+ Self::set_statistic(&mut statistics, Statistic::IndexSats, u64::from(index_transactions))?;
+ Self::set_statistic(&mut statistics, Statistic::Schema, SCHEMA_VERSION)?;
}
tx.commit()?;
@@ -360,6 +353,7 @@ impl Index {
height_limit: options.height_limit,
index_runes,
index_sats,
+ index_transactions,
options: options.clone(),
path,
started: Utc::now(),
@@ -609,6 +603,12 @@ impl Index {
insert_table_info(&mut tables, &wtx, total_bytes, SEQUENCE_NUMBER_TO_SATPOINT);
insert_table_info(&mut tables, &wtx, total_bytes, STATISTIC_TO_COUNT);
insert_table_info(&mut tables, &wtx, total_bytes, TRANSACTION_ID_TO_RUNE);
+ insert_table_info(
+ &mut tables,
+ &wtx,
+ total_bytes,
+ TRANSACTION_ID_TO_TRANSACTION,
+ );
insert_table_info(
&mut tables,
&wtx,
@@ -791,6 +791,28 @@ impl Index {
Ok(())
}
+ pub(crate) fn set_statistic(
+ statistics: &mut Table,
+ statistic: Statistic,
+ value: u64,
+ ) -> Result<()> {
+ statistics.insert(&statistic.key(), &value)?;
+ Ok(())
+ }
+
+ pub(crate) fn is_statistic_set(
+ statistics: &ReadOnlyTable,
+ statistic: Statistic,
+ ) -> Result {
+ Ok(
+ statistics
+ .get(&statistic.key())?
+ .map(|guard| guard.value())
+ .unwrap_or_default()
+ != 0,
+ )
+ }
+
#[cfg(test)]
pub(crate) fn statistic(&self, statistic: Statistic) -> u64 {
self
@@ -1435,10 +1457,21 @@ impl Index {
pub(crate) fn get_transaction(&self, txid: Txid) -> Result