@@ -320,6 +320,7 @@ instance Error ScriptDataRangeError where
320
320
-- can round-trip the JSON.
321
321
--
322
322
-- The subset of JSON supported is all JSON except:
323
+ --
323
324
-- * No null or bool values
324
325
-- * No floating point, only integers in the range of a 64bit signed integer
325
326
-- * A limitation on string lengths
@@ -345,6 +346,20 @@ instance Error ScriptDataRangeError where
345
346
-- precisely. It also means any script data can be converted into the JSON and
346
347
-- back without loss. That is we can round-trip the script data via the JSON and
347
348
-- also round-trip schema-compliant JSON via script data.
349
+ --
350
+ -- *Warning*: While the JSON representation does round-trip, the CBOR through
351
+ -- JSON does not. When serialising and deserialising 'HashableScriptData'
352
+ -- through JSON e.g:
353
+ -- @
354
+ -- CBOR -> HashableScriptData -> JSON -> HashableScriptData -> CBOR
355
+ -- @
356
+ -- the original CBOR representation is lost and the resulting CBOR *will*
357
+ -- be different resulting in a different script data hash, which is
358
+ -- calculated from CBOR. This is because cardano-ledger does not canonicalise
359
+ -- CBOR representation, so you can have few slightly different serialised
360
+ -- representations of a data structure, which represent the same value.
361
+ --
362
+ -- See: https://github.com/IntersectMBO/cardano-api/issues/612#issuecomment-2701256007
348
363
data ScriptDataJsonSchema
349
364
= -- | Use the \"no schema\" mapping between JSON and script data as
350
365
-- described above.
@@ -507,6 +522,10 @@ scriptDataJsonToHashable schema scriptDataVal = do
507
522
-- JSON conversion using the "detailed schema" style
508
523
--
509
524
525
+ -- | Convert a script data value into JSON using detailed schema.
526
+ --
527
+ -- This conversion is total but is not necessarily invertible.
528
+ -- See 'ScriptDataJsonSchema' for the details.
510
529
scriptDataToJsonDetailedSchema :: HashableScriptData -> Aeson. Value
511
530
scriptDataToJsonDetailedSchema = conv . getScriptData
512
531
where
@@ -538,6 +557,10 @@ scriptDataToJsonDetailedSchema = conv . getScriptData
538
557
539
558
singleFieldObject name v = Aeson. object [(name, v)]
540
559
560
+ -- | Convert a script data value from JSON using detailed schema.
561
+ --
562
+ -- This conversion is total but is not necessarily invertible.
563
+ -- See 'ScriptDataJsonSchema' for the details.
541
564
scriptDataFromJsonDetailedSchema
542
565
:: Aeson. Value
543
566
-> Either
0 commit comments