From 305c5c562285b5a6b81e91eba18e72444481bd23 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Fri, 17 Jan 2025 23:46:59 -0300 Subject: [PATCH] chore: fix lint warnings (#582) --- examples/crawler/src/main.rs | 10 +- pallas-applying/src/babbage.rs | 11 ++- pallas-applying/src/conway.rs | 54 +++++------ pallas-applying/src/lib.rs | 4 +- pallas-applying/src/utils.rs | 155 ++++++++++++++++++++++--------- pallas-applying/tests/babbage.rs | 2 +- pallas-configs/src/shelley.rs | 26 +++--- pallas-utxorpc/src/lib.rs | 2 +- pallas-utxorpc/src/params.rs | 1 - 9 files changed, 169 insertions(+), 96 deletions(-) diff --git a/examples/crawler/src/main.rs b/examples/crawler/src/main.rs index 2e5d9ab7..2c02ca33 100644 --- a/examples/crawler/src/main.rs +++ b/examples/crawler/src/main.rs @@ -12,14 +12,14 @@ use pallas::{ // An arbitrary predicate to decide whether to save the block or not; // fill in with your own purpose built logic -async fn block_matches<'a>(block: &MultiEraBlock<'a>) -> bool { +async fn block_matches(block: &MultiEraBlock<'_>) -> bool { // As an example, we save any blocks that have an "Update proposal" in any era block.update().is_some() || block.txs().iter().any(|tx| tx.update().is_some()) } // An arbitrary predicate to decide whether to save the transaction or not; // fill in with your own purpose built logic -async fn tx_matches<'a>(_tx: &MultiEraTx<'a>) -> bool { +async fn tx_matches(_tx: &MultiEraTx<'_>) -> bool { false } @@ -41,7 +41,8 @@ async fn main() -> Result<()> { .await?; loop { - // We either request the next block, or wait until we're told that the block is ready + // We either request the next block, or wait until we're told that the block is + // ready let next = client.chainsync().request_or_await_next().await?; // And depending on the message we receive... match next { @@ -101,7 +102,8 @@ struct Args { /// The network magic used to handshake with that node; defaults to mainnet #[arg(short, long, env("CARDANO_NETWORK_MAGIC"), default_value_t = 764824073)] pub network_magic: u64, - /// A list of points to use when trying to decide a startpoint; defaults to origin + /// A list of points to use when trying to decide a startpoint; defaults to + /// origin #[arg(short, long, value_parser = parse_point)] pub point: Vec, /// Download only the first block found that matches this criteria diff --git a/pallas-applying/src/babbage.rs b/pallas-applying/src/babbage.rs index df7a9ff7..72b9be3b 100644 --- a/pallas-applying/src/babbage.rs +++ b/pallas-applying/src/babbage.rs @@ -5,9 +5,9 @@ use crate::utils::{ compute_plutus_v1_script_hash, compute_plutus_v2_script_hash, empty_value, get_babbage_tx_size, get_lovelace_from_alonzo_val, get_payment_part, get_shelley_address, get_val_size_in_words, is_byron_address, lovelace_diff_or_fail, mk_alonzo_vk_wits_check_list, values_are_equal, - verify_signature, + verify_signature, BabbageProtParams, PostAlonzoError::*, - BabbageProtParams, UTxOs, + UTxOs, ValidationError::{self, *}, ValidationResult, }; @@ -261,8 +261,11 @@ fn check_collaterals_assets( None => Value::Coin(0), }; // The balance between collateral inputs and output contains only lovelace. - let paid_collateral: u64 = - lovelace_diff_or_fail(&coll_input, &coll_return, &PostAlonzo(NonLovelaceCollateral))?; + let paid_collateral: u64 = lovelace_diff_or_fail( + &coll_input, + &coll_return, + &PostAlonzo(NonLovelaceCollateral), + )?; let fee_percentage: u64 = tx_body.fee * prot_pps.collateral_percentage as u64; // The balance is not lower than the minimum allowed. if paid_collateral * 100 < fee_percentage { diff --git a/pallas-applying/src/conway.rs b/pallas-applying/src/conway.rs index 4ffedc39..109a16cd 100644 --- a/pallas-applying/src/conway.rs +++ b/pallas-applying/src/conway.rs @@ -6,8 +6,9 @@ use crate::utils::{ conway_add_values, conway_get_val_size_in_words, conway_lovelace_diff_or_fail, conway_values_are_equal, get_conway_tx_size, get_lovelace_from_conway_val, get_payment_part, get_shelley_address, is_byron_address, mk_alonzo_vk_wits_check_list, verify_signature, + ConwayProtParams, PostAlonzoError::*, - ConwayProtParams, UTxOs, + UTxOs, ValidationError::{self, *}, ValidationResult, }; @@ -19,12 +20,12 @@ use pallas_codec::{ use pallas_primitives::{ babbage, conway::{ - Language, Mint, MintedTransactionBody, MintedTransactionOutput, MintedTx, - MintedWitnessSet, NativeScript, PseudoDatumOption, PseudoScript, PseudoTransactionOutput, - Redeemer, Redeemers, RedeemersKey, RequiredSigners, VKeyWitness, Value, + Language, Mint, MintedTransactionBody, MintedTransactionOutput, MintedTx, MintedWitnessSet, + NativeScript, PseudoDatumOption, PseudoScript, PseudoTransactionOutput, Redeemer, + Redeemers, RedeemersKey, RequiredSigners, VKeyWitness, Value, }, - AddrKeyhash, Hash, NonEmptyKeyValuePairs, PlutusData, PlutusScript, PolicyId, - PositiveCoin, TransactionInput, + AddrKeyhash, Hash, NonEmptyKeyValuePairs, PlutusData, PlutusScript, PolicyId, PositiveCoin, + TransactionInput, }; use pallas_traverse::{MultiEraInput, MultiEraOutput, OriginalHash}; use std::ops::Deref; @@ -166,17 +167,17 @@ fn check_min_fee( fn presence_of_plutus_scripts(mtx: &MintedTx) -> bool { let minted_witness_set: &MintedWitnessSet = &mtx.transaction_witness_set; - let plutus_v1_scripts: &[PlutusScript<1>] = &minted_witness_set + let plutus_v1_scripts: &[PlutusScript<1>] = minted_witness_set .plutus_v1_script .as_ref() .map(|x| x.as_slice()) .unwrap_or(&[]); - let plutus_v2_scripts: &[PlutusScript<2>] = &minted_witness_set + let plutus_v2_scripts: &[PlutusScript<2>] = minted_witness_set .plutus_v2_script .as_ref() .map(|x| x.as_slice()) .unwrap_or(&[]); - let plutus_v3_scripts: &[PlutusScript<3>] = &minted_witness_set + let plutus_v3_scripts: &[PlutusScript<3>] = minted_witness_set .plutus_v3_script .as_ref() .map(|x| x.as_slice()) @@ -395,7 +396,8 @@ fn get_produced(tx_body: &MintedTransactionBody) -> Result { - res = conway_add_values(&res, &Value::Coin(coin), &PostAlonzo(NegativeValue))? + res = + conway_add_values(&res, &Value::Coin(coin), &PostAlonzo(NegativeValue))? } babbage::Value::Multiasset(coin, assets) => { let mut conway_assets = Vec::new(); @@ -1699,11 +1701,9 @@ fn check_script_data_hash( } } } - }, - (None, None) => { - Err(PostAlonzo(ScriptIntegrityHash)) } - (Some(_), None) => Err(PostAlonzo(ScriptIntegrityHash)), + (None, None) => Err(PostAlonzo(ScriptIntegrityHash)), + (Some(_), None) => Err(PostAlonzo(ScriptIntegrityHash)), }, None => { let plutus_data = mtx @@ -1713,14 +1713,14 @@ fn check_script_data_hash( .map(|x| x.to_vec()); let redeemer_is_empty = mtx.transaction_witness_set.redeemer.is_none(); - if !redeemer_is_empty{ + if !redeemer_is_empty { if option_vec_is_empty(&plutus_data) { match &mtx - .transaction_witness_set - .redeemer - .clone() - .unwrap() - .unwrap() + .transaction_witness_set + .redeemer + .clone() + .unwrap() + .unwrap() { Redeemers::List(redeemers) => { if !option_vec_is_empty(&Some(redeemers.clone().to_vec())) { @@ -1737,7 +1737,7 @@ fn check_script_data_hash( } else { Err(PostAlonzo(ScriptIntegrityHash)) } - }else { + } else { Ok(()) } } @@ -1837,16 +1837,14 @@ fn cost_model_cbor( hex::decode( "a10198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a" ).unwrap() - } - else if !tx_languages.contains(&Language::PlutusV1) + } else if !tx_languages.contains(&Language::PlutusV1) && !tx_languages.contains(&Language::PlutusV2) && tx_languages.contains(&Language::PlutusV3) { hex::decode( "a1029901291a000189b41901a401011903e818ad00011903e819ea350401192baf18201a000312591920a404193e801864193e801864193e801864193e801864193e801864193e80186418641864193e8018641a000170a718201a00020782182019f016041a0001194a18b2000119568718201a0001643519030104021a00014f581a0001e143191c893903831906b419022518391a00014f580001011903e819a7a90402195fe419733a1826011a000db464196a8f0119ca3f19022e011999101903e819ecb2011a00022a4718201a000144ce1820193bc318201a0001291101193371041956540a197147184a01197147184a0119a9151902280119aecd19021d0119843c18201a00010a9618201a00011aaa1820191c4b1820191cdf1820192d1a18201a00014f581a0001e143191c893903831906b419022518391a00014f5800011a0001614219020700011a000122c118201a00014f581a0001e143191c893903831906b419022518391a00014f580001011a00014f581a0001e143191c893903831906b419022518391a00014f5800011a000e94721a0003414000021a0004213c19583c041a00163cad19fc3604194ff30104001a00022aa818201a000189b41901a401011a00013eff182019e86a1820194eae182019600c1820195108182019654d182019602f18201a0290f1e70a1a032e93af1937fd0a1a0298e40b1966c40a193e801864193e8018641a000eaf1f121a002a6e06061a0006be98011a0321aac7190eac121a00041699121a048e466e1922a4121a0327ec9a121a001e743c18241a0031410f0c1a000dbf9e011a09f2f6d31910d318241a0004578218241a096e44021967b518241a0473cee818241a13e62472011a0f23d40118481a00212c5618481a0022814619fc3b041a00032b00192076041a0013be0419702c183f00011a000f59d919aa6718fb00011a000187551902d61902cf00011a000187551902d61902cf00011a000187551902d61902cf00011a0001a5661902a800011a00017468011a00044a391949a000011a0002bfe2189f01011a00026b371922ee00011a00026e9219226d00011a0001a3e2190ce2011a00019e4919028f011a001df8bb195fc803" ).unwrap() - } - else { + } else { hex::decode( "a241005901b69f1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0aff0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a" ).unwrap() @@ -1913,16 +1911,14 @@ fn cost_model_cbor( hex::decode( "a10198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a" ).unwrap() - } - else if !tx_languages.contains(&Language::PlutusV1) + } else if !tx_languages.contains(&Language::PlutusV1) && !tx_languages.contains(&Language::PlutusV2) && tx_languages.contains(&Language::PlutusV3) { hex::decode( "a1029901291a000189b41901a401011903e818ad00011903e819ea350401192baf18201a000312591920a404193e801864193e801864193e801864193e801864193e801864193e80186418641864193e8018641a000170a718201a00020782182019f016041a0001194a18b2000119568718201a0001643519030104021a00014f581a0001e143191c893903831906b419022518391a00014f580001011903e819a7a90402195fe419733a1826011a000db464196a8f0119ca3f19022e011999101903e819ecb2011a00022a4718201a000144ce1820193bc318201a0001291101193371041956540a197147184a01197147184a0119a9151902280119aecd19021d0119843c18201a00010a9618201a00011aaa1820191c4b1820191cdf1820192d1a18201a00014f581a0001e143191c893903831906b419022518391a00014f5800011a0001614219020700011a000122c118201a00014f581a0001e143191c893903831906b419022518391a00014f580001011a00014f581a0001e143191c893903831906b419022518391a00014f5800011a000e94721a0003414000021a0004213c19583c041a00163cad19fc3604194ff30104001a00022aa818201a000189b41901a401011a00013eff182019e86a1820194eae182019600c1820195108182019654d182019602f18201a0290f1e70a1a032e93af1937fd0a1a0298e40b1966c40a193e801864193e8018641a000eaf1f121a002a6e06061a0006be98011a0321aac7190eac121a00041699121a048e466e1922a4121a0327ec9a121a001e743c18241a0031410f0c1a000dbf9e011a09f2f6d31910d318241a0004578218241a096e44021967b518241a0473cee818241a13e62472011a0f23d40118481a00212c5618481a0022814619fc3b041a00032b00192076041a0013be0419702c183f00011a000f59d919aa6718fb00011a000187551902d61902cf00011a000187551902d61902cf00011a000187551902d61902cf00011a0001a5661902a800011a00017468011a00044a391949a000011a0002bfe2189f01011a00026b371922ee00011a00026e9219226d00011a0001a3e2190ce2011a00019e4919028f011a001df8bb195fc803" ).unwrap() - } - else { + } else { hex::decode( "a241005901b69f1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0aff0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a" ).unwrap() diff --git a/pallas-applying/src/lib.rs b/pallas-applying/src/lib.rs index 6ff2e7a8..3dca30a3 100644 --- a/pallas-applying/src/lib.rs +++ b/pallas-applying/src/lib.rs @@ -3,9 +3,9 @@ pub mod alonzo; pub mod babbage; pub mod byron; +pub mod conway; pub mod shelley_ma; pub mod utils; -pub mod conway; use alonzo::validate_alonzo_tx; use babbage::validate_babbage_tx; @@ -97,7 +97,7 @@ pub fn validate_tx( env.network_id(), ), _ => Err(TxAndProtParamsDiffer), - } + }, (_, None) => Err(EnvMissingAccountState), } } diff --git a/pallas-applying/src/utils.rs b/pallas-applying/src/utils.rs index 363d8742..eba314ab 100644 --- a/pallas-applying/src/utils.rs +++ b/pallas-applying/src/utils.rs @@ -13,10 +13,15 @@ use pallas_crypto::key::ed25519::{PublicKey, Signature}; use pallas_primitives::{ alonzo::{ AuxiliaryData, MintedTx as AlonzoMintedTx, Multiasset, NativeScript, VKeyWitness, Value, - }, babbage::MintedTx as BabbageMintedTx, conway::{MintedTx as ConwayMintedTx, Multiasset as ConwayMultiasset, Value as ConwayValue,}, AddrKeyhash, AssetName, Coin, Epoch, GenesisDelegateHash, Genesishash, NetworkId, NonEmptyKeyValuePairs, NonZeroInt, PlutusScript, PolicyId, PoolKeyhash, PoolMetadata, PositiveCoin, Relay, RewardAccount, StakeCredential, TransactionIndex, UnitInterval, VrfKeyhash + }, + babbage::MintedTx as BabbageMintedTx, + conway::{MintedTx as ConwayMintedTx, Multiasset as ConwayMultiasset, Value as ConwayValue}, + AddrKeyhash, AssetName, Coin, Epoch, GenesisDelegateHash, Genesishash, NetworkId, + NonEmptyKeyValuePairs, NonZeroInt, PlutusScript, PolicyId, PoolKeyhash, PoolMetadata, + PositiveCoin, Relay, RewardAccount, StakeCredential, TransactionIndex, UnitInterval, + VrfKeyhash, }; - use pallas_traverse::{time::Slot, MultiEraInput, MultiEraOutput}; use std::collections::HashMap; use std::ops::Deref; @@ -84,19 +89,24 @@ pub fn conway_add_values( ) -> Result { match (first, second) { (ConwayValue::Coin(f), ConwayValue::Coin(s)) => Ok(ConwayValue::Coin(f + s)), - (ConwayValue::Multiasset(f, fma), ConwayValue::Coin(s)) => Ok(ConwayValue::Multiasset(f + s, fma.clone())), - (ConwayValue::Coin(f), ConwayValue::Multiasset(s, sma)) => Ok(ConwayValue::Multiasset(f + s, sma.clone())), - (ConwayValue::Multiasset(f, fma), ConwayValue::Multiasset(s, sma)) => Ok(ConwayValue::Multiasset( - f + s, - conway_coerce_to_coin( - &conway_add_multiasset_values(&coerce_to_u64(fma), &coerce_to_u64(sma)), - err, - )?, - )), + (ConwayValue::Multiasset(f, fma), ConwayValue::Coin(s)) => { + Ok(ConwayValue::Multiasset(f + s, fma.clone())) + } + (ConwayValue::Coin(f), ConwayValue::Multiasset(s, sma)) => { + Ok(ConwayValue::Multiasset(f + s, sma.clone())) + } + (ConwayValue::Multiasset(f, fma), ConwayValue::Multiasset(s, sma)) => { + Ok(ConwayValue::Multiasset( + f + s, + conway_coerce_to_coin( + &conway_add_multiasset_values(&coerce_to_u64(fma), &coerce_to_u64(sma)), + err, + )?, + )) + } } } - pub fn lovelace_diff_or_fail( first: &Value, second: &Value, @@ -162,7 +172,10 @@ pub fn conway_lovelace_diff_or_fail( pub fn multi_assets_are_equal(fma: &Multiasset, sma: &Multiasset) -> bool { multi_asset_included(fma, sma) && multi_asset_included(sma, fma) } -pub fn conway_multi_assets_are_equal(fma: &ConwayMultiasset, sma: &ConwayMultiasset) -> bool { +pub fn conway_multi_assets_are_equal( + fma: &ConwayMultiasset, + sma: &ConwayMultiasset, +) -> bool { conway_multi_asset_included(fma, sma) && conway_multi_asset_included(sma, fma) } @@ -190,7 +203,10 @@ pub fn multi_asset_included(fma: &Multiasset, sma: &Multiasset) -> b true } -pub fn conway_multi_asset_included(fma: &ConwayMultiasset, sma: &ConwayMultiasset) -> bool { +pub fn conway_multi_asset_included( + fma: &ConwayMultiasset, + sma: &ConwayMultiasset, +) -> bool { for (fpolicy, fassets) in fma.iter() { match conway_find_policy(sma, fpolicy) { Some(sassets) => { @@ -236,7 +252,10 @@ pub fn conway_add_minted_value( err: &ValidationError, ) -> Result { match base_value { - ConwayValue::Coin(n) => Ok(ConwayValue::Multiasset(*n, conway_coerce_to_coin(minted_value, err)?)), + ConwayValue::Coin(n) => Ok(ConwayValue::Multiasset( + *n, + conway_coerce_to_coin(minted_value, err)?, + )), ConwayValue::Multiasset(n, mary_base_value) => Ok(ConwayValue::Multiasset( *n, conway_coerce_to_coin( @@ -253,18 +272,23 @@ pub fn conway_add_minted_non_zero( err: &ValidationError, ) -> Result { match base_value { - ConwayValue::Coin(n) => Ok(ConwayValue::Multiasset(*n, conway_coerce_to_non_zero_coin(minted_value, err)?)), + ConwayValue::Coin(n) => Ok(ConwayValue::Multiasset( + *n, + conway_coerce_to_non_zero_coin(minted_value, err)?, + )), ConwayValue::Multiasset(n, mary_base_value) => Ok(ConwayValue::Multiasset( *n, conway_coerce_to_coin( - &conway_add_multiasset_non_zero_values(&coerce_to_u64(mary_base_value), minted_value), + &conway_add_multiasset_non_zero_values( + &coerce_to_u64(mary_base_value), + minted_value, + ), err, )?, )), } } - fn coerce_to_i64(value: &Multiasset) -> Multiasset { let mut res: Vec<(PolicyId, KeyValuePairs)> = Vec::new(); for (policy, assets) in value.clone().to_vec().iter() { @@ -284,7 +308,10 @@ fn coerce_to_u64(value: &ConwayMultiasset) -> ConwayMultiasset::try_from(aa).unwrap())); + res.push(( + *policy, + NonEmptyKeyValuePairs::::try_from(aa).unwrap(), + )); } NonEmptyKeyValuePairs::>::try_from(res).unwrap() } @@ -314,7 +341,10 @@ fn conway_coerce_to_coin( for (asset_name, amount) in assets.clone().to_vec().iter() { aa.push((asset_name.clone(), PositiveCoin::try_from(*amount).unwrap())); } - res.push((*policy, NonEmptyKeyValuePairs::::try_from(aa).unwrap())); + res.push(( + *policy, + NonEmptyKeyValuePairs::::try_from(aa).unwrap(), + )); } Ok(ConwayMultiasset::try_from(res).unwrap()) } @@ -326,9 +356,15 @@ fn conway_coerce_to_non_zero_coin( for (policy, assets) in value.iter() { let mut aa: Vec<(AssetName, PositiveCoin)> = Vec::new(); for (asset_name, amount) in assets.clone().to_vec().iter() { - aa.push((asset_name.clone(), PositiveCoin::try_from(i64::from(amount) as u64).unwrap())); + aa.push(( + asset_name.clone(), + PositiveCoin::try_from(i64::from(amount) as u64).unwrap(), + )); } - res.push((*policy, NonEmptyKeyValuePairs::::try_from(aa).unwrap())); + res.push(( + *policy, + NonEmptyKeyValuePairs::::try_from(aa).unwrap(), + )); } Ok(ConwayMultiasset::try_from(res).unwrap()) } @@ -350,42 +386,70 @@ fn add_multiasset_values(first: &Multiasset, second: &Multiasset) -> M wrap_multiasset(res) } -fn conway_add_multiasset_values(first: &ConwayMultiasset, second: &ConwayMultiasset) -> ConwayMultiasset { +fn conway_add_multiasset_values( + first: &ConwayMultiasset, + second: &ConwayMultiasset, +) -> ConwayMultiasset { let mut res: HashMap> = HashMap::new(); for (policy, new_assets) in first.iter() { match res.get(policy) { - Some(old_assets) => res.insert(*policy, conway_add_same_policy_assets(old_assets, new_assets)), - None => res.insert(*policy, conway_add_same_policy_assets(&HashMap::new(), new_assets)), + Some(old_assets) => res.insert( + *policy, + conway_add_same_policy_assets(old_assets, new_assets), + ), + None => res.insert( + *policy, + conway_add_same_policy_assets(&HashMap::new(), new_assets), + ), }; } for (policy, new_assets) in second.iter() { match res.get(policy) { - Some(old_assets) => res.insert(*policy, conway_add_same_policy_assets(old_assets, new_assets)), - None => res.insert(*policy, conway_add_same_policy_assets(&HashMap::new(), new_assets)), + Some(old_assets) => res.insert( + *policy, + conway_add_same_policy_assets(old_assets, new_assets), + ), + None => res.insert( + *policy, + conway_add_same_policy_assets(&HashMap::new(), new_assets), + ), }; } conway_wrap_multiasset(res) } -fn conway_add_multiasset_non_zero_values(first: &ConwayMultiasset, second: &ConwayMultiasset) -> ConwayMultiasset { +fn conway_add_multiasset_non_zero_values( + first: &ConwayMultiasset, + second: &ConwayMultiasset, +) -> ConwayMultiasset { let mut res: HashMap> = HashMap::new(); for (policy, new_assets) in first.iter() { match res.get(policy) { - Some(old_assets) => res.insert(*policy, conway_add_same_policy_assets(old_assets, new_assets)), - None => res.insert(*policy, conway_add_same_policy_assets(&HashMap::new(), new_assets)), + Some(old_assets) => res.insert( + *policy, + conway_add_same_policy_assets(old_assets, new_assets), + ), + None => res.insert( + *policy, + conway_add_same_policy_assets(&HashMap::new(), new_assets), + ), }; } for (policy, new_assets) in second.iter() { match res.get(policy) { - Some(old_assets) => res.insert(*policy, conway_add_same_non_zero_policy_assets(old_assets, new_assets)), - None => res.insert(*policy, conway_add_same_non_zero_policy_assets(&HashMap::new(), new_assets)), + Some(old_assets) => res.insert( + *policy, + conway_add_same_non_zero_policy_assets(old_assets, new_assets), + ), + None => res.insert( + *policy, + conway_add_same_non_zero_policy_assets(&HashMap::new(), new_assets), + ), }; } conway_wrap_multiasset(res) } - - fn add_same_policy_assets( old_assets: &HashMap, new_assets: &KeyValuePairs, @@ -420,7 +484,10 @@ fn conway_add_same_non_zero_policy_assets( let mut res: HashMap = old_assets.clone(); for (asset_name, new_amount) in new_assets.iter() { match res.get(asset_name) { - Some(old_amount) => res.insert(asset_name.clone(), old_amount + i64::from(new_amount) as u64), + Some(old_amount) => res.insert( + asset_name.clone(), + old_amount + i64::from(new_amount) as u64, + ), None => res.insert(asset_name.clone(), i64::from(new_amount) as u64), }; } @@ -443,7 +510,9 @@ fn wrap_multiasset(input: HashMap>) -> Multias ) } -fn conway_wrap_multiasset(input: HashMap>) -> ConwayMultiasset { +fn conway_wrap_multiasset( + input: HashMap>, +) -> ConwayMultiasset { ConwayMultiasset::try_from( input .into_iter() @@ -452,14 +521,15 @@ fn conway_wrap_multiasset(input: HashMap>) -> policy, NonEmptyKeyValuePairs::::try_from( assets.into_iter().collect::>(), - ).unwrap(), + ) + .unwrap(), ) }) .collect::)>>(), - ).unwrap() + ) + .unwrap() } - pub fn values_are_equal(first: &Value, second: &Value) -> bool { match (first, second) { (Value::Coin(f), Value::Coin(s)) => f == s, @@ -489,7 +559,6 @@ pub fn conway_values_are_equal(first: &ConwayValue, second: &ConwayValue) -> boo } } - fn find_policy( mary_value: &Multiasset, search_policy: &PolicyId, @@ -522,7 +591,10 @@ fn find_assets(assets: &KeyValuePairs, asset_name: &AssetName) } None } -fn conway_find_assets(assets: &NonEmptyKeyValuePairs, asset_name: &AssetName) -> Option { +fn conway_find_assets( + assets: &NonEmptyKeyValuePairs, + asset_name: &AssetName, +) -> Option { for (an, amount) in assets.clone().to_vec().iter() { if an == asset_name { return Some(*amount); @@ -648,7 +720,6 @@ pub fn compute_plutus_v3_script_hash(script: &PlutusScript<3>) -> PolicyId { pallas_crypto::hash::Hasher::<224>::hash(&payload) } - pub type CertificateIndex = u32; #[derive(PartialEq, Eq, Hash, Clone)] diff --git a/pallas-applying/tests/babbage.rs b/pallas-applying/tests/babbage.rs index b09fa016..b87efc88 100644 --- a/pallas-applying/tests/babbage.rs +++ b/pallas-applying/tests/babbage.rs @@ -4,7 +4,7 @@ use common::*; use pallas_addresses::{Address, Network, ShelleyAddress, ShelleyPaymentPart}; use pallas_applying::{ utils::{ - AccountState, PostAlonzoError, BabbageProtParams, Environment, MultiEraProtocolParameters, + AccountState, BabbageProtParams, Environment, MultiEraProtocolParameters, PostAlonzoError, ValidationError::*, }, validate_txs, CertState, UTxOs, diff --git a/pallas-configs/src/shelley.rs b/pallas-configs/src/shelley.rs index e6fdecb9..847d3b8b 100644 --- a/pallas-configs/src/shelley.rs +++ b/pallas-configs/src/shelley.rs @@ -110,14 +110,16 @@ pub struct ProtocolParams { #[serde(rename_all = "camelCase")] pub struct Metadata { pub hash: String, - pub url: String + pub url: String, } #[derive(Debug, Deserialize, Clone)] pub struct SingleHostAddr { pub port: Option, - pub IPv6: Option, - pub IPv4: Option, + #[serde(rename = "IPv6")] + pub ipv6: Option, + #[serde(rename = "IPv4")] + pub ipv4: Option, } #[derive(Debug, Deserialize, Clone)] @@ -210,13 +212,16 @@ pub type GenesisUtxo = (Hash<32>, pallas_addresses::Address, u64); pub fn shelley_utxos(config: &GenesisFile) -> Vec { match &config.initial_funds { None => Vec::new(), - Some(funds) => funds.iter().map(|(addr, amount)| { - let addr = pallas_addresses::Address::from_hex(addr).unwrap(); + Some(funds) => funds + .iter() + .map(|(addr, amount)| { + let addr = pallas_addresses::Address::from_hex(addr).unwrap(); - let txid = pallas_crypto::hash::Hasher::<256>::hash(&addr.to_vec()); + let txid = pallas_crypto::hash::Hasher::<256>::hash(&addr.to_vec()); - (txid, addr, *amount) - }).collect() + (txid, addr, *amount) + }) + .collect(), } } @@ -246,10 +251,7 @@ mod tests { utxo.1.to_bech32().unwrap(), "addr_test1qrsm4h32h9r95f8at64ykuugxqu3wvu0s5ay3vg6tlyevjh4e2flkegka00r69gt8c4vkxgf2vnnph3nsvhlkg5ukgxslee3tf" ); - assert_eq!( - utxo.2, - 12157196 - ); + assert_eq!(utxo.2, 12157196); } #[test] diff --git a/pallas-utxorpc/src/lib.rs b/pallas-utxorpc/src/lib.rs index b25084e0..ea69b278 100644 --- a/pallas-utxorpc/src/lib.rs +++ b/pallas-utxorpc/src/lib.rs @@ -164,7 +164,7 @@ impl Mapper { pub fn map_any_script(&self, x: &conway::MintedScriptRef) -> u5c::Script { match x { conway::PseudoScript::NativeScript(x) => u5c::Script { - script: u5c::script::Script::Native(Self::map_native_script(&x)).into(), + script: u5c::script::Script::Native(Self::map_native_script(x)).into(), }, conway::PseudoScript::PlutusV1Script(x) => u5c::Script { script: u5c::script::Script::PlutusV1(x.0.to_vec().into()).into(), diff --git a/pallas-utxorpc/src/params.rs b/pallas-utxorpc/src/params.rs index 8fa4414c..fb431b80 100644 --- a/pallas-utxorpc/src/params.rs +++ b/pallas-utxorpc/src/params.rs @@ -216,7 +216,6 @@ impl Mapper { .cost_models_for_script_languages .plutus_v3 .map(|values| u5c::CostModel { values }), - ..Default::default() } .into(), ..Default::default()