Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(traverse): Provide access to original Datum hash #189

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions pallas-primitives/src/alonzo/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ pub struct BootstrapWitness {

#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
#[cbor(map)]
pub struct TransactionWitnessSet {
pub struct WitnessSet {
#[n(0)]
pub vkeywitness: Option<Vec<VKeyWitness>>,

Expand All @@ -1179,6 +1179,43 @@ pub struct TransactionWitnessSet {
pub redeemer: Option<Vec<Redeemer>>,
}

#[derive(Encode, Decode, Debug, PartialEq, Clone)]
#[cbor(map)]
pub struct MintedWitnessSet<'b> {
#[n(0)]
pub vkeywitness: Option<Vec<VKeyWitness>>,

#[n(1)]
pub native_script: Option<Vec<NativeScript>>,
Copy link
Member

@jmhrpr jmhrpr Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use KeepRaw for NativeScript? When we decode a NativeScript into an internal representation we decode both definite and indefinite arrays, but we encode to definite. The hash needs to match the original bytes so that the script hash matches addresses in the inputs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, there are lot of sub-structures that will need this treatment. Off the top of my head, redeemers and metadata. I would prefer to treat each one on a different PR.


#[n(2)]
pub bootstrap_witness: Option<Vec<BootstrapWitness>>,

#[n(3)]
pub plutus_script: Option<Vec<PlutusScript>>,

#[b(4)]
pub plutus_data: Option<Vec<KeepRaw<'b, PlutusData>>>,

#[n(5)]
pub redeemer: Option<Vec<Redeemer>>,
}

impl<'b> From<MintedWitnessSet<'b>> for WitnessSet {
fn from(x: MintedWitnessSet<'b>) -> Self {
WitnessSet {
vkeywitness: x.vkeywitness,
native_script: x.native_script,
bootstrap_witness: x.bootstrap_witness,
plutus_script: x.plutus_script,
plutus_data: x
.plutus_data
.map(|x| x.into_iter().map(|x| x.unwrap()).collect()),
redeemer: x.redeemer,
}
}
}

#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
#[cbor(map)]
pub struct PostAlonzoAuxiliaryData {
Expand Down Expand Up @@ -1328,7 +1365,7 @@ pub struct Block {
pub transaction_bodies: Vec<TransactionBody>,

#[n(2)]
pub transaction_witness_sets: Vec<TransactionWitnessSet>,
pub transaction_witness_sets: Vec<WitnessSet>,

#[n(3)]
pub auxiliary_data_set: BTreeMap<TransactionIndex, AuxiliaryData>,
Expand All @@ -1351,7 +1388,7 @@ pub struct MintedBlock<'b> {
pub transaction_bodies: MaybeIndefArray<KeepRaw<'b, TransactionBody>>,

#[n(2)]
pub transaction_witness_sets: MaybeIndefArray<KeepRaw<'b, TransactionWitnessSet>>,
pub transaction_witness_sets: MaybeIndefArray<KeepRaw<'b, MintedWitnessSet<'b>>>,

#[n(3)]
pub auxiliary_data_set: KeyValuePairs<TransactionIndex, KeepRaw<'b, AuxiliaryData>>,
Expand All @@ -1375,6 +1412,7 @@ impl<'b> From<MintedBlock<'b>> for Block {
.to_vec()
.into_iter()
.map(|x| x.unwrap())
.map(|x| WitnessSet::from(x))
.collect(),
auxiliary_data_set: x
.auxiliary_data_set
Expand All @@ -1393,7 +1431,7 @@ pub struct Tx {
pub transaction_body: TransactionBody,

#[n(1)]
pub transaction_witness_set: TransactionWitnessSet,
pub transaction_witness_set: WitnessSet,

#[n(2)]
pub success: bool,
Expand All @@ -1408,7 +1446,7 @@ pub struct MintedTx<'b> {
pub transaction_body: KeepRaw<'b, TransactionBody>,

#[n(1)]
pub transaction_witness_set: KeepRaw<'b, TransactionWitnessSet>,
pub transaction_witness_set: KeepRaw<'b, MintedWitnessSet<'b>>,

#[n(2)]
pub success: bool,
Expand Down
54 changes: 48 additions & 6 deletions pallas-primitives/src/babbage/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub use crate::alonzo::BootstrapWitness;

#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
#[cbor(map)]
pub struct TransactionWitnessSet {
pub struct WitnessSet {
#[n(0)]
pub vkeywitness: Option<Vec<VKeyWitness>>,

Expand All @@ -398,6 +398,47 @@ pub struct TransactionWitnessSet {
pub plutus_v2_script: Option<Vec<PlutusV2Script>>,
}

#[derive(Encode, Decode, Debug, PartialEq, Clone)]
#[cbor(map)]
pub struct MintedWitnessSet<'b> {
#[n(0)]
pub vkeywitness: Option<Vec<VKeyWitness>>,

#[n(1)]
pub native_script: Option<Vec<NativeScript>>,

#[n(2)]
pub bootstrap_witness: Option<Vec<BootstrapWitness>>,

#[n(3)]
pub plutus_v1_script: Option<Vec<PlutusV1Script>>,

#[b(4)]
pub plutus_data: Option<Vec<KeepRaw<'b, PlutusData>>>,

#[n(5)]
pub redeemer: Option<Vec<Redeemer>>,

#[n(6)]
pub plutus_v2_script: Option<Vec<PlutusV2Script>>,
}

impl<'b> From<MintedWitnessSet<'b>> for WitnessSet {
fn from(x: MintedWitnessSet<'b>) -> Self {
WitnessSet {
vkeywitness: x.vkeywitness,
native_script: x.native_script,
bootstrap_witness: x.bootstrap_witness,
plutus_v1_script: x.plutus_v1_script,
plutus_data: x
.plutus_data
.map(|x| x.into_iter().map(|x| x.unwrap()).collect()),
redeemer: x.redeemer,
plutus_v2_script: x.plutus_v2_script,
}
}
}

#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Clone)]
#[cbor(map)]
pub struct PostAlonzoAuxiliaryData {
Expand Down Expand Up @@ -521,7 +562,7 @@ pub struct Block {
pub transaction_bodies: Vec<TransactionBody>,

#[n(2)]
pub transaction_witness_sets: Vec<TransactionWitnessSet>,
pub transaction_witness_sets: Vec<WitnessSet>,

#[n(3)]
pub auxiliary_data_set: BTreeMap<TransactionIndex, AuxiliaryData>,
Expand All @@ -544,7 +585,7 @@ pub struct MintedBlock<'b> {
pub transaction_bodies: MaybeIndefArray<KeepRaw<'b, TransactionBody>>,

#[n(2)]
pub transaction_witness_sets: MaybeIndefArray<KeepRaw<'b, TransactionWitnessSet>>,
pub transaction_witness_sets: MaybeIndefArray<KeepRaw<'b, MintedWitnessSet<'b>>>,

#[n(3)]
pub auxiliary_data_set: KeyValuePairs<TransactionIndex, KeepRaw<'b, AuxiliaryData>>,
Expand All @@ -568,6 +609,7 @@ impl<'b> From<MintedBlock<'b>> for Block {
.to_vec()
.into_iter()
.map(|x| x.unwrap())
.map(|x| WitnessSet::from(x))
.collect(),
auxiliary_data_set: x
.auxiliary_data_set
Expand All @@ -586,7 +628,7 @@ pub struct Tx {
pub transaction_body: TransactionBody,

#[n(1)]
pub transaction_witness_set: TransactionWitnessSet,
pub transaction_witness_set: WitnessSet,

#[n(2)]
pub success: bool,
Expand All @@ -601,7 +643,7 @@ pub struct MintedTx<'b> {
pub transaction_body: KeepRaw<'b, TransactionBody>,

#[n(1)]
pub transaction_witness_set: KeepRaw<'b, TransactionWitnessSet>,
pub transaction_witness_set: KeepRaw<'b, MintedWitnessSet<'b>>,

#[n(2)]
pub success: bool,
Expand All @@ -614,7 +656,7 @@ impl<'b> From<MintedTx<'b>> for Tx {
fn from(x: MintedTx<'b>) -> Self {
Tx {
transaction_body: x.transaction_body.unwrap(),
transaction_witness_set: x.transaction_witness_set.unwrap(),
transaction_witness_set: x.transaction_witness_set.unwrap().into(),
success: x.success,
auxiliary_data: x.auxiliary_data.map(|x| x.unwrap()),
}
Expand Down
Loading