Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lisicky committed Oct 24, 2023
1 parent 7b8bce8 commit 641db4e
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 182 deletions.
33 changes: 18 additions & 15 deletions src/filters/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,35 +157,38 @@ fn metadata_any_sub_label_matches(event: &Event, sub_label: &str) -> bool {
fn vkey_witnesses_matches(event: &Event, witness: &str) -> bool {
match &event.data {
EventData::VKeyWitness(x) => x.vkey_hex == witness,
EventData::Transaction(x) =>
x.vkey_witnesses.as_ref()
.map(|vs| vs.iter().any(|v| v.vkey_hex == witness))
.unwrap_or(false),
_ => false
EventData::Transaction(x) => x
.vkey_witnesses
.as_ref()
.map(|vs| vs.iter().any(|v| v.vkey_hex == witness))
.unwrap_or(false),
_ => false,
}
}

#[inline]
fn native_scripts_matches(event: &Event, policy_id: &str) -> bool {
match &event.data {
EventData::NativeWitness(x) => x.policy_id == policy_id,
EventData::Transaction(x) =>
x.native_witnesses.as_ref()
.map(|vs| vs.iter().any(|v| v.policy_id == policy_id))
.unwrap_or(false),
_ => false
EventData::Transaction(x) => x
.native_witnesses
.as_ref()
.map(|vs| vs.iter().any(|v| v.policy_id == policy_id))
.unwrap_or(false),
_ => false,
}
}

#[inline]
fn plutus_scripts_matches(event: &Event, script_hash: &str) -> bool {
match &event.data {
EventData::PlutusWitness(x) => x.script_hash == script_hash,
EventData::Transaction(x) =>
x.plutus_witnesses.as_ref()
.map(|vs| vs.iter().any(|v| v.script_hash == script_hash))
.unwrap_or(false),
_ => false
EventData::Transaction(x) => x
.plutus_witnesses
.as_ref()
.map(|vs| vs.iter().any(|v| v.script_hash == script_hash))
.unwrap_or(false),
_ => false,
}
}

Expand Down
45 changes: 33 additions & 12 deletions src/mapper/babbage.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
use std::collections::HashMap;
use pallas::codec::utils::KeepRaw;
use std::collections::HashMap;

use pallas::ledger::primitives::babbage::{AuxiliaryData, CostMdls, Language, MintedBlock, MintedDatumOption, MintedPostAlonzoTransactionOutput, MintedTransactionBody, MintedTransactionOutput, MintedWitnessSet, NetworkId, ProtocolParamUpdate, Update};
use pallas::ledger::primitives::babbage::{
AuxiliaryData, CostMdls, Language, MintedBlock, MintedDatumOption,
MintedPostAlonzoTransactionOutput, MintedTransactionBody, MintedTransactionOutput,
MintedWitnessSet, NetworkId, ProtocolParamUpdate, Update,
};

use pallas::crypto::hash::Hash;
use pallas::ledger::traverse::OriginalHash;
use serde_json::json;

use crate::model::{BlockRecord, CostModelRecord, CostModelsRecord, Era, LanguageVersionRecord, ProtocolParamUpdateRecord, TransactionRecord, UpdateRecord};
use crate::model::{
BlockRecord, CostModelRecord, CostModelsRecord, Era, LanguageVersionRecord,
ProtocolParamUpdateRecord, TransactionRecord, UpdateRecord,
};
use crate::utils::time::TimeProvider;
use crate::{
model::{EventContext, EventData},
Expand Down Expand Up @@ -383,7 +390,10 @@ impl EventWriter {
Ok(())
}

pub fn to_babbage_cost_models_record(&self, cost_models: &Option<CostMdls>) -> Option<CostModelsRecord> {
pub fn to_babbage_cost_models_record(
&self,
cost_models: &Option<CostMdls>,
) -> Option<CostModelsRecord> {
match cost_models {
Some(cost_models) => {
let mut cost_models_record = HashMap::new();
Expand All @@ -399,19 +409,25 @@ impl EventWriter {
}

Some(CostModelsRecord(cost_models_record))
},
}
None => None,
}
}

pub fn to_babbage_language_version_record(&self, language_version: &Language) -> LanguageVersionRecord {
pub fn to_babbage_language_version_record(
&self,
language_version: &Language,
) -> LanguageVersionRecord {
match language_version {
Language::PlutusV1 => LanguageVersionRecord::PlutusV1,
Language::PlutusV2 => LanguageVersionRecord::PlutusV2,
}
}

pub fn to_babbage_protocol_update_record(&self, update: &ProtocolParamUpdate) -> ProtocolParamUpdateRecord {
pub fn to_babbage_protocol_update_record(
&self,
update: &ProtocolParamUpdate,
) -> ProtocolParamUpdateRecord {
ProtocolParamUpdateRecord {
minfee_a: update.minfee_a,
minfee_b: update.minfee_b,
Expand All @@ -422,18 +438,20 @@ impl EventWriter {
pool_deposit: update.pool_deposit,
maximum_epoch: update.maximum_epoch,
desired_number_of_stake_pools: update.desired_number_of_stake_pools,
pool_pledge_influence: self.to_rational_number_record_option(&update.pool_pledge_influence),
pool_pledge_influence: self
.to_rational_number_record_option(&update.pool_pledge_influence),
expansion_rate: self.to_unit_interval_record(&update.expansion_rate),
treasury_growth_rate: self.to_unit_interval_record(&update.treasury_growth_rate),
decentralization_constant: None,
extra_entropy: None,
protocol_version: update.protocol_version,
min_pool_cost: update.min_pool_cost,
ada_per_utxo_byte: update.ada_per_utxo_byte,
cost_models_for_script_languages: self.to_babbage_cost_models_record(&update.cost_models_for_script_languages),
cost_models_for_script_languages: self
.to_babbage_cost_models_record(&update.cost_models_for_script_languages),
execution_costs: match &update.execution_costs {

Check failure on line 452 in src/mapper/babbage.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

manual implementation of `Option::map`
Some(execution_costs) => Some(json!(execution_costs)),
None => None
None => None,
},
max_tx_ex_units: self.to_ex_units_record(&update.max_tx_ex_units),
max_block_ex_units: self.to_ex_units_record(&update.max_block_ex_units),
Expand All @@ -446,10 +464,13 @@ impl EventWriter {
pub fn to_babbage_update_record(&self, update: &Update) -> UpdateRecord {
let mut updates = HashMap::new();
for update in update.proposed_protocol_parameter_updates.clone().to_vec() {
updates.insert(update.0.to_hex(), self.to_babbage_protocol_update_record(&update.1));
updates.insert(
update.0.to_hex(),
self.to_babbage_protocol_update_record(&update.1),
);
}

UpdateRecord{
UpdateRecord {
proposed_protocol_parameter_updates: updates,
epoch: update.epoch,
}
Expand Down
9 changes: 6 additions & 3 deletions src/mapper/collect.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pallas::ledger::primitives::alonzo::{Certificate, RequiredSigners};
use pallas::{
codec::utils::{KeepRaw, KeyValuePairs, MaybeIndefArray},
ledger::{
Expand All @@ -14,8 +15,8 @@ use pallas::{
traverse::OriginalHash,
},
};
use pallas::ledger::primitives::alonzo::{Certificate, RequiredSigners};

use crate::model::{CertificateRecord, RequiredSignerRecord};
use crate::{
model::{
MetadataRecord, MintRecord, NativeWitnessRecord, OutputAssetRecord, PlutusDatumRecord,
Expand All @@ -24,7 +25,6 @@ use crate::{
},
Error,
};
use crate::model::{CertificateRecord, RequiredSignerRecord};

use super::{map::ToHex, EventWriter};

Expand Down Expand Up @@ -234,7 +234,10 @@ impl EventWriter {
.collect()
}

pub fn collect_required_signers_records(&self, req_signers: &RequiredSigners) -> Result<Vec<RequiredSignerRecord>, Error> {
pub fn collect_required_signers_records(
&self,
req_signers: &RequiredSigners,
) -> Result<Vec<RequiredSignerRecord>, Error> {
let mut signers = vec![];
for req_sign in req_signers {
let hex = req_sign.to_hex();
Expand Down
Loading

0 comments on commit 641db4e

Please sign in to comment.