Skip to content

Commit

Permalink
Merge pull request #91 from input-output-hk/fragment_validate
Browse files Browse the repository at this point in the history
Ledger apply TX clean up
  • Loading branch information
NicolasDP authored Sep 6, 2019
2 parents b7b266d + 5cdc4ca commit ae0a405
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 281 deletions.
56 changes: 56 additions & 0 deletions chain-impl-mockchain/src/ledger/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,59 @@ pub(super) fn valid_pool_update_certificate(
)?;
Ok(())
}

custom_error! {
#[derive(Clone, PartialEq, Eq)]
pub TxVerifyError
TooManyInputs {expected: usize, actual: usize }
= "too many inputs, expected maximum of {expected}, but received {actual}",
TooManyOutputs {expected: usize, actual: usize }
= "too many outputs, expected maximum of {expected}, but received {actual}",
TooManyWitnesses {expected: usize, actual: usize }
= "too many witnesses, expected maximum of {expected}, but received {actual}",
NumberOfSignaturesInvalid { expected: usize, actual: usize }
= "invalid number of signatures, expected {expected}, but received {actual}",
}

pub struct TxVerifyLimits {
pub max_inputs_count: usize,
pub max_outputs_count: usize,
pub max_witnesses_count: usize,
}

impl<OutAddress, Extra> AuthenticatedTransaction<OutAddress, Extra> {
pub fn verify_well_formed(&self, limits: &TxVerifyLimits) -> Result<(), TxVerifyError> {
let inputs = &self.transaction.inputs;
if inputs.len() > limits.max_inputs_count {
return Err(TxVerifyError::TooManyInputs {
expected: limits.max_inputs_count,
actual: inputs.len(),
});
}

let outputs = &self.transaction.outputs;
if outputs.len() > limits.max_outputs_count {
return Err(TxVerifyError::TooManyOutputs {
expected: limits.max_outputs_count,
actual: outputs.len(),
});
}

let witnesses = &self.witnesses;
if witnesses.len() > limits.max_witnesses_count {
return Err(TxVerifyError::TooManyWitnesses {
expected: limits.max_witnesses_count,
actual: witnesses.len(),
});
}

if inputs.len() != witnesses.len() {
return Err(TxVerifyError::NumberOfSignaturesInvalid {
expected: inputs.len(),
actual: witnesses.len(),
});
}

Ok(())
}
}
Loading

0 comments on commit ae0a405

Please sign in to comment.