fix(interop): use correct input order to match redeemers (#487)

This commit is contained in:
Santiago Carmuega 2024-07-14 13:48:05 -03:00 committed by GitHub
parent 9b16a98fb1
commit 9f9e088091
8 changed files with 1917 additions and 27 deletions

View file

@ -62,6 +62,11 @@ impl<'b> MultiEraInput<'b> {
}
}
/// Returns the key used for lexicographical ordering of the input
pub fn lexicographical_key(&self) -> String {
format!("{}#{}", self.hash(), self.index())
}
pub fn hash(&self) -> &Hash<32> {
match self {
MultiEraInput::Byron(x) => match x.deref().deref() {

View file

@ -196,6 +196,19 @@ impl<'b> MultiEraTx<'b> {
}
}
/// Return inputs as expected for processing
///
/// To process inputs we need a set (no duplicated) and lexicographical
/// order (hash#idx). This function will take the raw inputs and apply the
/// aforementioned cleanup changes.
pub fn inputs_sorted_set(&self) -> Vec<MultiEraInput> {
let mut raw = self.inputs();
raw.sort_by_key(|x| x.lexicographical_key());
raw.dedup_by_key(|x| x.lexicographical_key());
raw
}
/// Return the transaction reference inputs
///
/// NOTE: It is possible for this to return duplicates. See

View file

@ -155,6 +155,12 @@ impl<'b> MultiEraTx<'b> {
}
}
pub fn find_spend_redeemer(&self, input_order: u32) -> Option<MultiEraRedeemer> {
self.redeemers().into_iter().find(|r| {
r.tag() == pallas_primitives::conway::RedeemerTag::Spend && r.index() == input_order
})
}
pub fn plutus_v2_scripts(&self) -> &[PlutusV2Script] {
match self {
Self::Byron(_) => &[],