Skip to content

Commit

Permalink
feat(applying): scaffolding for missing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicoLeberle committed Nov 23, 2023
1 parent ef3c638 commit 2b7ba9c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pallas-applying/src/byron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ pub fn validate_byron_tx(
prot_magic: &u32,
) -> ValidationResult {
let tx: &Tx = &mtxp.transaction;
let size: u64 = get_tx_size(tx)?;
let size: &u64 = &get_tx_size(tx)?;
check_ins_not_empty(tx)?;
check_outs_not_empty(tx)?;
check_ins_in_utxos(tx, utxos)?;
check_outs_have_lovelace(tx)?;
check_fees(tx, &size, utxos, prot_pps)?;
check_size(&size, prot_pps)?;
check_fees(tx, size, utxos, prot_pps)?;
check_size(size, prot_pps)?;
check_witnesses(mtxp, utxos, prot_magic)
}

Expand Down
49 changes: 45 additions & 4 deletions pallas-applying/src/shelley.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
//! Utilities required for Shelley-era transaction validation.
use crate::types::{
ShelleyError::*, ShelleyProtParams, UTxOs, ValidationError::*, ValidationResult,
ShelleyError::*,
ShelleyProtParams, UTxOs,
ValidationError::{self, *},
ValidationResult,
};
use pallas_addresses::{Address, ShelleyAddress};
use pallas_primitives::alonzo::{MintedTx, TransactionBody};
use pallas_primitives::alonzo::{MintedTx, MintedWitnessSet, TransactionBody};
use pallas_traverse::MultiEraInput;

// TODO: implement each of the validation rules.
pub fn validate_shelley_tx(
mtx: &MintedTx,
utxos: &UTxOs,
_prot_pps: &ShelleyProtParams,
prot_pps: &ShelleyProtParams,
_prot_magic: &u32,
block_slot: &u64,
network_id: &u8,
) -> ValidationResult {
let tx_body: &TransactionBody = &mtx.transaction_body;
let tx_wits: &MintedWitnessSet = &mtx.transaction_witness_set;
let size: &u64 = &get_tx_size(tx_body)?;
check_ins_not_empty(tx_body)?;
check_ins_in_utxos(tx_body, utxos)?;
check_ttl(tx_body, block_slot)?;
check_network_id(tx_body, network_id)
check_size(size, prot_pps)?;
check_min_lovelace(tx_body, prot_pps)?;
check_preservation_of_value(tx_body, utxos, prot_pps)?;
check_fees(tx_body, prot_pps)?;
check_network_id(tx_body, network_id)?;
check_witnesses(tx_body, tx_wits)
}

fn get_tx_size(_tx_body: &TransactionBody) -> Result<u64, ValidationError> {
Ok(0)
}

fn check_ins_not_empty(tx_body: &TransactionBody) -> ValidationResult {
Expand Down Expand Up @@ -52,6 +66,29 @@ fn check_ttl(tx_body: &TransactionBody, block_slot: &u64) -> ValidationResult {
}
}

fn check_size(_size: &u64, _prot_pps: &ShelleyProtParams) -> ValidationResult {
Ok(())
}

fn check_min_lovelace(
_tx_body: &TransactionBody,
_prot_pps: &ShelleyProtParams,
) -> ValidationResult {
Ok(())
}

fn check_preservation_of_value(
_tx_body: &TransactionBody,
_utxos: &UTxOs,
_prot_pps: &ShelleyProtParams,
) -> ValidationResult {
Ok(())
}

fn check_fees(_tx_body: &TransactionBody, _prot_pps: &ShelleyProtParams) -> ValidationResult {
Ok(())
}

fn check_network_id(tx_body: &TransactionBody, network_id: &u8) -> ValidationResult {
for output in tx_body.outputs.iter() {
let addr: ShelleyAddress =
Expand All @@ -66,3 +103,7 @@ fn check_network_id(tx_body: &TransactionBody, network_id: &u8) -> ValidationRes
}
Ok(())
}

fn check_witnesses(_tx_body: &TransactionBody, _tx_wits: &MintedWitnessSet) -> ValidationResult {
Ok(())
}

0 comments on commit 2b7ba9c

Please sign in to comment.