Skip to content

Commit

Permalink
Allow empty query parameters on /satscard route (#4238)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Feb 22, 2025
1 parent 7d30613 commit 0235b18
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/ordinals/src/rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Rune {
pub fn reserved(block: u64, tx: u32) -> Self {
Self(
Self::RESERVED
.checked_add(u128::from(block) << 32 | u128::from(tx))
.checked_add((u128::from(block) << 32) | u128::from(tx))
.unwrap(),
)
}
Expand Down Expand Up @@ -416,7 +416,7 @@ mod tests {
assert_eq!(Rune::reserved(1, 1), Rune(Rune::RESERVED + (1 << 32) + 1));
assert_eq!(
Rune::reserved(u64::MAX, u32::MAX),
Rune(Rune::RESERVED + (u128::from(u64::MAX) << 32 | u128::from(u32::MAX))),
Rune(Rune::RESERVED + ((u128::from(u64::MAX) << 32) | u128::from(u32::MAX))),
);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ordinals/src/spaced_rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Display for SpacedRune {
for (i, c) in rune.chars().enumerate() {
write!(f, "{c}")?;

if i < rune.len() - 1 && self.spacers & 1 << i != 0 {
if i < rune.len() - 1 && self.spacers & (1 << i) != 0 {
write!(f, "•")?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ordinals/src/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod tests {
let mut n = 0;

for i in 0..129 {
n = n << 1 | (i % 2);
n = (n << 1) | (i % 2);
let encoded = encode(n);
let (decoded, length) = decode(&encoded).unwrap();
assert_eq!(decoded, n);
Expand Down
2 changes: 1 addition & 1 deletion src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl Entry for SatRange {
fn store(self) -> Self::Value {
let base = self.0;
let delta = self.1 - self.0;
let n = u128::from(base) | u128::from(delta) << 51;
let n = u128::from(base) | (u128::from(delta) << 51);
n.to_le_bytes()[0..11].try_into().unwrap()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl InscriptionUpdater<'_, '_> {
// still have to normalize over inscription size
for flotsam in &mut floating_inscriptions {
if let Flotsam {
origin: Origin::New { ref mut fee, .. },
origin: Origin::New { fee, .. },
..
} = flotsam
{
Expand Down
10 changes: 9 additions & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl Server {
};
}

let satscard = if let Some(query) = uri.query() {
let satscard = if let Some(query) = uri.query().filter(|query| !query.is_empty()) {
let satscard = Satscard::from_query_parameters(settings.chain(), query).map_err(|err| {
ServerError::BadRequest(format!("invalid satscard query parameters: {err}"))
})?;
Expand Down Expand Up @@ -7448,6 +7448,14 @@ next
);
}

#[test]
fn satscard_empty_query_parameters_are_allowed() {
TestServer::builder()
.chain(Chain::Mainnet)
.build()
.assert_html("/satscard?", SatscardHtml { satscard: None });
}

#[test]
fn satscard_display_without_address_index() {
TestServer::builder()
Expand Down

0 comments on commit 0235b18

Please sign in to comment.