Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data ScriptData
- hashScriptData ∷ ScriptData → Hash ScriptData
- validateScriptData ∷ ScriptData → Either ScriptDataRangeError ()
- data ScriptDataRangeError
- data ScriptDataJsonSchema
- scriptDataFromJson ∷ ScriptDataJsonSchema → Value → Either ScriptDataJsonError ScriptData
- scriptDataToJson ∷ ScriptDataJsonSchema → ScriptData → Value
- data ScriptDataJsonError
- data ScriptDataJsonSchemaError
- = ScriptDataJsonNullNotAllowed
- | ScriptDataJsonBoolNotAllowed
- | ScriptDataJsonNumberNotInteger !Double
- | ScriptDataJsonNotObject !Value
- | ScriptDataJsonBadObject ![(Text, Value)]
- | ScriptDataJsonBadMapPair !Value
- | ScriptDataJsonTypeMismatch !Text !Value
- toZerepochData ∷ ScriptData → Data
- fromZerepochData ∷ Data → ScriptData
- toAurumData ∷ ScriptData → Data ledgerera
- fromAurumData ∷ Data ledgerera → ScriptData
- data family AsType t
- data family Hash keyrole ∷ Type
Script data
data ScriptData Source #
ScriptDataConstructor Integer [ScriptData] | |
ScriptDataMap [(ScriptData, ScriptData)] | |
ScriptDataList [ScriptData] | |
ScriptDataNumber Integer | |
ScriptDataBytes ByteString |
Instances
Script data hashes
Validating metadata
validateScriptData ∷ ScriptData → Either ScriptDataRangeError () Source #
Validate script data. This is for use with existing constructed script data values, e.g. constructed manually or decoded from CBOR directly.
data ScriptDataRangeError Source #
An error in script data due to an out-of-range value.
ScriptDataNumberOutOfRange !Integer | The number is outside the maximum range of |
ScriptDataConstructorOutOfRange !Integer | The number is outside the maximum range of |
ScriptDataBytesTooLong !Int | The length of a byte string metadatum value exceeds the maximum of 64 bytes. |
Instances
Eq ScriptDataRangeError Source # | |
Defined in Bcc.Api.ScriptData | |
Show ScriptDataRangeError Source # | |
Defined in Bcc.Api.ScriptData | |
Error ScriptDataRangeError Source # | |
Defined in Bcc.Api.ScriptData |
Converstion to/from JSON
data ScriptDataJsonSchema Source #
Script data is similar to JSON but not exactly the same. It has some deliberate limitations such as no support for floating point numbers or special forms for null or boolean values. It also has limitations on the length of strings. On the other hand, unlike JSON, it distinguishes between byte strings and text strings. It also supports any value as map keys rather than just string. It also supports alternatives / tagged unions, used for representing constructors for Zerepoch data values.
We provide two different mappings between script data and JSON, useful for different purposes:
- A mapping that allows almost any JSON value to be converted into script data. This does not require a specific JSON schema for the input. It does not expose the full representation capability of script data.
- A mapping that exposes the full representation capability of script data, but relies on a specific JSON schema for the input JSON.
In the "no schema" mapping, the idea is that (almost) any JSON can be turned into script data and then converted back, without loss. That is, we can round-trip the JSON.
The subset of JSON supported is all JSON except: * No null or bool values * No floating point, only integers in the range of a 64bit signed integer * A limitation on string lengths
The approach for this mapping is to use whichever representation as script data is most compact. In particular:
- JSON lists and maps represented as CBOR lists and maps
- JSON strings represented as CBOR strings
- JSON hex strings with "0x" prefix represented as CBOR byte strings
- JSON integer numbers represented as CBOR signed or unsigned numbers
- JSON maps with string keys that parse as numbers or hex byte strings, represented as CBOR map keys that are actually numbers or byte strings.
The string length limit depends on whether the hex string representation is used or not. For text strings the limit is 64 bytes for the UTF8 representation of the text string. For byte strings the limit is 64 bytes for the raw byte form (ie not the input hex, but after hex decoding).
In the "detailed schema" mapping, the idea is that we expose the full representation capability of the script data in the form of a JSON schema. This means the full representation is available and can be controlled precisely. It also means any script data can be converted into the JSON and back without loss. That is we can round-trip the script data via the JSON and also round-trip schema-compliant JSON via script data.
ScriptDataJsonNoSchema | Use the "no schema" mapping between JSON and script data as described above. |
ScriptDataJsonDetailedSchema | Use the "detailed schema" mapping between JSON and script data as described above. |
Instances
Eq ScriptDataJsonSchema Source # | |
Defined in Bcc.Api.ScriptData | |
Show ScriptDataJsonSchema Source # | |
Defined in Bcc.Api.ScriptData |
scriptDataFromJson ∷ ScriptDataJsonSchema → Value → Either ScriptDataJsonError ScriptData Source #
Convert a value from JSON into script data, using the given choice of mapping between JSON and script data.
This may fail with a conversion error if the JSON is outside the supported
subset for the chosen mapping. See ScriptDataJsonSchema
for the details.
scriptDataToJson ∷ ScriptDataJsonSchema → ScriptData → Value Source #
Convert a script data value into JSON , using the given choice of mapping between JSON and script data.
This conversion is total but is not necessarily invertible.
See ScriptDataJsonSchema
for the details.
data ScriptDataJsonError Source #
ScriptDataJsonSchemaError !Value !ScriptDataJsonSchemaError | |
ScriptDataRangeError !Value !ScriptDataRangeError |
Instances
Eq ScriptDataJsonError Source # | |
Defined in Bcc.Api.ScriptData | |
Show ScriptDataJsonError Source # | |
Defined in Bcc.Api.ScriptData | |
Error ScriptDataJsonError Source # | |
Defined in Bcc.Api.ScriptData |
data ScriptDataJsonSchemaError Source #
Instances
Internal conversion functions
toZerepochData ∷ ScriptData → Data Source #
fromZerepochData ∷ Data → ScriptData Source #
toAurumData ∷ ScriptData → Data ledgerera Source #
fromAurumData ∷ Data ledgerera → ScriptData Source #
Data family instances
A family of singleton types used in this API to indicate which type to use where it would otherwise be ambiguous or merely unclear.
Values of this type are passed to deserialisation functions for example.
Instances
data family Hash keyrole ∷ Type Source #