refactor: support roundtrip encoding for script data hash components (#526)

This commit is contained in:
Santiago Carmuega 2024-10-22 10:09:37 -03:00 committed by GitHub
parent 969d5612b7
commit 537cd45c23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 84 additions and 119 deletions

View file

@ -182,7 +182,7 @@ mod tests {
use crate::{Era, MultiEraTx};
use super::{ComputeHash, OriginalHash};
use pallas_codec::utils::Int;
use pallas_codec::utils::{Int, MaybeIndefArray};
use pallas_codec::{minicbor, utils::Bytes};
use pallas_crypto::hash::Hash;
use pallas_crypto::key::ed25519::PublicKey;
@ -283,26 +283,26 @@ mod tests {
let pd = alonzo::PlutusData::Constr(alonzo::Constr::<alonzo::PlutusData> {
tag: 1280,
any_constructor: None,
fields: vec![
fields: MaybeIndefArray::Indef(vec![
alonzo::PlutusData::BigInt(alonzo::BigInt::Int(Int::from(4))),
alonzo::PlutusData::Constr(alonzo::Constr::<alonzo::PlutusData> {
tag: 124,
any_constructor: None,
fields: vec![
fields: MaybeIndefArray::Indef(vec![
alonzo::PlutusData::BigInt(alonzo::BigInt::Int(Int::from(-4))),
alonzo::PlutusData::Constr(alonzo::Constr::<alonzo::PlutusData> {
tag: 102,
any_constructor: Some(453),
fields: vec![
fields: MaybeIndefArray::Indef(vec![
alonzo::PlutusData::BigInt(alonzo::BigInt::Int(Int::from(2))),
alonzo::PlutusData::BigInt(alonzo::BigInt::Int(Int::from(3434))),
],
]),
}),
alonzo::PlutusData::BigInt(alonzo::BigInt::Int(Int::from(-11828293))),
],
]),
}),
alonzo::PlutusData::BigInt(alonzo::BigInt::Int(Int::from(11828293))),
],
]),
});
// if you need to try this out in the cardano-cli, uncomment this line to see

View file

@ -65,4 +65,17 @@ impl<'b> MultiEraRedeemer<'b> {
Box::new(Cow::Borrowed(redeemers_val)),
)
}
pub fn from_conway_deprecated(redeemer: &'b conway::Redeemer) -> Self {
Self::Conway(
Box::new(Cow::Owned(conway::RedeemersKey {
tag: redeemer.tag,
index: redeemer.index,
})),
Box::new(Cow::Owned(conway::RedeemersValue {
data: redeemer.data.clone(),
ex_units: redeemer.ex_units,
})),
)
}
}

View file

@ -1,7 +1,7 @@
use pallas_codec::utils::KeepRaw;
use pallas_primitives::{
alonzo::{self, BootstrapWitness, NativeScript, VKeyWitness},
PlutusData, PlutusScript,
conway, PlutusData, PlutusScript,
};
use crate::{MultiEraRedeemer, MultiEraTx};
@ -144,13 +144,17 @@ impl<'b> MultiEraTx<'b> {
.flat_map(|x| x.iter())
.map(MultiEraRedeemer::from_alonzo_compatible)
.collect(),
Self::Conway(x) => x
.transaction_witness_set
.redeemer
.iter()
.flat_map(|x| x.iter())
.map(|(k, v)| MultiEraRedeemer::from_conway(k, v))
.collect(),
Self::Conway(x) => match x.transaction_witness_set.redeemer.as_deref() {
Some(conway::Redeemers::Map(x)) => x
.iter()
.map(|(k, v)| MultiEraRedeemer::from_conway(k, v))
.collect(),
Some(conway::Redeemers::List(x)) => x
.iter()
.map(MultiEraRedeemer::from_conway_deprecated)
.collect(),
_ => vec![],
},
}
}