Skip to content

Commit 7d3f2a6

Browse files
authored
Merge branch 'master' into evgenii/assets_random_improve
2 parents 041c0b6 + 2e04521 commit 7d3f2a6

File tree

8 files changed

+581
-156
lines changed

8 files changed

+581
-156
lines changed

rust/pkg/cardano_serialization_lib.js.flow

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,12 @@ declare export class Costmdls {
19521952
* @returns {Languages}
19531953
*/
19541954
keys(): Languages;
1955+
1956+
/**
1957+
* @param {Languages} languages
1958+
* @returns {Costmdls}
1959+
*/
1960+
retain_language_versions(languages: Languages): Costmdls;
19551961
}
19561962
/**
19571963
*/
@@ -2124,6 +2130,23 @@ declare export class DataHash {
21242130
*/
21252131
static from_hex(hex: string): DataHash;
21262132
}
2133+
/**
2134+
*/
2135+
declare export class DatumSource {
2136+
free(): void;
2137+
2138+
/**
2139+
* @param {PlutusData} datum
2140+
* @returns {DatumSource}
2141+
*/
2142+
static new(datum: PlutusData): DatumSource;
2143+
2144+
/**
2145+
* @param {TransactionInput} input
2146+
* @returns {DatumSource}
2147+
*/
2148+
static new_ref_input(input: TransactionInput): DatumSource;
2149+
}
21272150
/**
21282151
*/
21292152
declare export class Ed25519KeyHash {
@@ -4715,6 +4738,27 @@ declare export class PlutusScript {
47154738
*/
47164739
language_version(): Language;
47174740
}
4741+
/**
4742+
*/
4743+
declare export class PlutusScriptSource {
4744+
free(): void;
4745+
4746+
/**
4747+
* @param {PlutusScript} script
4748+
* @returns {PlutusScriptSource}
4749+
*/
4750+
static new(script: PlutusScript): PlutusScriptSource;
4751+
4752+
/**
4753+
* @param {ScriptHash} script_hash
4754+
* @param {TransactionInput} input
4755+
* @returns {PlutusScriptSource}
4756+
*/
4757+
static new_ref_input(
4758+
script_hash: ScriptHash,
4759+
input: TransactionInput
4760+
): PlutusScriptSource;
4761+
}
47184762
/**
47194763
*/
47204764
declare export class PlutusScripts {
@@ -4797,14 +4841,26 @@ declare export class PlutusWitness {
47974841
): PlutusWitness;
47984842

47994843
/**
4800-
* @returns {PlutusScript}
4844+
* @param {PlutusScriptSource} script
4845+
* @param {DatumSource} datum
4846+
* @param {Redeemer} redeemer
4847+
* @returns {PlutusWitness}
48014848
*/
4802-
script(): PlutusScript;
4849+
static new_with_ref(
4850+
script: PlutusScriptSource,
4851+
datum: DatumSource,
4852+
redeemer: Redeemer
4853+
): PlutusWitness;
48034854

48044855
/**
4805-
* @returns {PlutusData}
4856+
* @returns {PlutusScript | void}
4857+
*/
4858+
script(): PlutusScript | void;
4859+
4860+
/**
4861+
* @returns {PlutusData | void}
48064862
*/
4807-
datum(): PlutusData;
4863+
datum(): PlutusData | void;
48084864

48094865
/**
48104866
* @returns {Redeemer}
@@ -9296,6 +9352,11 @@ declare export class TxInputsBuilder {
92969352
*/
92979353
add_required_plutus_input_scripts(scripts: PlutusWitnesses): number;
92989354

9355+
/**
9356+
* @returns {TransactionInputs}
9357+
*/
9358+
get_ref_inputs(): TransactionInputs;
9359+
92999360
/**
93009361
* Returns a copy of the current script input witness scripts in the builder
93019362
* @returns {NativeScripts | void}

rust/src/crypto.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crypto::bech32::Bech32 as _;
77
use rand_os::OsRng;
88
use std::io::{BufRead, Seek, Write};
99
use std::str::FromStr;
10+
use std::fmt::Display;
11+
use std::fmt;
1012

1113
use cryptoxide::blake2b::Blake2b;
1214

@@ -1058,6 +1060,12 @@ macro_rules! impl_hash_type {
10581060
String::is_referenceable()
10591061
}
10601062
}
1063+
1064+
impl Display for $name {
1065+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1066+
write!(f, "{}", self.to_hex())
1067+
}
1068+
}
10611069
};
10621070
}
10631071

rust/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ impl std::fmt::Display for DeserializeError {
130130
}
131131
}
132132

133+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
134+
impl std::error::Error for DeserializeError {}
135+
133136
impl From<DeserializeError> for JsError {
134137
fn from(e: DeserializeError) -> JsError {
135138
JsError::from_str(&e.to_string())
@@ -202,3 +205,6 @@ impl std::fmt::Display for JsError {
202205
write!(f, "{}", self.msg)
203206
}
204207
}
208+
209+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
210+
impl std::error::Error for JsError {}

rust/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ use plutus::*;
6666
use schemars::JsonSchema;
6767
use std::cmp::Ordering;
6868
use std::collections::BTreeSet;
69+
use std::fmt::Display;
70+
use std::fmt;
6971
use utils::*;
7072

7173
type DeltaCoin = Int;
@@ -566,7 +568,7 @@ impl TransactionBody {
566568

567569
#[wasm_bindgen]
568570
#[derive(
569-
Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize, JsonSchema,
571+
Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash, serde::Serialize, serde::Deserialize, JsonSchema,
570572
)]
571573
pub struct TransactionInput {
572574
transaction_id: TransactionHash,
@@ -3153,6 +3155,12 @@ impl HeaderBody {
31533155
#[derive(Clone, Debug, Eq, PartialEq)]
31543156
pub struct AssetName(Vec<u8>);
31553157

3158+
impl Display for AssetName {
3159+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3160+
write!(f, "{}", hex::encode(&self.0))
3161+
}
3162+
}
3163+
31563164
impl Ord for AssetName {
31573165
fn cmp(&self, other: &Self) -> Ordering {
31583166
// Implementing canonical CBOR order for asset names,

rust/src/plutus.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ impl Costmdls {
386386
serializer.finalize()
387387
}
388388

389-
pub(crate) fn retain_language_versions(&self, languages: Vec<Language>) -> Costmdls {
389+
pub fn retain_language_versions(&self, languages: &Languages) -> Costmdls {
390390
let mut result = Costmdls::new();
391-
for lang in languages {
391+
for lang in &languages.0 {
392392
match self.get(&lang) {
393393
Some(costmodel) => { result.insert(&lang, &costmodel); },
394394
_ => {}
@@ -2362,7 +2362,7 @@ mod tests {
23622362
let hash = hash_script_data(
23632363
&redeemers,
23642364
&TxBuilderConstants::plutus_vasil_cost_models()
2365-
.retain_language_versions(vec![Language::new_plutus_v1()]),
2365+
.retain_language_versions(&Languages(vec![Language::new_plutus_v1()])),
23662366
Some(datums),
23672367
);
23682368
assert_eq!(hex::encode(hash.to_bytes()), "e6129f50a866d19d95bc9c95ee87b57a9e695c05d92ba2746141b03c15cf5f70");

0 commit comments

Comments
 (0)