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 rune numbers #2557

Merged
merged 2 commits into from
Oct 24, 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
1 change: 1 addition & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub(crate) enum Statistic {
IndexSats,
LostSats,
OutputsTraversed,
Runes,
SatRanges,
Schema,
UnboundInscriptions,
Expand Down
17 changes: 13 additions & 4 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char>,
Expand All @@ -38,19 +39,20 @@ impl Default for RuneEntry {
burned: 0,
divisibility: 0,
etching: Txid::all_zeros(),
number: 0,
rune: Rune(0),
supply: 0,
symbol: None,
}
}
}

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,
Expand All @@ -64,6 +66,7 @@ impl Entry for RuneEntry {
high[14], high[15],
])
},
number,
rune: Rune(rune),
supply,
symbol: char::from_u32(symbol),
Expand All @@ -87,6 +90,7 @@ impl Entry for RuneEntry {
]),
)
},
self.number,
self.rune.0,
self.supply,
match self.symbol {
Expand Down Expand Up @@ -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'),
};

Expand All @@ -433,6 +438,7 @@ mod tests {
),
3,
4,
5,
u32::from('a'),
)
);
Expand All @@ -447,6 +453,7 @@ mod tests {
),
3,
4,
5,
u32::from('a'),
)),
rune_entry
Expand All @@ -468,6 +475,7 @@ mod tests {
),
3,
4,
5,
u32::max_value(),
)
);
Expand All @@ -482,6 +490,7 @@ mod tests {
),
3,
4,
5,
u32::max_value(),
)),
rune_entry
Expand Down
4 changes: 3 additions & 1 deletion src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
21 changes: 18 additions & 3 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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<Self> {
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<()> {
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1310,6 +1311,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1432,6 +1434,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1483,6 +1486,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1544,6 +1548,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1678,6 +1683,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1747,6 +1753,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1935,6 +1942,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
),
Expand Down Expand Up @@ -2175,6 +2183,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -2244,6 +2253,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down
2 changes: 2 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3319,6 +3319,8 @@ mod tests {
<dl>
<dt>id</dt>
<dd>2/1</dd>
<dt>number</dt>
<dd>0</dd>
<dt>supply</dt>
<dd>\$340282366920938463463374607431768211455</dd>
<dt>burned</dt>
Expand Down
5 changes: 4 additions & 1 deletion src/templates/rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -42,6 +43,8 @@ mod tests {
<dl>
<dt>id</dt>
<dd>10/9</dd>
<dt>number</dt>
<dd>25</dd>
<dt>supply</dt>
<dd>\$123456789.123456789</dd>
<dt>burned</dt>
Expand Down
2 changes: 2 additions & 0 deletions templates/rune.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ <h1>Rune {{ self.entry.rune }}</h1>
<dl>
<dt>id</dt>
<dd>{{ self.id }}</dd>
<dt>number</dt>
<dd>{{ self.entry.number }}</dd>
<dt>supply</dt>
<dd>{{ Pile{ amount: self.entry.supply, divisibility: self.entry.divisibility, symbol: self.entry.symbol } }}</dd>
<dt>burned</dt>
Expand Down
Loading