Skip to content

Commit

Permalink
Fix slice error for inscriptions block view (ordinals#2378)
Browse files Browse the repository at this point in the history
  • Loading branch information
veryordinally authored Aug 27, 2023
1 parent c458791 commit 7a6d8b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/index/block_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ impl BlockIndex {
index: &Index,
block_height: u64,
) -> Result<Vec<InscriptionId>> {
if index.block_count()?
> self.lowest_blessed_by_block.len() as u64 + self.first_inscription_height
{
return Err(anyhow!(
"Block index not fully indexed ({} indexed of {})",
self.lowest_blessed_by_block.len() as u64 + self.first_inscription_height,
index.block_count()?
));
}
if block_height >= index.block_count()? || block_height < self.first_inscription_height {
return Ok(Vec::new());
}
Expand Down
11 changes: 8 additions & 3 deletions src/templates/inscriptions_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ impl InscriptionsBlockHtml {
inscriptions: Vec<InscriptionId>,
page_index: usize,
) -> Result<Self> {
let start = page_index * 100;
let end = start + 100;
let num_inscriptions = inscriptions.len();

let start = page_index * 100;
let end = usize::min(start + 100, num_inscriptions);

if start > num_inscriptions || start > end {
return Err(anyhow!("page index {page_index} exceeds inscription count"));
}
let inscriptions = inscriptions[start..end].to_vec();

Ok(Self {
Expand All @@ -36,7 +41,7 @@ impl InscriptionsBlockHtml {
} else {
None
},
next_page: if page_index * 100 <= num_inscriptions {
next_page: if (page_index + 1) * 100 <= num_inscriptions {
Some(page_index + 1)
} else {
None
Expand Down

0 comments on commit 7a6d8b7

Please sign in to comment.