Skip to content

Commit a287615

Browse files
authored
Merge branch 'master' into cddl-update-collateral-params
2 parents 625da85 + 4a67375 commit a287615

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
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": "9.1.2",
3+
"version": "9.1.3",
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; 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 = "9.1.2"
3+
version = "9.1.3"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"

rust/src/metadata.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,21 +610,26 @@ impl cbor_event::se::Serialize for MetadataMap {
610610
impl Deserialize for MetadataMap {
611611
fn deserialize<R: BufRead + Seek>(raw: &mut Deserializer<R>) -> Result<Self, DeserializeError> {
612612
let mut table = LinkedHashMap::new();
613+
let mut entries: Vec<(TransactionMetadatum, TransactionMetadatum)> = Vec::new();
613614
(|| -> Result<_, DeserializeError> {
614615
let len = raw.map()?;
615-
while match len { cbor_event::Len::Len(n) => table.len() < n as usize, cbor_event::Len::Indefinite => true, } {
616+
while match len { cbor_event::Len::Len(n) => entries.len() < n as usize, cbor_event::Len::Indefinite => true, } {
616617
if raw.cbor_type()? == CBORType::Special {
617618
assert_eq!(raw.special()?, CBORSpecial::Break);
618619
break;
619620
}
620621
let key = TransactionMetadatum::deserialize(raw)?;
621622
let value = TransactionMetadatum::deserialize(raw)?;
622-
if table.insert(key.clone(), value).is_some() {
623-
return Err(DeserializeFailure::DuplicateKey(Key::Str(String::from("some complicated/unsupported type"))).into());
624-
}
623+
entries.push((key.clone(), value));
625624
}
626625
Ok(())
627626
})().map_err(|e| e.annotate("MetadataMap"))?;
627+
entries.iter().for_each(|(k, v)| {
628+
if table.insert(k.clone(), v.clone()).is_some() {
629+
// Turns out this is totally possible on the actual blockchain
630+
// return Err(DeserializeFailure::DuplicateKey(Key::Str(String::from("some complicated/unsupported type"))).into());
631+
}
632+
});
628633
Ok(Self(table))
629634
}
630635
}
@@ -1066,4 +1071,10 @@ mod tests {
10661071
let ad3_deser = AuxiliaryData::from_bytes(aux_data.to_bytes()).unwrap();
10671072
assert_eq!(aux_data.to_bytes(), ad3_deser.to_bytes());
10681073
}
1074+
1075+
#[test]
1076+
fn metadatum_map_duplicate_keys() {
1077+
let bytes = hex::decode("a105a4781b232323232323232323232323232323232323232323232323232323827840232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323237840232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323236e232323232323232323232323232382a36f2323232323232323232323232323236a323030302d30312d303166232323232323784023232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323712323232323232323232323232323232323784023232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323a36f2323232323232323232323232323236a323030302d30312d303166232323232323784023232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323712323232323232323232323232323232323784023232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323752323232323232323232323232323232323232323236a323030302d30312d3031752323232323232323232323232323232323232323236a323030302d30312d3031").unwrap();
1078+
TransactionMetadatum::from_bytes(bytes).unwrap();
1079+
}
10691080
}

0 commit comments

Comments
 (0)