refactor: support roundtrip encoding for script data hash components (#526)
This commit is contained in:
parent
969d5612b7
commit
537cd45c23
9 changed files with 84 additions and 119 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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![],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue