diff --git a/pallas-txbuilder/src/babbage.rs b/pallas-txbuilder/src/babbage.rs index 24ca4464..d772633f 100644 --- a/pallas-txbuilder/src/babbage.rs +++ b/pallas-txbuilder/src/babbage.rs @@ -27,7 +27,8 @@ use crate::{ pub trait BuildBabbage { fn build_babbage_raw(self) -> Result; - // fn build_babbage(staging_tx: StagingTransaction, resolver: (), params: ()) -> Result; + // fn build_babbage(staging_tx: StagingTransaction, resolver: (), params: ()) -> + // Result; } impl BuildBabbage for StagingTransaction { @@ -51,28 +52,23 @@ impl BuildBabbage for StagingTransaction { .map(babbage_output) .collect::, _>>()?; - let mint: Option, KeyValuePairs<_, _>>> = - if let Some(massets) = self.mint { - Some( - massets - .deref() - .iter() - .map(|(pid, assets)| { - ( - pid.0.into(), - assets - .into_iter() - .map(|(n, x)| (n.clone().into(), *x)) - .collect::>() - .into(), - ) - }) - .collect::>() - .into(), - ) - } else { - None - }; + let mint: Option, KeyValuePairs<_, _>>> = self.mint.map(|massets| { + massets + .deref() + .iter() + .map(|(pid, assets)| { + ( + pid.0.into(), + assets + .iter() + .map(|(n, x)| (n.clone().into(), *x)) + .collect::>() + .into(), + ) + }) + .collect::>() + .into() + }); let collateral = self .collateral_inputs @@ -260,8 +256,8 @@ impl BuildBabbage for StagingTransaction { }) } - // fn build_babbage(staging_tx: StagingTransaction) -> Result { - // todo!() + // fn build_babbage(staging_tx: StagingTransaction) -> Result { todo!() // } } @@ -276,7 +272,7 @@ fn babbage_output( ( pid.0.into(), assets - .into_iter() + .iter() .map(|(n, x)| (n.clone().into(), *x)) .collect::>() .into(), diff --git a/pallas-txbuilder/src/lib.rs b/pallas-txbuilder/src/lib.rs index 7ccbf4e5..7ecdafe8 100644 --- a/pallas-txbuilder/src/lib.rs +++ b/pallas-txbuilder/src/lib.rs @@ -15,7 +15,8 @@ pub enum TxBuilderError { /// Provided datum hash was not 32 bytes in length #[error("Invalid bytes length for datum hash")] MalformedDatumHash, - /// Input, policy, etc pointed to by a redeemer was not found in the transaction + /// Input, policy, etc pointed to by a redeemer was not found in the + /// transaction #[error("Input/policy pointed to by redeemer not found in tx")] RedeemerTargetMissing, /// Provided network ID is invalid (must be 0 or 1) diff --git a/pallas-txbuilder/src/transaction/mod.rs b/pallas-txbuilder/src/transaction/mod.rs index c63d4796..abead44a 100644 --- a/pallas-txbuilder/src/transaction/mod.rs +++ b/pallas-txbuilder/src/transaction/mod.rs @@ -26,9 +26,9 @@ pub struct Hash28(pub [u8; 28]); #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub struct Bytes(pub Vec); -impl Into for Bytes { - fn into(self) -> pallas_codec::utils::Bytes { - self.0.into() +impl From for pallas_codec::utils::Bytes { + fn from(value: Bytes) -> Self { + value.0.into() } } diff --git a/pallas-txbuilder/src/transaction/model.rs b/pallas-txbuilder/src/transaction/model.rs index 2e8e76f6..f8e89880 100644 --- a/pallas-txbuilder/src/transaction/model.rs +++ b/pallas-txbuilder/src/transaction/model.rs @@ -469,7 +469,7 @@ impl Output { } } -#[derive(PartialEq, Eq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone, Default)] pub struct OutputAssets(HashMap>); impl Deref for OutputAssets { @@ -481,10 +481,6 @@ impl Deref for OutputAssets { } impl OutputAssets { - pub fn new() -> Self { - Self(HashMap::new()) - } - pub fn from_map(map: HashMap>) -> Self { Self(map) } @@ -561,7 +557,7 @@ pub struct ExUnits { pub steps: u64, } -#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default)] pub struct Redeemers(HashMap)>); impl Deref for Redeemers { @@ -573,10 +569,6 @@ impl Deref for Redeemers { } impl Redeemers { - pub fn new() -> Self { - Redeemers(HashMap::new()) - } - pub fn from_map(map: HashMap)>) -> Self { Self(map) } @@ -653,12 +645,24 @@ impl BuiltTransaction { Ok(self) } - pub fn add_signature(mut self, pub_key: ed25519::PublicKey, signature: [u8; 64]) -> Result { + pub fn add_signature( + mut self, + pub_key: ed25519::PublicKey, + signature: [u8; 64], + ) -> Result { match self.era { BuilderEra::Babbage => { let mut new_sigs = self.signatures.unwrap_or_default(); - new_sigs.insert(Bytes32(pub_key.as_ref().try_into().map_err(|_| TxBuilderError::MalformedKey)?), Bytes64(signature)); + new_sigs.insert( + Bytes32( + pub_key + .as_ref() + .try_into() + .map_err(|_| TxBuilderError::MalformedKey)?, + ), + Bytes64(signature), + ); self.signatures = Some(new_sigs); @@ -687,7 +691,12 @@ impl BuiltTransaction { BuilderEra::Babbage => { let mut new_sigs = self.signatures.unwrap_or_default(); - let pk = Bytes32(pub_key.as_ref().try_into().map_err(|_| TxBuilderError::MalformedKey)?); + let pk = Bytes32( + pub_key + .as_ref() + .try_into() + .map_err(|_| TxBuilderError::MalformedKey)?, + ); new_sigs.remove(&pk); diff --git a/pallas-txbuilder/src/transaction/serialise.rs b/pallas-txbuilder/src/transaction/serialise.rs index dea5c34e..5dd9bccf 100644 --- a/pallas-txbuilder/src/transaction/serialise.rs +++ b/pallas-txbuilder/src/transaction/serialise.rs @@ -18,7 +18,7 @@ impl Serialize for Bytes32 { where S: Serializer, { - serializer.serialize_str(&hex::encode(&self.0)) + serializer.serialize_str(&hex::encode(self.0)) } } @@ -58,7 +58,7 @@ impl Serialize for Hash28 { where S: Serializer, { - serializer.serialize_str(&hex::encode(&self.0)) + serializer.serialize_str(&hex::encode(self.0)) } } @@ -245,9 +245,9 @@ impl Serialize for RedeemerPurpose { { let str = match self { RedeemerPurpose::Spend(Input { tx_hash, txo_index }) => { - format!("spend:{}#{}", hex::encode(&tx_hash.0), txo_index) + format!("spend:{}#{}", hex::encode(tx_hash.0), txo_index) } - RedeemerPurpose::Mint(hash) => format!("mint:{}", hex::encode(&hash.0)), + RedeemerPurpose::Mint(hash) => format!("mint:{}", hex::encode(hash.0)), }; serializer.serialize_str(&str) @@ -277,13 +277,13 @@ impl<'de> Visitor<'de> for RedeemerPurposeVisitor { E: de::Error, { let (tag, item) = v - .split_once(":") + .split_once(':') .ok_or(E::custom("invalid redeemer purpose"))?; match tag { "spend" => { let (hash, index) = item - .split_once("#") + .split_once('#') .ok_or(E::custom("invalid spend redeemer item"))?; let tx_hash = Bytes32( @@ -355,7 +355,7 @@ impl Serialize for Bytes64 { where S: Serializer, { - serializer.serialize_str(&hex::encode(&self.0)) + serializer.serialize_str(&hex::encode(self.0)) } }