Skip to content

Commit

Permalink
Datum and redeemer insertion order (#130)
Browse files Browse the repository at this point in the history
* Maintain insertion order when inserting redeemers and datum into a hashmap

* wasm js change

* Remove unnecessary clones from functions that use iter and clone the item
  • Loading branch information
MicroProofs committed Sep 27, 2022
1 parent 3fff412 commit fbc858b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
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.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.iter().map(|i|{
i.1.clone()
}).collect_vec())
}

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

0 comments on commit fbc858b

Please sign in to comment.