Skip to content

Commit

Permalink
Add rune numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Oct 17, 2023
1 parent 49ec31c commit ec9d648
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub(crate) enum Statistic {
UnboundInscriptions = 5,
CursedInscriptions = 6,
BlessedInscriptions = 7,
Runes = 8,
}

impl Statistic {
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 @@ -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)?;
}
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 @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1294,6 +1295,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1416,6 +1418,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1467,6 +1470,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1528,6 +1532,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1662,6 +1667,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1731,6 +1737,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -1919,6 +1926,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
),
Expand Down Expand Up @@ -2159,6 +2167,7 @@ mod tests {
etching: txid1,
rune: Rune(RUNE + 1),
supply: u128::max_value(),
number: 1,
..Default::default()
}
)
Expand Down Expand Up @@ -2228,6 +2237,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 @@ -3261,6 +3261,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

0 comments on commit ec9d648

Please sign in to comment.