feat(applying): check non-empty set of inputs and outputs (#312)
This commit is contained in:
parent
bf973dff3c
commit
2dca64c4c9
4 changed files with 111 additions and 34 deletions
|
|
@ -1,14 +1,30 @@
|
|||
//! Utilities required for Byron-era transaction validation.
|
||||
|
||||
use crate::types::{ByronProtParams, UTxOs, ValidationResult};
|
||||
use crate::types::{ByronProtParams, UTxOs, ValidationError, ValidationResult};
|
||||
|
||||
use pallas_primitives::byron::MintedTxPayload;
|
||||
use pallas_primitives::byron::{MintedTxPayload, Tx};
|
||||
|
||||
// TODO: implement each of the validation rules.
|
||||
// TODO: implement missing validation rules.
|
||||
pub fn validate_byron_tx(
|
||||
_mtxp: &MintedTxPayload,
|
||||
mtxp: &MintedTxPayload,
|
||||
_utxos: &UTxOs,
|
||||
_prot_pps: &ByronProtParams,
|
||||
) -> ValidationResult {
|
||||
let tx: &Tx = &mtxp.transaction;
|
||||
check_ins_not_empty(tx)?;
|
||||
check_outs_not_empty(tx)
|
||||
}
|
||||
|
||||
fn check_ins_not_empty(tx: &Tx) -> ValidationResult {
|
||||
if tx.inputs.clone().to_vec().is_empty() {
|
||||
return Err(ValidationError::TxInsEmpty);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_outs_not_empty(tx: &Tx) -> ValidationResult {
|
||||
if tx.outputs.clone().to_vec().is_empty() {
|
||||
return Err(ValidationError::TxOutsEmpty);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ pub enum MultiEraProtParams<'b> {
|
|||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum ValidationError {
|
||||
ValidationError,
|
||||
TxInsEmpty,
|
||||
TxOutsEmpty,
|
||||
}
|
||||
|
||||
pub type ValidationResult = Result<(), ValidationError>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue