feat: scaffold Byron phase-1 validations (#300)

Co-authored-by: Santiago Carmuega <santiago@carmuega.me>
This commit is contained in:
Maico Leberle 2023-10-10 17:16:26 -03:00 committed by GitHub
parent cdcb679921
commit 5391a037d6
14 changed files with 306 additions and 19 deletions

View file

@ -0,0 +1,14 @@
//! Utilities required for Byron-era transaction validation.
use crate::types::{ByronProtParams, UTxOs, ValidationResult};
use pallas_primitives::byron::MintedTxPayload;
// TODO: implement each of the validation rules.
pub fn validate_byron_tx(
_mtxp: &MintedTxPayload,
_utxos: &UTxOs,
_prot_pps: &ByronProtParams,
) -> ValidationResult {
Ok(())
}

View file

@ -0,0 +1,24 @@
//! Logic for validating and applying new blocks and txs to the chain state
pub mod byron;
pub mod types;
use byron::validate_byron_tx;
use pallas_traverse::{MultiEraTx, MultiEraTx::Byron as ByronTxPayload};
pub use types::{
MultiEraProtParams, MultiEraProtParams::Byron as ByronProtParams, UTxOs, ValidationResult,
};
pub fn validate(
metx: &MultiEraTx,
utxos: &UTxOs,
prot_pps: &MultiEraProtParams,
) -> ValidationResult {
match (metx, prot_pps) {
(ByronTxPayload(mtxp), ByronProtParams(bpp)) => validate_byron_tx(mtxp, utxos, bpp),
// TODO: implement the rest of the eras.
_ => Ok(()),
}
}

View file

@ -0,0 +1,27 @@
//! Base types used for validating transactions in each era.
use std::{borrow::Cow, collections::HashMap};
pub use pallas_traverse::{MultiEraInput, MultiEraOutput};
pub type UTxOs<'b> = HashMap<MultiEraInput<'b>, MultiEraOutput<'b>>;
// TODO: add a field for each protocol parameter in the Byron era.
#[derive(Debug, Clone)]
pub struct ByronProtParams;
// TODO: add variants for the other eras.
#[derive(Debug)]
#[non_exhaustive]
pub enum MultiEraProtParams<'b> {
Byron(Box<Cow<'b, ByronProtParams>>),
}
// TODO: replace this generic variant with validation-rule-specific ones.
#[derive(Debug)]
#[non_exhaustive]
pub enum ValidationError {
ValidationError,
}
pub type ValidationResult = Result<(), ValidationError>;