diff --git a/src/decimal.rs b/src/decimal.rs index 21a8c63508..91cb86b6ee 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -7,7 +7,7 @@ pub struct Decimal { } impl Decimal { - pub fn to_amount(self, divisibility: u8) -> Result { + pub fn to_integer(self, divisibility: u8) -> Result { match divisibility.checked_sub(self.scale) { Some(difference) => Ok( self @@ -128,7 +128,7 @@ mod tests { assert_eq!( s.parse::() .unwrap() - .to_amount(divisibility) + .to_integer(divisibility) .unwrap(), amount, ); @@ -136,7 +136,7 @@ mod tests { assert_eq!( Decimal { value: 0, scale: 0 } - .to_amount(255) + .to_integer(255) .unwrap_err() .to_string(), "divisibility out of range" @@ -147,7 +147,7 @@ mod tests { value: u128::MAX, scale: 0, } - .to_amount(1) + .to_integer(1) .unwrap_err() .to_string(), "amount out of range", @@ -155,7 +155,7 @@ mod tests { assert_eq!( Decimal { value: 1, scale: 1 } - .to_amount(0) + .to_integer(0) .unwrap_err() .to_string(), "excessive precision", diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index 779dc4940f..b963bac0ea 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -235,16 +235,16 @@ impl Inscribe { "rune `{rune}` has already been etched", ); - let premine = etching.premine.to_amount(etching.divisibility)?; + let premine = etching.premine.to_integer(etching.divisibility)?; - let supply = etching.supply.to_amount(etching.divisibility)?; + let supply = etching.supply.to_integer(etching.divisibility)?; let mintable = etching .terms .map(|terms| -> Result { terms .cap - .checked_mul(terms.amount.to_amount(etching.divisibility)?) + .checked_mul(terms.amount.to_integer(etching.divisibility)?) .ok_or_else(|| anyhow!("`terms.count` * `terms.amount` over maximum")) }) .transpose()? @@ -295,10 +295,10 @@ impl Inscribe { ); } - ensure!(terms.cap > 0, "`terms.cap` must be greater than zero",); + ensure!(terms.cap > 0, "`terms.cap` must be greater than zero"); ensure!( - terms.amount.to_amount(etching.divisibility)? > 0, + terms.amount.to_integer(etching.divisibility)? > 0, "`terms.amount` must be greater than zero", ); } diff --git a/src/subcommand/wallet/send.rs b/src/subcommand/wallet/send.rs index 728c5a2902..d0cdcd64a8 100644 --- a/src/subcommand/wallet/send.rs +++ b/src/subcommand/wallet/send.rs @@ -231,7 +231,7 @@ impl Send { .get_rune(spaced_rune.rune)? .with_context(|| format!("rune `{}` has not been etched", spaced_rune.rune))?; - let amount = decimal.to_amount(entry.divisibility)?; + let amount = decimal.to_integer(entry.divisibility)?; let inscribed_outputs = inscriptions .keys() diff --git a/src/wallet/batch/plan.rs b/src/wallet/batch/plan.rs index 990cc17105..680ebd3d1f 100644 --- a/src/wallet/batch/plan.rs +++ b/src/wallet/batch/plan.rs @@ -433,7 +433,7 @@ impl Plan { let vout; let destination; - premine = etching.premine.to_amount(etching.divisibility)?; + premine = etching.premine.to_integer(etching.divisibility)?; if premine > 0 { let output = u32::try_from(reveal_outputs.len()).unwrap(); @@ -470,7 +470,7 @@ impl Plan { terms.height.and_then(|range| (range.start)), terms.height.and_then(|range| (range.end)), ), - amount: Some(terms.amount.to_amount(etching.divisibility)?), + amount: Some(terms.amount.to_integer(etching.divisibility)?), offset: ( terms.offset.and_then(|range| (range.start)), terms.offset.and_then(|range| (range.end)), diff --git a/tests/lib.rs b/tests/lib.rs index 2e3f833df6..92d60e0a76 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -257,11 +257,11 @@ fn batch( } = batchfile.etching.unwrap(); { - let supply = supply.to_amount(divisibility).unwrap(); - let premine = premine.to_amount(divisibility).unwrap(); + let supply = supply.to_integer(divisibility).unwrap(); + let premine = premine.to_integer(divisibility).unwrap(); let mintable = terms - .map(|terms| terms.cap * terms.amount.to_amount(divisibility).unwrap()) + .map(|terms| terms.cap * terms.amount.to_integer(divisibility).unwrap()) .unwrap_or_default(); assert_eq!(supply, premine + mintable); @@ -324,7 +324,7 @@ fn batch( mint_definition.push(format!( "
{}
", Pile { - amount: terms.amount.to_amount(divisibility).unwrap(), + amount: terms.amount.to_integer(divisibility).unwrap(), divisibility, symbol: Some(symbol), } @@ -384,7 +384,7 @@ fn batch( rune, } = inscribe.rune.clone().unwrap(); - if premine.to_amount(divisibility).unwrap() > 0 { + if premine.to_integer(divisibility).unwrap() > 0 { let destination = destination .unwrap() .clone()