feat: scaffold Byron phase-1 validations (#300)
Co-authored-by: Santiago Carmuega <santiago@carmuega.me>
This commit is contained in:
parent
cdcb679921
commit
5391a037d6
14 changed files with 306 additions and 19 deletions
14
pallas-applying/src/byron.rs
Normal file
14
pallas-applying/src/byron.rs
Normal 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(())
|
||||
}
|
||||
24
pallas-applying/src/lib.rs
Normal file
24
pallas-applying/src/lib.rs
Normal 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(()),
|
||||
}
|
||||
}
|
||||
27
pallas-applying/src/types.rs
Normal file
27
pallas-applying/src/types.rs
Normal 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>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue