From fa670791b9f656bdf52a120b9c84396803917d25 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 17 Oct 2023 11:16:33 -0700 Subject: [PATCH] Add rune numbers --- src/index.rs | 1 + src/index/entry.rs | 17 +++++++++++++---- src/index/updater.rs | 4 +++- src/index/updater/rune_updater.rs | 21 ++++++++++++++++++--- src/runes.rs | 10 ++++++++++ src/subcommand/server.rs | 2 ++ src/templates/rune.rs | 5 ++++- templates/rune.html | 2 ++ 8 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/index.rs b/src/index.rs index 4a90797fea..e3851e6b94 100644 --- a/src/index.rs +++ b/src/index.rs @@ -83,6 +83,7 @@ pub(crate) enum Statistic { IndexSats, LostSats, OutputsTraversed, + Runes, SatRanges, Schema, UnboundInscriptions, diff --git a/src/index/entry.rs b/src/index/entry.rs index 3ec8afff72..c71b716cf0 100644 --- a/src/index/entry.rs +++ b/src/index/entry.rs @@ -27,6 +27,7 @@ pub(crate) struct RuneEntry { pub(crate) burned: u128, pub(crate) divisibility: u8, pub(crate) etching: Txid, + pub(crate) number: u64, pub(crate) rune: Rune, pub(crate) supply: u128, pub(crate) symbol: Option, @@ -38,6 +39,7 @@ impl Default for RuneEntry { burned: 0, divisibility: 0, etching: Txid::all_zeros(), + number: 0, rune: Rune(0), supply: 0, symbol: None, @@ -45,12 +47,12 @@ impl Default for RuneEntry { } } -pub(super) type RuneEntryValue = (u128, u8, (u128, u128), u128, u128, u32); +pub(super) type RuneEntryValue = (u128, u8, (u128, u128), u64, u128, u128, u32); impl Entry for RuneEntry { type Value = RuneEntryValue; - fn load((burned, divisibility, etching, rune, supply, symbol): RuneEntryValue) -> Self { + fn load((burned, divisibility, etching, number, rune, supply, symbol): RuneEntryValue) -> Self { Self { burned, divisibility, @@ -64,6 +66,7 @@ impl Entry for RuneEntry { high[14], high[15], ]) }, + number, rune: Rune(rune), supply, symbol: char::from_u32(symbol), @@ -87,6 +90,7 @@ impl Entry for RuneEntry { ]), ) }, + self.number, self.rune.0, self.supply, match self.symbol { @@ -417,8 +421,9 @@ mod tests { 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, ]), - rune: Rune(3), - supply: 4, + number: 3, + rune: Rune(4), + supply: 5, symbol: Some('a'), }; @@ -433,6 +438,7 @@ mod tests { ), 3, 4, + 5, u32::from('a'), ) ); @@ -447,6 +453,7 @@ mod tests { ), 3, 4, + 5, u32::from('a'), )), rune_entry @@ -468,6 +475,7 @@ mod tests { ), 3, 4, + 5, u32::max_value(), ) ); @@ -482,6 +490,7 @@ mod tests { ), 3, 4, + 5, u32::max_value(), )), rune_entry diff --git a/src/index/updater.rs b/src/index/updater.rs index 03f5d51411..8a3c3550f0 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -380,12 +380,14 @@ impl<'index> Updater<'_> { let mut outpoint_to_rune_balances = wtx.open_table(OUTPOINT_TO_RUNE_BALANCES)?; let mut rune_id_to_rune_entry = wtx.open_table(RUNE_ID_TO_RUNE_ENTRY)?; let mut rune_to_rune_id = wtx.open_table(RUNE_TO_RUNE_ID)?; + let mut statistic_to_count = wtx.open_table(STATISTIC_TO_COUNT)?; let mut rune_updater = RuneUpdater::new( self.height, &mut outpoint_to_rune_balances, &mut rune_id_to_rune_entry, &mut rune_to_rune_id, - ); + &mut statistic_to_count, + )?; for (i, (tx, txid)) in block.txdata.iter().enumerate() { rune_updater.index_runes(i, tx, *txid)?; } diff --git a/src/index/updater/rune_updater.rs b/src/index/updater/rune_updater.rs index bbca38911a..38d691c1e5 100644 --- a/src/index/updater/rune_updater.rs +++ b/src/index/updater/rune_updater.rs @@ -17,6 +17,8 @@ pub(super) struct RuneUpdater<'a, 'db, 'tx> { minimum: Rune, outpoint_to_balances: &'a mut Table<'db, 'tx, &'static OutPointValue, &'static [u8]>, rune_to_id: &'a mut Table<'db, 'tx, u128, RuneIdValue>, + runes: u64, + statistic_to_count: &'a mut Table<'db, 'tx, u64, u64>, } impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> { @@ -25,14 +27,21 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> { outpoint_to_balances: &'a mut Table<'db, 'tx, &'static OutPointValue, &'static [u8]>, id_to_entry: &'a mut Table<'db, 'tx, RuneIdValue, RuneEntryValue>, rune_to_id: &'a mut Table<'db, 'tx, u128, RuneIdValue>, - ) -> Self { - Self { + statistic_to_count: &'a mut Table<'db, 'tx, u64, u64>, + ) -> Result { + let runes = statistic_to_count + .get(&Statistic::Runes.into())? + .map(|x| x.value()) + .unwrap_or(0); + Ok(Self { height, id_to_entry, minimum: Rune::minimum_at_height(Height(height)), outpoint_to_balances, rune_to_id, - } + runes, + statistic_to_count, + }) } pub(super) fn index_runes(&mut self, index: usize, tx: &Transaction, txid: Txid) -> Result<()> { @@ -177,12 +186,18 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> { { let id = RuneId::try_from(id).unwrap(); self.rune_to_id.insert(rune.0, id.store())?; + let number = self.runes; + self.runes += 1; + self + .statistic_to_count + .insert(&Statistic::Runes.into(), self.runes)?; self.id_to_entry.insert( id.store(), RuneEntry { burned: 0, divisibility, etching: txid, + number, rune, supply: u128::max_value() - balance, symbol, diff --git a/src/runes.rs b/src/runes.rs index 775b3bade9..97d5c52341 100644 --- a/src/runes.rs +++ b/src/runes.rs @@ -1259,6 +1259,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1310,6 +1311,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1432,6 +1434,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1483,6 +1486,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1544,6 +1548,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1678,6 +1683,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1747,6 +1753,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1935,6 +1942,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ), @@ -2175,6 +2183,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -2244,6 +2253,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 5c665565c4..9f69a6d9b8 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -3319,6 +3319,8 @@ mod tests {
id
2/1
+
number
+
0
supply
\$340282366920938463463374607431768211455
burned
diff --git a/src/templates/rune.rs b/src/templates/rune.rs index 3efa16fdb3..54760e9655 100644 --- a/src/templates/rune.rs +++ b/src/templates/rune.rs @@ -24,9 +24,10 @@ mod tests { entry: RuneEntry { burned: 123456789123456789, divisibility: 9, + etching: Txid::all_zeros(), + number: 25, rune: Rune(u128::max_value()), supply: 123456789123456789, - etching: Txid::all_zeros(), symbol: Some('$'), }, id: RuneId { @@ -42,6 +43,8 @@ mod tests {
id
10/9
+
number
+
25
supply
\$123456789.123456789
burned
diff --git a/templates/rune.html b/templates/rune.html index c6c974af71..ea330ffef3 100644 --- a/templates/rune.html +++ b/templates/rune.html @@ -2,6 +2,8 @@

Rune {{ self.entry.rune }}

id
{{ self.id }}
+
number
+
{{ self.entry.number }}
supply
{{ Pile{ amount: self.entry.supply, divisibility: self.entry.divisibility, symbol: self.entry.symbol } }}
burned