From eaf0cef4b0f32b57ad41e73eeff587539627c4f7 Mon Sep 17 00:00:00 2001 From: Maico Date: Wed, 13 Dec 2023 14:20:55 -0300 Subject: [PATCH] fix: Rust (clippy) linting errors --- src/sync/ledger.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/sync/ledger.rs b/src/sync/ledger.rs index 069ab0ba..3eb0f5c5 100644 --- a/src/sync/ledger.rs +++ b/src/sync/ledger.rs @@ -10,6 +10,45 @@ use tracing::{debug, info, warn}; use crate::prelude::*; use crate::storage::applydb::ApplyDB; +pub fn execute_phase1_validation( + ledger: &ApplyDB, + block: &MultiEraBlock<'_>, +) -> Result<(), WorkerError> { + let mut utxos = HashMap::new(); + ledger + .resolve_inputs_for_block(block, &mut utxos) + .or_panic()?; + + let mut utxos2 = UTxOs::new(); + + for (ref_, output) in utxos.iter() { + let txin = pallas::ledger::primitives::byron::TxIn::Variant0( + pallas::codec::utils::CborWrap((ref_.0, ref_.1 as u32)), + ); + + let key = MultiEraInput::Byron( + >>::from(Cow::Owned(txin)), + ); + + let era = Era::try_from(output.0).or_panic()?; + let value = MultiEraOutput::decode(era, &output.1).or_panic()?; + + utxos2.insert(key, value); + } + + let env = ledger.get_active_pparams(block.slot()).or_panic()?; + + for tx in block.txs().iter() { + let res = validate(tx, &utxos2, &env); + + if let Err(err) = res { + warn!(?err, "validation error"); + } + } + + Ok(()) +} + pub type UpstreamPort = gasket::messaging::tokio::InputPort; #[derive(Stage)]