Skip to content

Commit 0fee459

Browse files
authored
Merge branch 'master' into evgenii/non-protocol-entities-json
2 parents 0b0dce5 + 8b0a2b2 commit 0fee459

11 files changed

+246
-31
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cardano-serialization-lib",
3-
"version": "11.0.0",
3+
"version": "11.0.5",
44
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
55
"scripts": {
66
"rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; cd ..; npm run js:ts-json-gen; cd rust; wasm-pack pack) && npm run js:flowgen",

rust/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cardano-serialization-lib"
3-
version = "11.0.0"
3+
version = "11.0.5"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"

rust/json-gen/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/pkg/cardano_serialization_lib.js.flow

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,13 @@ declare export class BigNum {
10591059
* @returns {boolean}
10601060
*/
10611061
less_than(rhs_value: BigNum): boolean;
1062+
1063+
/**
1064+
* @param {BigNum} a
1065+
* @param {BigNum} b
1066+
* @returns {BigNum}
1067+
*/
1068+
static max(a: BigNum, b: BigNum): BigNum;
10621069
}
10631070
/**
10641071
*/

rust/src/fakes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#![allow(dead_code)]
2-
use crate::{
3-
to_bignum, Address, BaseAddress, Bip32PrivateKey, DataHash, Ed25519KeyHash, Ed25519Signature,
4-
NetworkInfo, StakeCredential, TransactionHash, TransactionIndex, TransactionInput,
5-
TransactionOutput, Value, Vkey,
6-
};
2+
use crate::{to_bignum, Address, BaseAddress, Bip32PrivateKey, DataHash, Ed25519KeyHash, Ed25519Signature, NetworkInfo, StakeCredential, TransactionHash, TransactionIndex, TransactionInput, TransactionOutput, Value, Vkey, PolicyID};
73

84
pub(crate) fn fake_bytes_32(x: u8) -> Vec<u8> {
95
vec![
@@ -69,3 +65,7 @@ pub(crate) fn fake_vkey() -> Vkey {
6965
pub(crate) fn fake_signature(x: u8) -> Ed25519Signature {
7066
Ed25519Signature::from_bytes([x; 64].to_vec()).unwrap()
7167
}
68+
69+
pub(crate) fn fake_policy_id(x: u8) -> PolicyID {
70+
PolicyID::from([x; 28])
71+
}

rust/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ impl DataCost {
256256
}
257257
}
258258
}
259+
260+
// <TODO:REMOVE_AFTER_BABBAGE>
261+
pub(crate) fn coins_per_word(&self) -> Result<Coin, JsError> {
262+
match &self.0 {
263+
DataCostEnum::CoinsPerByte(coins_per_byte) => {
264+
coins_per_byte
265+
.checked_mul(&BigNum::from_str("8")?)
266+
},
267+
DataCostEnum::CoinsPerWord(coins_per_word) => Ok(coins_per_word.clone()),
268+
}
269+
}
259270
}
260271

261272
#[wasm_bindgen]

rust/src/plutus.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,17 @@ impl Costmdls {
385385
}
386386
serializer.finalize()
387387
}
388+
389+
pub(crate) fn retain_language_versions(&self, languages: Vec<Language>) -> Costmdls {
390+
let mut result = Costmdls::new();
391+
for lang in languages {
392+
match self.get(&lang) {
393+
Some(costmodel) => { result.insert(&lang, &costmodel); },
394+
_ => {}
395+
}
396+
}
397+
result
398+
}
388399
}
389400

390401
#[wasm_bindgen]
@@ -1909,6 +1920,7 @@ impl Deserialize for Strings {
19091920
mod tests {
19101921
use super::*;
19111922
use hex::*;
1923+
use crate::tx_builder_constants::TxBuilderConstants;
19121924

19131925
#[test]
19141926
pub fn plutus_constr_data() {
@@ -2074,6 +2086,7 @@ mod tests {
20742086
assert_eq!(datum, datum2);
20752087
}
20762088

2089+
#[test]
20772090
pub fn test_cost_model() {
20782091
let arr = vec![
20792092
197209, 0, 1, 1, 396231, 621, 0, 1, 150000, 1000, 0, 1, 150000, 32, 2477736, 29175, 4,
@@ -2294,4 +2307,64 @@ mod tests {
22942307
"816cdf6d4d8cba3ad0188ca643db95ddf0e03cdfc0e75a9550a72a82cb146222"
22952308
);
22962309
}
2310+
2311+
#[test]
2312+
fn test_known_plutus_data_hash_with_no_datums() {
2313+
let mut costmodels = Costmdls::new();
2314+
costmodels.insert(
2315+
&Language::new_plutus_v2(),
2316+
&TxBuilderConstants::plutus_vasil_cost_models().get(&Language::new_plutus_v2()).unwrap(),
2317+
);
2318+
let hash = hash_script_data(
2319+
&Redeemers(vec![
2320+
Redeemer::new(
2321+
&RedeemerTag::new_spend(),
2322+
&BigNum::zero(),
2323+
&PlutusData::new_empty_constr_plutus_data(&BigNum::zero()),
2324+
&ExUnits::new(&to_bignum(842996), &to_bignum(246100241)),
2325+
),
2326+
]),
2327+
&costmodels,
2328+
None,
2329+
);
2330+
assert_eq!(hex::encode(hash.to_bytes()), "ac71f2adcaecd7576fa658098b12001dec03ce5c27dbb890e16966e3e135b3e2");
2331+
}
2332+
2333+
#[test]
2334+
fn test_known_plutus_data_hash_2() {
2335+
let datums = PlutusList::from(vec![
2336+
PlutusData::new_constr_plutus_data(
2337+
&ConstrPlutusData::new(
2338+
&BigNum::zero(),
2339+
&PlutusList::from(vec![
2340+
PlutusData::new_bytes(
2341+
hex::decode("45F6A506A49A38263C4A8BBB2E1E369DD8732FB1F9A281F3E8838387").unwrap(),
2342+
),
2343+
PlutusData::new_integer(&BigInt::from_str("60000000").unwrap()),
2344+
PlutusData::new_bytes(
2345+
hex::decode("EE8E37676F6EBB8E031DFF493F88FF711D24AA68666A09D61F1D3FB3").unwrap(),
2346+
),
2347+
PlutusData::new_bytes(
2348+
hex::decode("43727970746F44696E6F3036333039").unwrap(),
2349+
),
2350+
]),
2351+
)
2352+
)
2353+
]);
2354+
let redeemers = Redeemers(vec![
2355+
Redeemer::new(
2356+
&RedeemerTag::new_spend(),
2357+
&BigNum::one(),
2358+
&PlutusData::new_empty_constr_plutus_data(&BigNum::one()),
2359+
&ExUnits::new(&to_bignum(61300), &to_bignum(18221176)),
2360+
),
2361+
]);
2362+
let hash = hash_script_data(
2363+
&redeemers,
2364+
&TxBuilderConstants::plutus_vasil_cost_models()
2365+
.retain_language_versions(vec![Language::new_plutus_v1()]),
2366+
Some(datums),
2367+
);
2368+
assert_eq!(hex::encode(hash.to_bytes()), "e6129f50a866d19d95bc9c95ee87b57a9e695c05d92ba2746141b03c15cf5f70");
2369+
}
22972370
}

0 commit comments

Comments
 (0)