Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ordinals/ord into fix-batch-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Dec 5, 2023
2 parents 1b684f8 + d0ae915 commit 72a2e31
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
31 changes: 31 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ impl Server {
block_height,
index.block_height()?.unwrap_or(Height(0)).n(),
inscriptions,
more,
page_index,
)?
.page(page_config)
Expand Down Expand Up @@ -4760,4 +4761,34 @@ next
assert!(!children_json.more);
assert_eq!(children_json.page, 1);
}

#[test]
fn inscriptions_in_block_page() {
let server = TestServer::new_with_regtest_with_index_sats();

for _ in 0..101 {
server.mine_blocks(1);
}

for i in 0..101 {
server.bitcoin_rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(i + 1, 0, 0, inscription("text/foo", "hello").to_witness())],
..Default::default()
});
}

server.mine_blocks(1);

server.assert_response_regex(
"/inscriptions/block/102",
StatusCode::OK,
r".*(<a href=/inscription/[[:xdigit:]]{64}i0>.*</a>.*){100}.*",
);

server.assert_response_regex(
"/inscriptions/block/102/1",
StatusCode::OK,
r".*<a href=/inscription/[[:xdigit:]]{64}i0>.*</a>.*",
);
}
}
17 changes: 4 additions & 13 deletions src/templates/inscriptions_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ impl InscriptionsBlockHtml {
block: u32,
current_blockheight: u32,
inscriptions: Vec<InscriptionId>,
more_inscriptions: bool,
page_index: usize,
) -> Result<Self> {
let num_inscriptions = inscriptions.len();

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

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

Ok(Self {
block,
Expand All @@ -36,12 +31,8 @@ impl InscriptionsBlockHtml {
} else {
None
},
prev_page: if page_index > 0 {
Some(page_index - 1)
} else {
None
},
next_page: if (page_index + 1) * 100 <= num_inscriptions {
prev_page: page_index.checked_sub(1),
next_page: if more_inscriptions {
Some(page_index + 1)
} else {
None
Expand Down

0 comments on commit 72a2e31

Please sign in to comment.