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

Datum and redeemer insertion order #130

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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: 24 additions & 24 deletions rust/pkg/cardano_multiplatform_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ declare export function calc_script_data_hash(
used_langs: Languages
): ScriptDataHash | void;

/**
* @param {TransactionHash} tx_body_hash
* @param {ByronAddress} addr
* @param {LegacyDaedalusPrivateKey} key
* @returns {BootstrapWitness}
*/
declare export function make_daedalus_bootstrap_witness(
tx_body_hash: TransactionHash,
addr: ByronAddress,
key: LegacyDaedalusPrivateKey
): BootstrapWitness;

/**
* @param {TransactionHash} tx_body_hash
* @param {ByronAddress} addr
* @param {Bip32PrivateKey} key
* @returns {BootstrapWitness}
*/
declare export function make_icarus_bootstrap_witness(
tx_body_hash: TransactionHash,
addr: ByronAddress,
key: Bip32PrivateKey
): BootstrapWitness;

/**
* @param {string} json
* @param {number} schema
Expand Down Expand Up @@ -129,30 +153,6 @@ declare export function encode_json_str_to_native_script(
schema: number
): NativeScript;

/**
* @param {TransactionHash} tx_body_hash
* @param {ByronAddress} addr
* @param {LegacyDaedalusPrivateKey} key
* @returns {BootstrapWitness}
*/
declare export function make_daedalus_bootstrap_witness(
tx_body_hash: TransactionHash,
addr: ByronAddress,
key: LegacyDaedalusPrivateKey
): BootstrapWitness;

/**
* @param {TransactionHash} tx_body_hash
* @param {ByronAddress} addr
* @param {Bip32PrivateKey} key
* @returns {BootstrapWitness}
*/
declare export function make_icarus_bootstrap_witness(
tx_body_hash: TransactionHash,
addr: ByronAddress,
key: Bip32PrivateKey
): BootstrapWitness;

/**
* Provide backwards compatibility to Alonzo by taking the max min value of both er
* @param {TransactionOutput} output
Expand Down
15 changes: 11 additions & 4 deletions rust/src/builders/witness_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{collections::{HashMap}, fmt::Debug};
use itertools::Itertools;
use linked_hash_map::LinkedHashMap;

use crate::{*, ledger::common::hash::hash_plutus_data, byron::ByronAddress};

use super::redeemer_builder::RedeemerWitnessKey;
Expand Down Expand Up @@ -225,8 +228,8 @@ pub struct TransactionWitnessSetBuilder {
pub(crate) vkeys: HashMap<Vkey, Vkeywitness>,
pub(crate) bootstraps: HashMap<Vkey, BootstrapWitness>,
pub(crate) scripts: HashMap<ScriptHash, ScriptEnum>,
pub(crate) plutus_data: HashMap<DataHash, PlutusData>,
pub(crate) redeemers: HashMap<RedeemerWitnessKey, Redeemer>,
pub(crate) plutus_data: LinkedHashMap<DataHash, PlutusData>,
pub(crate) redeemers: LinkedHashMap<RedeemerWitnessKey, Redeemer>,

/// witnesses that need to be added for the build function to succeed
/// this allows checking that witnesses are present at build time (instead of when submitting to a node)
Expand Down Expand Up @@ -320,7 +323,9 @@ impl TransactionWitnessSetBuilder {

pub fn get_plutus_datum(&self) -> PlutusList {
PlutusList {
elems: self.plutus_data.clone().into_values().collect(),
elems: self.plutus_data.clone().iter().map(|i|{
i.1.clone()
}).collect_vec(),
definite_encoding: None
}
}
Expand All @@ -337,7 +342,9 @@ impl TransactionWitnessSetBuilder {
}

pub fn get_redeemer(&self) -> Redeemers {
Redeemers(self.redeemers.clone().into_values().collect())
Redeemers(self.redeemers.clone().iter().map(|i|{
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this clone is necessary anymore since iter() should give you refs to iterate over which you are cloning in that map anyway. Same with the one above in get_plutus_datum.

i.1.clone()
}).collect_vec())
}

pub fn add_required_wits(&mut self, required_wits: &RequiredWitnessSet) {
Expand Down