Skip to content

Commit

Permalink
Merge pull request #251 from Emurgo/release/9.1.2
Browse files Browse the repository at this point in the history
Release / 9.1.2
  • Loading branch information
vsubhuman authored Nov 7, 2021
2 parents 7728a29 + 2354cbd commit e875161
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cardano-serialization-lib",
"version": "9.1.1",
"version": "9.1.2",
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
"scripts": {
"rust:build-nodejs": "rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; wasm-pack pack; cd .. && npm run js:flowgen",
Expand All @@ -9,7 +9,7 @@
"rust:build-asm": "rimraf ./rust/pkg && cd rust; wasm-pack build --target=browser --release; wasm-pack pack && npm run asm:build && npm run js:flowgen",
"rust:publish": "cd rust && cargo publish && cd ../",
"asm:build": "./binaryen/bin/wasm2js ./rust/pkg/cardano_serialization_lib_bg.wasm --output ./rust/pkg/cardano_serialization_lib.asm.js && node ./scripts/wasm-to-asm",
"rust:test": "cd rust; cargo test; cd ..",
"rust:test": "(cd rust; cargo test)",
"js:flowgen": "flowgen ./rust/pkg/cardano_serialization_lib.d.ts -o ./rust/pkg/cardano_serialization_lib.js.flow --add-flow-header",
"js:prepublish": "npm run rust:test && rimraf ./publish && cp -r ./rust/pkg ./publish && cp README.md publish/ && cp LICENSE publish/",
"js:publish-nodejs": "npm run rust:build-nodejs && npm run js:prepublish && node ./scripts/publish-helper -nodejs && cd publish && npm publish --access public",
Expand Down
4 changes: 1 addition & 3 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cardano-serialization-lib"
version = "9.1.1"
version = "9.1.2"
edition = "2018"
authors = ["EMURGO"]
license = "MIT"
Expand Down
10 changes: 10 additions & 0 deletions rust/pkg/cardano_serialization_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -4682,11 +4682,21 @@ declare export class Transaction {
*/
witness_set(): TransactionWitnessSet;

/**
* @returns {boolean}
*/
is_valid(): boolean;

/**
* @returns {AuxiliaryData | void}
*/
auxiliary_data(): AuxiliaryData | void;

/**
* @param {boolean} valid
*/
set_is_valid(valid: boolean): void;

/**
* @param {TransactionBody} body
* @param {TransactionWitnessSet} witness_set
Expand Down
2 changes: 2 additions & 0 deletions rust/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum DeserializeFailure {
DuplicateKey(Key),
EndingBreakMissing,
ExpectedNull,
ExpectedBool,
FixedValueMismatch{
found: Key,
expected: Key,
Expand Down Expand Up @@ -95,6 +96,7 @@ impl std::fmt::Display for DeserializeError {
DeserializeFailure::DuplicateKey(key) => write!(f, "Duplicate key: {}", key),
DeserializeFailure::EndingBreakMissing => write!(f, "Missing ending CBOR Break"),
DeserializeFailure::ExpectedNull => write!(f, "Expected null, found other type"),
DeserializeFailure::ExpectedBool => write!(f, "Expected bool, found other type"),
DeserializeFailure::FixedValueMismatch{ found, expected } => write!(f, "Expected fixed value {} found {}", expected, found),
DeserializeFailure::MandatoryFieldMissing(key) => write!(f, "Mandatory field {} not found", key),
DeserializeFailure::Metadata(e) => write!(f, "Metadata error: {:?}", e),
Expand Down
20 changes: 10 additions & 10 deletions rust/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ mod tests {
let linear_fee = LinearFee::new(&to_bignum(500), &to_bignum(2));
assert_eq!(
hex::encode(signed_tx.to_bytes()),
"83a400818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00016f32030aa10081825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840fae5de40c94d759ce13bf9886262159c4f26a289fd192e165995b785259e503f6887bf39dfa23a47cf163784c6eee23f61440e749bc1df3c73975f5231aeda0ff6"
"84a400818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00016f32030aa10081825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840fae5de40c94d759ce13bf9886262159c4f26a289fd192e165995b785259e503f6887bf39dfa23a47cf163784c6eee23f61440e749bc1df3c73975f5231aeda0ff5f6"
);
assert_eq!(
min_fee(&signed_tx, &linear_fee).unwrap().to_str(),
"94002" // todo: compare to Haskell fee to make sure the diff is not too big
"94502" // todo: compare to Haskell fee to make sure the diff is not too big
);
}

Expand Down Expand Up @@ -128,11 +128,11 @@ mod tests {
let linear_fee = LinearFee::new(&to_bignum(500), &to_bignum(2));
assert_eq!(
hex::encode(signed_tx.to_bytes()),
"83a400818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a0001b582030aa10281845820473811afd4d939b337c9be1a2ceeb2cb2c75108bddf224c5c21c51592a7b204a5840f0b04a852353eb23b9570df80b2aa6a61b723341ab45a2024a05b07cf58be7bdfbf722c09040db6cee61a0d236870d6ad1e1349ac999ec0db28f9471af25fb0c5820c8b95d0d35fe75a70f9f5633a3e2439b2994b9e2bc851c49e9f91d1a5dcbb1a341a0f6"
"84a400818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a0001b582030aa10281845820473811afd4d939b337c9be1a2ceeb2cb2c75108bddf224c5c21c51592a7b204a5840f0b04a852353eb23b9570df80b2aa6a61b723341ab45a2024a05b07cf58be7bdfbf722c09040db6cee61a0d236870d6ad1e1349ac999ec0db28f9471af25fb0c5820c8b95d0d35fe75a70f9f5633a3e2439b2994b9e2bc851c49e9f91d1a5dcbb1a341a0f5f6"
);
assert_eq!(
min_fee(&signed_tx, &linear_fee).unwrap().to_str(),
"112002" // todo: compare to Haskell fee to make sure the diff is not too big
"112502" // todo: compare to Haskell fee to make sure the diff is not too big
);
}

Expand Down Expand Up @@ -198,11 +198,11 @@ mod tests {
let linear_fee = LinearFee::new(&to_bignum(500), &to_bignum(2));
assert_eq!(
hex::encode(signed_tx.to_bytes()),
"83a400828258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7182a82582082839f8200d81858248258203b40265111d8bb3c3c608d95b3a0bf83461ace3207018282581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c19012182581d61bcd18fcffa797c16c007014e2b8553b8b9b1e94c507688726243d6111a3420989c021a0002ccce031903e7a10082825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee58401ec3e56008650282ba2e1f8a20e81707810b2d0973c4d42a1b4df65b732bda81567c7824904840b2554d2f33861da5d70588a29d33b2b61042e3c3445301d8008258206872b0a874acfe1cace12b20ea348559a7ecc912f2fc7f674f43481df973d92c5840a0718fb5b37d89ddf926c08e456d3f4c7f749e91f78bb3e370751d5b632cbd20d38d385805291b1ef2541b02543728a235e01911f4b400bfb50e5fce589de907f6"
"84a400828258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7182a82582082839f8200d81858248258203b40265111d8bb3c3c608d95b3a0bf83461ace3207018282581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c19012182581d61bcd18fcffa797c16c007014e2b8553b8b9b1e94c507688726243d6111a3420989c021a0002ccce031903e7a10082825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee58401ec3e56008650282ba2e1f8a20e81707810b2d0973c4d42a1b4df65b732bda81567c7824904840b2554d2f33861da5d70588a29d33b2b61042e3c3445301d8008258206872b0a874acfe1cace12b20ea348559a7ecc912f2fc7f674f43481df973d92c5840a0718fb5b37d89ddf926c08e456d3f4c7f749e91f78bb3e370751d5b632cbd20d38d385805291b1ef2541b02543728a235e01911f4b400bfb50e5fce589de907f5f6"
);
assert_eq!(
min_fee(&signed_tx, &linear_fee).unwrap().to_str(),
"183502" // todo: compare to Haskell fee to make sure the diff is not too big
"184002" // todo: compare to Haskell fee to make sure the diff is not too big
);
}

Expand Down Expand Up @@ -294,11 +294,11 @@ mod tests {
let linear_fee = LinearFee::new(&to_bignum(500), &to_bignum(2));
assert_eq!(
hex::encode(signed_tx.to_bytes()),
"83a500818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00040f12030a04818a03581c1c13374874c68016df54b1339b6cacdd801098431e7659b24928efc15820bd0000f498ccacdc917c28274cba51c415f3f21931ff41ca8dc1197499f8e1241a000f42401a000f4240d81e82031864581de151df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af7081581c51df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af7080f6a10083825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840a7f305d7e46abfe0f7bea6098bdf853ab9ce8e7aa381be5a991a871852f895a718e20614e22be43494c4dc3a8c78c56cd44fd38e0e5fff3e2fbd19f70402fc02825820b24c040e65994bd5b0621a060166d32d356ef4be3cc1f848426a4cf386887089584013c372f82f1523484eab273241d66d92e1402507760e279480912aa5f0d88d656d6f25d41e65257f2f38c65ac5c918a6735297741adfc718394994f20a1cfd0082582054d1a9c5ad69586ceeb839c438400c376c0bd34825fb4c17cc2f58c54e1437f35840d326b993dfec21b9b3e1bd2f80adadc2cd673a1d8d033618cc413b0b02bc3b7efbb23d1ff99138abd05c398ce98e7983a641b50dcf0f64ed33f26c6e636b0b0ff6"
"84a500818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00040f12030a04818a03581c1c13374874c68016df54b1339b6cacdd801098431e7659b24928efc15820bd0000f498ccacdc917c28274cba51c415f3f21931ff41ca8dc1197499f8e1241a000f42401a000f4240d81e82031864581de151df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af7081581c51df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af7080f6a10083825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840a7f305d7e46abfe0f7bea6098bdf853ab9ce8e7aa381be5a991a871852f895a718e20614e22be43494c4dc3a8c78c56cd44fd38e0e5fff3e2fbd19f70402fc02825820b24c040e65994bd5b0621a060166d32d356ef4be3cc1f848426a4cf386887089584013c372f82f1523484eab273241d66d92e1402507760e279480912aa5f0d88d656d6f25d41e65257f2f38c65ac5c918a6735297741adfc718394994f20a1cfd0082582054d1a9c5ad69586ceeb839c438400c376c0bd34825fb4c17cc2f58c54e1437f35840d326b993dfec21b9b3e1bd2f80adadc2cd673a1d8d033618cc413b0b02bc3b7efbb23d1ff99138abd05c398ce98e7983a641b50dcf0f64ed33f26c6e636b0b0ff5f6"
);
assert_eq!(
min_fee(&signed_tx, &linear_fee).unwrap().to_str(),
"269002" // todo: compare to Haskell fee to make sure the diff is not too big
"269502" // todo: compare to Haskell fee to make sure the diff is not too big
);
}

Expand Down Expand Up @@ -488,11 +488,11 @@ mod tests {
let linear_fee = LinearFee::new(&to_bignum(500), &to_bignum(2));
assert_eq!(
hex::encode(signed_tx.to_bytes()),
"83a500818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00027ac6030a05a1581de151df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af70190539a10082825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840fc0493f7121efe385d72830680e735ccdef99c3a31953fe877b89ad3a97fcdb871cc7f2cdd6a8104e52f6963bd9e10d814d4fabdbcdc8475bc63e872dcc94d0a82582054d1a9c5ad69586ceeb839c438400c376c0bd34825fb4c17cc2f58c54e1437f35840a051ba927582004aedab736b9f1f9330ff867c260f4751135d480074256e83cd23d2a4bb109f955c43afdcdc5d1841b28d5c1ea2148dfbb6252693590692bb00f6"
"84a500818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00027ac6030a05a1581de151df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af70190539a10082825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840fc0493f7121efe385d72830680e735ccdef99c3a31953fe877b89ad3a97fcdb871cc7f2cdd6a8104e52f6963bd9e10d814d4fabdbcdc8475bc63e872dcc94d0a82582054d1a9c5ad69586ceeb839c438400c376c0bd34825fb4c17cc2f58c54e1437f35840a051ba927582004aedab736b9f1f9330ff867c260f4751135d480074256e83cd23d2a4bb109f955c43afdcdc5d1841b28d5c1ea2148dfbb6252693590692bb00f5f6"
);
assert_eq!(
min_fee(&signed_tx, &linear_fee).unwrap().to_str(),
"162502" // todo: compare to Haskell fee to make sure the diff is not too big
"163002" // todo: compare to Haskell fee to make sure the diff is not too big
);
}
}
10 changes: 10 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type Slot = u32;
pub struct Transaction {
body: TransactionBody,
witness_set: TransactionWitnessSet,
is_valid: bool,
auxiliary_data: Option<AuxiliaryData>,
}

Expand All @@ -113,10 +114,18 @@ impl Transaction {
self.witness_set.clone()
}

pub fn is_valid(&self) -> bool {
self.is_valid.clone()
}

pub fn auxiliary_data(&self) -> Option<AuxiliaryData> {
self.auxiliary_data.clone()
}

pub fn set_is_valid(&mut self, valid: bool) {
self.is_valid = valid
}

pub fn new(
body: &TransactionBody,
witness_set: &TransactionWitnessSet,
Expand All @@ -125,6 +134,7 @@ impl Transaction {
Self {
body: body.clone(),
witness_set: witness_set.clone(),
is_valid: true,
auxiliary_data: auxiliary_data.clone(),
}
}
Expand Down
51 changes: 41 additions & 10 deletions rust/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ impl DeserializeEmbeddedGroup for UnitInterval {

impl cbor_event::se::Serialize for Transaction {
fn serialize<'se, W: Write>(&self, serializer: &'se mut Serializer<W>) -> cbor_event::Result<&'se mut Serializer<W>> {
serializer.write_array(cbor_event::Len::Len(3))?;
serializer.write_array(cbor_event::Len::Len(4))?;
self.body.serialize(serializer)?;
self.witness_set.serialize(serializer)?;
serializer.write_special(CBORSpecial::Bool(self.is_valid))?;
match &self.auxiliary_data {
Some(x) => {
x.serialize(serializer)
Expand Down Expand Up @@ -94,22 +95,52 @@ impl DeserializeEmbeddedGroup for Transaction {
let witness_set = (|| -> Result<_, DeserializeError> {
Ok(TransactionWitnessSet::deserialize(raw)?)
})().map_err(|e| e.annotate("witness_set"))?;
let auxiliary_data = (|| -> Result<_, DeserializeError> {
Ok(match raw.cbor_type()? != CBORType::Special {
let mut checked_auxiliary_data = false;
let mut auxiliary_data = None;
let is_valid = (|| -> Result<_, DeserializeError> {
match raw.cbor_type()? == CBORType::Special {
true => {
Some(AuxiliaryData::deserialize(raw)?)
// if it's special it can be either a bool or null. if it's null, then it's empty auxiliary data, otherwise not a valid encoding
let special = raw.special()?;
if let CBORSpecial::Bool(b) = special {
return Ok(b);
} else if special == CBORSpecial::Null {
checked_auxiliary_data = true;
return Ok(true);
} else {
return Err(DeserializeFailure::ExpectedBool.into());
}
},
false => {
if raw.special()? != CBORSpecial::Null {
return Err(DeserializeFailure::ExpectedNull.into());
}
None
// if no special symbol was detected, it must have auxiliary data
auxiliary_data = (|| -> Result<_, DeserializeError> {
Ok(Some(AuxiliaryData::deserialize(raw)?))
})().map_err(|e| e.annotate("auxiliary_data"))?;
checked_auxiliary_data = true;
return Ok(true);
}
})
})().map_err(|e| e.annotate("auxiliary_data"))?;
}
})().map_err(|e| e.annotate("is_valid"))?;
if (!checked_auxiliary_data) {
// this branch is reached, if the 3rd argument was a bool. then it simply follows the rules for checking auxiliary data
auxiliary_data = (|| -> Result<_, DeserializeError> {
Ok(match raw.cbor_type()? != CBORType::Special {
true => {
Some(AuxiliaryData::deserialize(raw)?)
},
false => {
if raw.special()? != CBORSpecial::Null {
return Err(DeserializeFailure::ExpectedNull.into());
}
None
}
})
})().map_err(|e| e.annotate("auxiliary_data"))?;
}
Ok(Transaction {
body,
witness_set,
is_valid,
auxiliary_data,
})
}
Expand Down
Loading

0 comments on commit e875161

Please sign in to comment.