1+ use std:: hash:: Hash ;
12use super :: * ;
23use std:: io:: { BufRead , Seek , Write } ;
4+ use linked_hash_map:: LinkedHashMap ;
5+ use core:: hash:: Hasher ;
36
47// This library was code-generated using an experimental CDDL to rust tool:
58// https://github.com/Emurgo/cddl-codegen
@@ -208,7 +211,7 @@ impl PlutusScripts {
208211}
209212
210213#[ wasm_bindgen]
211- #[ derive( Clone , Debug , Eq , Ord , PartialEq , PartialOrd , ) ]
214+ #[ derive( Clone , Debug , Eq , Ord , PartialEq , PartialOrd , Hash ) ]
212215pub struct ConstrPlutusData {
213216 alternative : BigNum ,
214217 data : PlutusList ,
@@ -555,15 +558,15 @@ impl Languages {
555558}
556559
557560#[ wasm_bindgen]
558- #[ derive( Clone , Debug , Eq , Ord , PartialEq , PartialOrd , ) ]
559- pub struct PlutusMap ( std :: collections :: BTreeMap < PlutusData , PlutusData > ) ;
561+ #[ derive( Clone , Debug , Eq , Ord , PartialEq , PartialOrd , Hash ) ]
562+ pub struct PlutusMap ( LinkedHashMap < PlutusData , PlutusData > ) ;
560563
561564to_from_bytes ! ( PlutusMap ) ;
562565
563566#[ wasm_bindgen]
564567impl PlutusMap {
565568 pub fn new ( ) -> Self {
566- Self ( std :: collections :: BTreeMap :: new ( ) )
569+ Self ( LinkedHashMap :: new ( ) )
567570 }
568571
569572 pub fn len ( & self ) -> usize {
@@ -597,7 +600,7 @@ pub enum PlutusDataKind {
597600}
598601
599602#[ derive(
600- Clone , Debug , Eq , Ord , PartialEq , PartialOrd ) ]
603+ Clone , Debug , Eq , Ord , PartialEq , PartialOrd , Hash ) ]
601604pub enum PlutusDataEnum {
602605 ConstrPlutusData ( ConstrPlutusData ) ,
603606 Map ( PlutusMap ) ,
@@ -621,6 +624,12 @@ impl std::cmp::PartialEq<Self> for PlutusData {
621624 }
622625}
623626
627+ impl Hash for PlutusData {
628+ fn hash < H : Hasher > ( & self , state : & mut H ) {
629+ self . datum . hash ( state)
630+ }
631+ }
632+
624633impl std:: cmp:: Eq for PlutusData { }
625634
626635to_from_bytes ! ( PlutusData ) ;
@@ -758,7 +767,7 @@ impl <'de> serde::de::Deserialize<'de> for PlutusData {
758767}
759768
760769#[ wasm_bindgen]
761- #[ derive( Clone , Debug , Ord , PartialOrd , serde:: Serialize , serde:: Deserialize , JsonSchema ) ]
770+ #[ derive( Clone , Debug , Ord , PartialOrd , Hash , serde:: Serialize , serde:: Deserialize , JsonSchema ) ]
762771pub struct PlutusList {
763772 elems : Vec < PlutusData > ,
764773 // We should always preserve the original datums when deserialized as this is NOT canonicized
@@ -1624,7 +1633,7 @@ impl cbor_event::se::Serialize for PlutusMap {
16241633
16251634impl Deserialize for PlutusMap {
16261635 fn deserialize < R : BufRead + Seek > ( raw : & mut Deserializer < R > ) -> Result < Self , DeserializeError > {
1627- let mut table = std :: collections :: BTreeMap :: new ( ) ;
1636+ let mut table = LinkedHashMap :: new ( ) ;
16281637 ( || -> Result < _ , DeserializeError > {
16291638 let len = raw. map ( ) ?;
16301639 while match len {
0 commit comments