Skip to content

Commit

Permalink
Address runes review comments (ordinals#3605)
Browse files Browse the repository at this point in the history
- Use inclusive range in Index::get_runes_in_block
- Remove out-of-date comment
- Use checked_pow in Decimal Display impl
- Use checked_pow in impl FromStr for Decimal
  • Loading branch information
casey committed Apr 18, 2024
1 parent 3d969a6 commit 879cee6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Decimal {

impl Display for Decimal {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let magnitude = 10u128.pow(self.scale.into());
let magnitude = 10u128.checked_pow(self.scale.into()).ok_or(fmt::Error)?;

let integer = self.value / magnitude;
let mut fraction = self.value % magnitude;
Expand Down Expand Up @@ -68,7 +68,10 @@ impl FromStr for Decimal {
} else {
let trailing_zeros = decimal.chars().rev().take_while(|c| *c == '0').count();
let significant_digits = decimal.chars().count() - trailing_zeros;
let decimal = decimal.parse::<u128>()? / 10u128.pow(u32::try_from(trailing_zeros).unwrap());
let decimal = decimal.parse::<u128>()?
/ 10u128
.checked_pow(u32::try_from(trailing_zeros).unwrap())
.context("excessive trailing zeros")?;
(decimal, u8::try_from(significant_digits).unwrap())
};

Expand Down
6 changes: 3 additions & 3 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,12 +1782,12 @@ impl Index {
};

let max_id = RuneId {
block: block_height + 1,
tx: 0,
block: block_height,
tx: u32::MAX,
};

let runes = rune_id_to_rune_entry
.range(min_id.store()..max_id.store())?
.range(min_id.store()..=max_id.store())?
.map(|result| result.map(|(_, entry)| RuneEntry::load(entry.value()).spaced_rune))
.collect::<Result<Vec<SpacedRune>, StorageError>>()?;

Expand Down
3 changes: 1 addition & 2 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> {
.unwrap_or_default();

// assign all un-allocated runes to the default output, or the first non
// OP_RETURN output if there is no default, or if the default output is
// too large
// OP_RETURN output if there is no default
if let Some(vout) = pointer
.map(|pointer| pointer.into_usize())
.inspect(|&pointer| assert!(pointer < allocated.len()))
Expand Down

0 comments on commit 879cee6

Please sign in to comment.