Skip to content

Commit

Permalink
Show etching and inscription on /rune page (#2512)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 10, 2023
1 parent a921f27 commit 8f0374b
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 137 deletions.
11 changes: 11 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,17 @@ impl Index {
}))
}

pub(crate) fn inscription_exists(&self, inscription_id: InscriptionId) -> Result<bool> {
Ok(
self
.database
.begin_read()?
.open_table(INSCRIPTION_ID_TO_SATPOINT)?
.get(&inscription_id.store())?
.is_some(),
)
}

pub(crate) fn get_inscriptions_on_output_with_satpoints(
&self,
outpoint: OutPoint,
Expand Down
63 changes: 59 additions & 4 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,31 @@ impl Entry for BlockHash {
pub(crate) struct RuneEntry {
pub(crate) burned: u128,
pub(crate) divisibility: u8,
pub(crate) etching: Txid,
pub(crate) rarity: Rarity,
pub(crate) rune: Rune,
pub(crate) supply: u128,
}

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

impl Entry for RuneEntry {
type Value = RuneEntryValue;

fn load((burned, divisibility, rarity, rune, supply): RuneEntryValue) -> Self {
fn load((burned, divisibility, etching, rarity, rune, supply): RuneEntryValue) -> Self {
Self {
burned,
divisibility,
etching: {
let low = etching.0.to_le_bytes();
let high = etching.1.to_le_bytes();
Txid::from_byte_array([
low[0], low[1], low[2], low[3], low[4], low[5], low[6], low[7], low[8], low[9], low[10],
low[11], low[12], low[13], low[14], low[15], high[0], high[1], high[2], high[3], high[4],
high[5], high[6], high[7], high[8], high[9], high[10], high[11], high[12], high[13],
high[14], high[15],
])
},
rarity: Rarity::try_from(rarity).unwrap(),
rune: Rune(rune),
supply,
Expand All @@ -50,6 +61,19 @@ impl Entry for RuneEntry {
(
self.burned,
self.divisibility,
{
let bytes = self.etching.to_byte_array();
(
u128::from_le_bytes([
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15],
]),
u128::from_le_bytes([
bytes[16], bytes[17], bytes[18], bytes[19], bytes[20], bytes[21], bytes[22], bytes[23],
bytes[24], bytes[25], bytes[26], bytes[27], bytes[28], bytes[29], bytes[30], bytes[31],
]),
)
},
self.rarity.into(),
self.rune.0,
self.supply,
Expand Down Expand Up @@ -372,14 +396,45 @@ mod tests {
let rune_entry = RuneEntry {
burned: 1,
divisibility: 2,
etching: Txid::from_byte_array([
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
0x1E, 0x1F,
]),
rarity: Rarity::Epic,
rune: Rune(4),
supply: 5,
};

assert_eq!(rune_entry.store(), (1, 2, 3, 4, 5));
assert_eq!(
rune_entry.store(),
(
1,
2,
(
0x0F0E0D0C0B0A09080706050403020100,
0x1F1E1D1C1B1A19181716151413121110
),
3,
4,
5,
)
);

assert_eq!(RuneEntry::load((1, 2, 3, 4, 5)), rune_entry);
assert_eq!(
RuneEntry::load((
1,
2,
(
0x0F0E0D0C0B0A09080706050403020100,
0x1F1E1D1C1B1A19181716151413121110
),
3,
4,
5,
)),
rune_entry
);
}

#[test]
Expand Down
11 changes: 6 additions & 5 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
// ignored.
match u16::try_from(index) {
Ok(index) => Some(Allocation {
id: u128::from(self.height) << 16 | u128::from(index),
balance: u128::max_value(),
rune: etching.rune,
divisibility: etching.divisibility,
id: u128::from(self.height) << 16 | u128::from(index),
rune: etching.rune,
}),
Err(_) => None,
}
Expand Down Expand Up @@ -128,10 +128,10 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
}

if let Some(Allocation {
id,
balance,
rune,
divisibility,
id,
rune,
}) = allocation
{
// Calculate the allocated supply
Expand All @@ -145,14 +145,15 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
id.store(),
RuneEntry {
burned: 0,
divisibility,
etching: txid,
rarity: if self.count == 0 {
self.rarity
} else {
Rarity::Common
},
rune,
supply,
divisibility,
}
.store(),
)?;
Expand Down
Loading

0 comments on commit 8f0374b

Please sign in to comment.