Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more info to /rune page #2528

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
self::{
entry::{
BlockHashValue, Entry, InscriptionEntry, InscriptionEntryValue, InscriptionIdValue,
OutPointValue, RuneEntryValue, RuneIdValue, SatPointValue, SatRange,
OutPointValue, RuneEntryValue, RuneIdValue, SatPointValue, SatRange, TxidValue,
},
reorg::*,
runes::{Rune, RuneId},
Expand Down Expand Up @@ -67,6 +67,7 @@ define_table! { RUNE_TO_RUNE_ID, u128, RuneIdValue }
define_table! { SAT_TO_SATPOINT, u64, &SatPointValue }
define_table! { SEQUENCE_NUMBER_TO_INSCRIPTION_ID, u64, &InscriptionIdValue }
define_table! { STATISTIC_TO_COUNT, u64, u64 }
define_table! { TRANSACTION_ID_TO_RUNE, &TxidValue, u128 }
define_table! { WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP, u64, u128 }

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -283,6 +284,7 @@ impl Index {
tx.open_table(RUNE_TO_RUNE_ID)?;
tx.open_table(SAT_TO_SATPOINT)?;
tx.open_table(SEQUENCE_NUMBER_TO_INSCRIPTION_ID)?;
tx.open_table(TRANSACTION_ID_TO_RUNE)?;
tx.open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)?;

{
Expand Down Expand Up @@ -797,6 +799,17 @@ impl Index {
.collect()
}

pub(crate) fn get_etching(&self, txid: Txid) -> Result<Option<Rune>> {
Ok(
self
.database
.begin_read()?
.open_table(TRANSACTION_ID_TO_RUNE)?
.get(&txid.store())?
.map(|entry| Rune(entry.value())),
)
}

pub(crate) fn get_rune_by_inscription_id(
&self,
inscription_id: InscriptionId,
Expand Down
27 changes: 19 additions & 8 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ pub(crate) struct RuneEntry {
pub(crate) rune: Rune,
pub(crate) supply: u128,
pub(crate) symbol: Option<char>,
pub(crate) timestamp: u32,
}

pub(super) type RuneEntryValue = (u128, u8, (u128, u128), u64, u128, u128, u32, u32);

impl Default for RuneEntry {
fn default() -> Self {
Self {
Expand All @@ -43,16 +46,17 @@ impl Default for RuneEntry {
rune: Rune(0),
supply: 0,
symbol: None,
timestamp: 0,
}
}
}

pub(super) type RuneEntryValue = (u128, u8, (u128, u128), u64, u128, u128, u32);

impl Entry for RuneEntry {
type Value = RuneEntryValue;

fn load((burned, divisibility, etching, number, rune, supply, symbol): RuneEntryValue) -> Self {
fn load(
(burned, divisibility, etching, number, rune, supply, symbol, timestamp): RuneEntryValue,
) -> Self {
Self {
burned,
divisibility,
Expand All @@ -70,6 +74,7 @@ impl Entry for RuneEntry {
rune: Rune(rune),
supply,
symbol: char::from_u32(symbol),
timestamp,
}
}

Expand Down Expand Up @@ -97,6 +102,7 @@ impl Entry for RuneEntry {
Some(symbol) => symbol.into(),
None => u32::max_value(),
},
self.timestamp,
)
}
}
Expand All @@ -120,31 +126,31 @@ pub(crate) struct InscriptionEntry {
pub(crate) fee: u64,
pub(crate) height: u64,
pub(crate) inscription_number: i64,
pub(crate) sequence_number: u64,
pub(crate) parent: Option<InscriptionId>,
pub(crate) sat: Option<Sat>,
pub(crate) sequence_number: u64,
pub(crate) timestamp: u32,
}

pub(crate) type InscriptionEntryValue = (u64, u64, i64, u64, ParentValue, u64, u32);
pub(crate) type InscriptionEntryValue = (u64, u64, i64, ParentValue, u64, u64, u32);

impl Entry for InscriptionEntry {
type Value = InscriptionEntryValue;

fn load(
(fee, height, inscription_number, sequence_number, parent, sat, timestamp): InscriptionEntryValue,
(fee, height, inscription_number, parent, sat, sequence_number, timestamp): InscriptionEntryValue,
) -> Self {
Self {
fee,
height,
inscription_number,
sequence_number,
parent: ParentEntry::load(parent),
sat: if sat == u64::MAX {
None
} else {
Some(Sat(sat))
},
sequence_number,
timestamp,
}
}
Expand All @@ -154,12 +160,12 @@ impl Entry for InscriptionEntry {
self.fee,
self.height,
self.inscription_number,
self.sequence_number,
self.parent.store(),
match self.sat {
Some(sat) => sat.n(),
None => u64::MAX,
},
self.sequence_number,
self.timestamp,
)
}
Expand Down Expand Up @@ -425,6 +431,7 @@ mod tests {
rune: Rune(4),
supply: 5,
symbol: Some('a'),
timestamp: 6,
};

assert_eq!(
Expand All @@ -440,6 +447,7 @@ mod tests {
4,
5,
u32::from('a'),
6,
)
);

Expand All @@ -455,6 +463,7 @@ mod tests {
4,
5,
u32::from('a'),
6,
)),
rune_entry
);
Expand All @@ -477,6 +486,7 @@ mod tests {
4,
5,
u32::max_value(),
6,
)
);

Expand All @@ -492,6 +502,7 @@ mod tests {
4,
5,
u32::max_value(),
6,
)),
rune_entry
);
Expand Down
5 changes: 4 additions & 1 deletion src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,14 +557,17 @@ impl<'index> Updater<'_> {
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 inscription_id_to_rune = wtx.open_table(INSCRIPTION_ID_TO_RUNE)?;
let mut transaction_id_to_rune = wtx.open_table(TRANSACTION_ID_TO_RUNE)?;
let mut rune_updater = RuneUpdater::new(
self.height,
&mut outpoint_to_rune_balances,
&mut rune_id_to_rune_entry,
&inscription_id_to_inscription_entry,
&mut inscription_id_to_rune,
&mut outpoint_to_rune_balances,
&mut rune_to_rune_id,
&mut statistic_to_count,
block.header.time,
&mut transaction_id_to_rune,
)?;
for (i, (tx, txid)) in block.txdata.iter().enumerate() {
rune_updater.index_runes(i, tx, *txid)?;
Expand Down
14 changes: 11 additions & 3 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ pub(super) struct RuneUpdater<'a, 'db, 'tx> {
rune_to_id: &'a mut Table<'db, 'tx, u128, RuneIdValue>,
runes: u64,
statistic_to_count: &'a mut Table<'db, 'tx, u64, u64>,
timestamp: u32,
transaction_id_to_rune: &'a mut Table<'db, 'tx, &'static TxidValue, u128>,
}

impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
pub(super) fn new(
height: u64,
outpoint_to_balances: &'a mut Table<'db, 'tx, &'static OutPointValue, &'static [u8]>,
id_to_entry: &'a mut Table<'db, 'tx, RuneIdValue, RuneEntryValue>,
inscription_id_to_inscription_entry: &'a Table<
'db,
Expand All @@ -36,8 +37,11 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
InscriptionEntryValue,
>,
inscription_id_to_rune: &'a mut Table<'db, 'tx, &'static InscriptionIdValue, u128>,
outpoint_to_balances: &'a mut Table<'db, 'tx, &'static OutPointValue, &'static [u8]>,
rune_to_id: &'a mut Table<'db, 'tx, u128, RuneIdValue>,
statistic_to_count: &'a mut Table<'db, 'tx, u64, u64>,
timestamp: u32,
transaction_id_to_rune: &'a mut Table<'db, 'tx, &'static TxidValue, u128>,
) -> Result<Self> {
let runes = statistic_to_count
.get(&Statistic::Runes.into())?
Expand All @@ -46,13 +50,15 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
Ok(Self {
height,
id_to_entry,
minimum: Rune::minimum_at_height(Height(height)),
outpoint_to_balances,
inscription_id_to_inscription_entry,
inscription_id_to_rune,
minimum: Rune::minimum_at_height(Height(height)),
outpoint_to_balances,
rune_to_id,
runes,
statistic_to_count,
timestamp,
transaction_id_to_rune,
})
}

Expand Down Expand Up @@ -198,6 +204,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
{
let id = RuneId::try_from(id).unwrap();
self.rune_to_id.insert(rune.0, id.store())?;
self.transaction_id_to_rune.insert(&txid.store(), rune.0)?;
let number = self.runes;
self.runes += 1;
self
Expand All @@ -213,6 +220,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
rune,
supply: u128::max_value() - balance,
symbol,
timestamp: self.timestamp,
}
.store(),
)?;
Expand Down
Loading
Loading