From ec9d648b388442228924164c403f9fc0ef8b9b99 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 5901c9af9a..919ee76ba9 100644 --- a/src/index.rs +++ b/src/index.rs @@ -85,6 +85,7 @@ pub(crate) enum Statistic { UnboundInscriptions = 5, CursedInscriptions = 6, BlessedInscriptions = 7, + Runes = 8, } impl Statistic { 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 11fd03c8cc..471d64cfda 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -382,12 +382,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 0065328387..29748d3965 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<()> { @@ -146,12 +155,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 4fbae8ce6a..01598d2441 100644 --- a/src/runes.rs +++ b/src/runes.rs @@ -1243,6 +1243,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1294,6 +1295,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1416,6 +1418,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1467,6 +1470,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1528,6 +1532,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1662,6 +1667,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1731,6 +1737,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -1919,6 +1926,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ), @@ -2159,6 +2167,7 @@ mod tests { etching: txid1, rune: Rune(RUNE + 1), supply: u128::max_value(), + number: 1, ..Default::default() } ) @@ -2228,6 +2237,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 97da562c7f..a87a72d8db 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -3261,6 +3261,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