chore(txbuilder): fix lint warnings (#343)
This commit is contained in:
parent
f3d9719b5d
commit
b13d3b6688
5 changed files with 56 additions and 50 deletions
|
|
@ -27,7 +27,8 @@ use crate::{
|
|||
pub trait BuildBabbage {
|
||||
fn build_babbage_raw(self) -> Result<BuiltTransaction, TxBuilderError>;
|
||||
|
||||
// fn build_babbage(staging_tx: StagingTransaction, resolver: (), params: ()) -> Result<BuiltTransaction, TxBuilderError>;
|
||||
// fn build_babbage(staging_tx: StagingTransaction, resolver: (), params: ()) ->
|
||||
// Result<BuiltTransaction, TxBuilderError>;
|
||||
}
|
||||
|
||||
impl BuildBabbage for StagingTransaction {
|
||||
|
|
@ -51,28 +52,23 @@ impl BuildBabbage for StagingTransaction {
|
|||
.map(babbage_output)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
let mint: Option<KeyValuePairs<Hash<28>, 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::<Vec<_>>()
|
||||
.into(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mint: Option<KeyValuePairs<Hash<28>, KeyValuePairs<_, _>>> = self.mint.map(|massets| {
|
||||
massets
|
||||
.deref()
|
||||
.iter()
|
||||
.map(|(pid, assets)| {
|
||||
(
|
||||
pid.0.into(),
|
||||
assets
|
||||
.iter()
|
||||
.map(|(n, x)| (n.clone().into(), *x))
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into()
|
||||
});
|
||||
|
||||
let collateral = self
|
||||
.collateral_inputs
|
||||
|
|
@ -260,8 +256,8 @@ impl BuildBabbage for StagingTransaction {
|
|||
})
|
||||
}
|
||||
|
||||
// fn build_babbage(staging_tx: StagingTransaction) -> Result<BuiltTransaction, TxBuilderError> {
|
||||
// todo!()
|
||||
// fn build_babbage(staging_tx: StagingTransaction) -> Result<BuiltTransaction,
|
||||
// TxBuilderError> { todo!()
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +272,7 @@ fn babbage_output(
|
|||
(
|
||||
pid.0.into(),
|
||||
assets
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|(n, x)| (n.clone().into(), *x))
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ pub struct Hash28(pub [u8; 28]);
|
|||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Bytes(pub Vec<u8>);
|
||||
|
||||
impl Into<pallas_codec::utils::Bytes> for Bytes {
|
||||
fn into(self) -> pallas_codec::utils::Bytes {
|
||||
self.0.into()
|
||||
impl From<Bytes> for pallas_codec::utils::Bytes {
|
||||
fn from(value: Bytes) -> Self {
|
||||
value.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -469,7 +469,7 @@ impl Output {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Default)]
|
||||
pub struct OutputAssets(HashMap<PolicyId, HashMap<AssetName, u64>>);
|
||||
|
||||
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<PolicyId, HashMap<Bytes, u64>>) -> 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<RedeemerPurpose, (Bytes, Option<ExUnits>)>);
|
||||
|
||||
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<RedeemerPurpose, (Bytes, Option<ExUnits>)>) -> 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<Self, TxBuilderError> {
|
||||
pub fn add_signature(
|
||||
mut self,
|
||||
pub_key: ed25519::PublicKey,
|
||||
signature: [u8; 64],
|
||||
) -> Result<Self, TxBuilderError> {
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue