mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-12 14:09:25 +00:00
Remove potentially-failing unchecked arithmetic operations for ones which error
In response to 9.13.3. Requires a bump to Rust 1.82 to take advantage of `Option::is_none_or`.
This commit is contained in:
@@ -18,7 +18,7 @@ use crate::{
|
||||
};
|
||||
|
||||
const RECENT_WINDOW: u64 = 15;
|
||||
const BLOCKS_PER_YEAR: usize = 365 * 24 * 60 * 60 / BLOCK_TIME;
|
||||
const BLOCKS_PER_YEAR: usize = (365 * 24 * 60 * 60) / BLOCK_TIME;
|
||||
#[allow(clippy::cast_precision_loss)]
|
||||
const TIP_APPLICATION: f64 = (DEFAULT_LOCK_WINDOW * BLOCK_TIME) as f64;
|
||||
|
||||
|
||||
@@ -232,7 +232,13 @@ impl InternalScanner {
|
||||
|
||||
res.push(WalletOutput {
|
||||
absolute_id: AbsoluteId { transaction: tx_hash, index_in_transaction: o },
|
||||
relative_id: RelativeId { index_on_blockchain: output_index_for_first_ringct_output + o },
|
||||
relative_id: RelativeId {
|
||||
index_on_blockchain: output_index_for_first_ringct_output.checked_add(o).ok_or(
|
||||
ScanError::InvalidScannableBlock(
|
||||
"transaction's output's index isn't representable as a u64",
|
||||
),
|
||||
)?,
|
||||
},
|
||||
data: OutputData { key: output_key, key_offset, commitment },
|
||||
metadata: Metadata {
|
||||
additional_timelock: tx.prefix().additional_timelock,
|
||||
|
||||
@@ -305,12 +305,13 @@ impl SignableTransaction {
|
||||
.payments
|
||||
.iter()
|
||||
.filter_map(|payment| match payment {
|
||||
InternalPayment::Payment(_, amount) => Some(amount),
|
||||
InternalPayment::Payment(_, amount) => Some(*amount),
|
||||
InternalPayment::Change(_) => None,
|
||||
})
|
||||
.sum::<u64>();
|
||||
.try_fold(0, u64::checked_add);
|
||||
let payments_amount = payments_amount.ok_or(SendError::TooManyOutputs)?;
|
||||
let (weight, necessary_fee) = self.weight_and_necessary_fee();
|
||||
if in_amount < (payments_amount + necessary_fee) {
|
||||
if payments_amount.checked_add(necessary_fee).is_none_or(|total_out| in_amount < total_out) {
|
||||
Err(SendError::NotEnoughFunds {
|
||||
inputs: in_amount,
|
||||
outputs: payments_amount,
|
||||
|
||||
Reference in New Issue
Block a user