Serialize/Deserialize unsorted maps separately from PlutusData#1
Open
MitchyCola wants to merge 7 commits intoIndigoProtocol:masterfrom
Open
Serialize/Deserialize unsorted maps separately from PlutusData#1MitchyCola wants to merge 7 commits intoIndigoProtocol:masterfrom
PlutusData#1MitchyCola wants to merge 7 commits intoIndigoProtocol:masterfrom
Conversation
6bd5502 to
ab06dae
Compare
KristianBalaj
approved these changes
Dec 21, 2022
Author
|
Right, I will fix that. I just quickly replaced all instances of the authors. I will wait to merge this in until @codybutz creates an NPM account for Indigo that we can upload this to. Then I can also update downstream dependencies. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CSL uses
BTreeMapin it's default implementation for serializing/deserializing CBOR maps from/toPlutusMap. Lexicographically ordered keys are an invariant property ofBTreeMap. This has an adverse effect on smart contracts that expect datums that contain unsorted maps, where the smart contract would need to sort the map in order to perform validation. This would waste onchain resources for unnecessary computation.IndexMappreserves the order of insertion and, therefore, can be used to simulate the behavior of Plutus's associative map. Since theOrdtrait cannot be derived forIndexMap, it could not be included in a constructor forPlutusDataEnum. The data typePlutusDatumMapwas created so that anIndexMapcan be serialized/deserialized independent ofPlutusData.After separate serialization of a
PlutusDatumMap, the CBOR can be added into thePlutusDatastructure by usingPlutusData::new_datum_map. And for deserialization, the CBOR for the map can taken by usingPlutusData::as_original_bytesand can then be separately deserialized intoPlutusDatumMapwhere an FFI program can unpack the items that are contained in thePlutusDatumMap.