mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-10 00:16:02 +01:00
feat: add unbalanced check
This commit is contained in:
@@ -26,6 +26,9 @@ pub enum Error {
|
||||
/// Not engough inputs provided
|
||||
#[error("Inputs: `{0}`, Outputs: `{0}`, Fee: `{0}`")]
|
||||
InsufficientInputs(u64, u64, u64),
|
||||
/// Transaction unbalanced
|
||||
#[error("Inputs: `{0}`, Outputs: `{0}`, Fee: `{0}`")]
|
||||
TransactionUnbalanced(u64, u64, u64),
|
||||
/// Duplicate proofs provided
|
||||
#[error("Duplicate proofs")]
|
||||
DuplicateProofs,
|
||||
|
||||
@@ -711,7 +711,9 @@ impl Mint {
|
||||
|
||||
let fee = self.get_proofs_fee(&swap_request.inputs).await?;
|
||||
|
||||
if proofs_total < output_total.checked_add(fee).ok_or(Error::AmountOverflow)? {
|
||||
let total_with_fee = output_total.checked_add(fee).ok_or(Error::AmountOverflow)?;
|
||||
|
||||
if proofs_total < total_with_fee {
|
||||
tracing::info!(
|
||||
"Swap request without enough inputs: {}, outputs {}, fee {}",
|
||||
proofs_total,
|
||||
@@ -725,6 +727,20 @@ impl Mint {
|
||||
));
|
||||
}
|
||||
|
||||
if proofs_total != total_with_fee {
|
||||
tracing::info!(
|
||||
"Swap request unbalanced: {}, outputs {}, fee {}",
|
||||
proofs_total,
|
||||
output_total,
|
||||
fee
|
||||
);
|
||||
return Err(Error::InsufficientInputs(
|
||||
proofs_total.into(),
|
||||
output_total.into(),
|
||||
fee.into(),
|
||||
));
|
||||
}
|
||||
|
||||
let proof_count = swap_request.inputs.len();
|
||||
|
||||
let input_ys = swap_request
|
||||
|
||||
Reference in New Issue
Block a user