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 etched runes in block #3366

Merged
merged 19 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
3 changes: 3 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Block {
pub best_height: u32,
pub height: u32,
pub inscriptions: Vec<InscriptionId>,
pub runes: Vec<RuneEntry>,
}

impl Block {
Expand All @@ -23,13 +24,15 @@ impl Block {
height: Height,
best_height: Height,
inscriptions: Vec<InscriptionId>,
runes: Vec<RuneEntry>,
) -> Self {
Self {
hash: block.header.block_hash(),
target: target_as_block_hash(block.header.target()),
height: height.0,
best_height: best_height.0,
inscriptions,
runes,
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,29 @@ impl Index {
.collect::<Result<Vec<InscriptionId>>>()
}

pub(crate) fn get_runes_in_block(&self, block_height: u32) -> Result<Vec<RuneEntry>> {
let rtx = self.database.begin_read()?;

let rune_id_to_rune_entry = rtx.open_table(RUNE_ID_TO_RUNE_ENTRY)?;

let min_id = RuneId {
block: u64::from(block_height),
tx: 0,
};

let max_id = RuneId {
block: u64::from(block_height + 1),
tx: 0,
};

let runes = rune_id_to_rune_entry
.range(min_id.store()..max_id.store())?
lugondev marked this conversation as resolved.
Show resolved Hide resolved
.map(|result| result.map(|(_, entry)| RuneEntry::load(entry.value())))
.collect::<Result<Vec<RuneEntry>, StorageError>>()?;

Ok(runes)
}

pub(crate) fn get_highest_paying_inscriptions_in_block(
&self,
block_height: u32,
Expand Down
3 changes: 3 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,15 @@ impl Server {
}
};

let runes = index.get_runes_in_block(height)?;
Ok(if accept_json {
let inscriptions = index.get_inscriptions_in_block(height)?;
Json(api::Block::new(
block,
Height(height),
Self::index_height(&index)?,
inscriptions,
runes,
))
.into_response()
} else {
Expand All @@ -831,6 +833,7 @@ impl Server {
Self::index_height(&index)?,
total_num,
featured_inscriptions,
runes,
)
.page(server_config)
.into_response()
Expand Down
7 changes: 7 additions & 0 deletions src/templates/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub(crate) struct BlockHtml {
height: Height,
inscription_count: usize,
featured_inscriptions: Vec<InscriptionId>,
runes: Vec<RuneEntry>,
}

impl BlockHtml {
Expand All @@ -18,6 +19,7 @@ impl BlockHtml {
best_height: Height,
inscription_count: usize,
featured_inscriptions: Vec<InscriptionId>,
runes: Vec<RuneEntry>,
) -> Self {
Self {
hash: block.header.block_hash(),
Expand All @@ -27,6 +29,7 @@ impl BlockHtml {
best_height,
inscription_count,
featured_inscriptions,
runes,
}
}
}
Expand All @@ -49,6 +52,7 @@ mod tests {
Height(0),
Height(0),
0,
Vec::new(),
Vec::new()
),
"
Expand All @@ -64,6 +68,7 @@ mod tests {
prev
next
.*
<h2>0 Runes</h2>
<h2>0 Inscriptions</h2>
<div class=thumbnails>
</div>
Expand All @@ -84,6 +89,7 @@ mod tests {
Height(0),
Height(1),
0,
Vec::new(),
Vec::new()
),
r"<h1>Block 0</h1>.*prev\s*<a class=next href=/block/1>next</a>.*"
Expand All @@ -98,6 +104,7 @@ mod tests {
Height(1),
Height(1),
0,
Vec::new(),
Vec::new()
),
r"<h1>Block 1</h1>.*<a class=prev href=/block/0>prev</a>\s*next.*",
Expand Down
8 changes: 8 additions & 0 deletions templates/block.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ <h1>Block {{ self.height }}</h1>
next
%% }
</div>
<h2>{{"Rune".tally(self.runes.len())}}</h2>
%% if self.runes.len() > 0 {
<ul>
%% for entry in &self.runes {
<li><a href=/rune/{{ entry.spaced_rune }}>{{ entry.spaced_rune }}</a></li>
lugondev marked this conversation as resolved.
Show resolved Hide resolved
%% }
</ul>
%% }
<h2>{{"Inscription".tally(self.inscription_count)}}</h2>
<div class=thumbnails>
%% for id in &self.featured_inscriptions {
Expand Down
1 change: 1 addition & 0 deletions tests/json_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ fn get_block() {
best_height: 1,
height: 0,
inscriptions: Vec::new(),
runes: Vec::new(),
}
);
}
Expand Down
Loading