fix(interop): map missing u5c redeemers (#490)

This commit is contained in:
Lucas 2024-07-15 20:47:25 -04:00 committed by GitHub
parent a85619623d
commit 4fbca7b8ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 95 additions and 14 deletions

View file

@ -18,6 +18,7 @@ pallas-codec = { version = "=0.28.0", path = "../pallas-codec" }
hex = "0.4.3"
thiserror = "1.0.31"
paste = "1.0.14"
itertools = "0.13.0"
# TODO: remove once GenesisValue moves into new genesis crate
serde = "1.0.155"

View file

@ -1,5 +1,6 @@
use std::{borrow::Cow, collections::HashSet, ops::Deref};
use itertools::Itertools;
use pallas_codec::{minicbor, utils::KeepRaw};
use pallas_crypto::hash::Hash;
use pallas_primitives::{
@ -209,6 +210,27 @@ impl<'b> MultiEraTx<'b> {
raw
}
pub fn mints_sorted_set(&self) -> Vec<MultiEraPolicyAssets> {
let mut raw = self.mints();
raw.sort_by_key(|m| *m.policy());
raw
}
pub fn withdrawals_sorted_set(&self) -> Vec<(&[u8], u64)> {
match self.withdrawals() {
MultiEraWithdrawals::NotApplicable | MultiEraWithdrawals::Empty => {
std::iter::empty().collect()
}
MultiEraWithdrawals::AlonzoCompatible(x) => x
.iter()
.map(|(k, v)| (k.as_slice(), *v))
.sorted_by_key(|(k, _)| *k)
.collect(),
}
}
/// Return the transaction reference inputs
///
/// NOTE: It is possible for this to return duplicates. See

View file

@ -161,6 +161,26 @@ impl<'b> MultiEraTx<'b> {
})
}
pub fn find_mint_redeemer(&self, mint_order: u32) -> Option<MultiEraRedeemer> {
self.redeemers().into_iter().find(|r| {
r.tag() == pallas_primitives::conway::RedeemerTag::Mint && r.index() == mint_order
})
}
pub fn find_withdrawal_redeemer(&self, withdrawal_order: u32) -> Option<MultiEraRedeemer> {
self.redeemers().into_iter().find(|r| {
r.tag() == pallas_primitives::conway::RedeemerTag::Reward
&& r.index() == withdrawal_order
})
}
pub fn find_certificate_redeemer(&self, certificate_order: u32) -> Option<MultiEraRedeemer> {
self.redeemers().into_iter().find(|r| {
r.tag() == pallas_primitives::conway::RedeemerTag::Cert
&& r.index() == certificate_order
})
}
pub fn plutus_v2_scripts(&self) -> &[PlutusV2Script] {
match self {
Self::Byron(_) => &[],