Safe Haskell | None |
---|---|
Language | Haskell2010 |
Metadata embedded in transactions
Synopsis
- newtype TxMetadata = TxMetadata {}
- class AsTxMetadata a where
- asTxMetadata :: a -> TxMetadata
- data TxMetadataValue
- makeTransactionMetadata :: Map Word64 TxMetadataValue -> TxMetadata
- mergeTransactionMetadata :: (TxMetadataValue -> TxMetadataValue -> TxMetadataValue) -> TxMetadata -> TxMetadata -> TxMetadata
- metaTextChunks :: Text -> TxMetadataValue
- metaBytesChunks :: ByteString -> TxMetadataValue
- validateTxMetadata :: TxMetadata -> Either [(Word64, TxMetadataRangeError)] ()
- data TxMetadataRangeError
- data TxMetadataJsonSchema
- metadataFromJson :: TxMetadataJsonSchema -> Value -> Either TxMetadataJsonError TxMetadata
- metadataToJson :: TxMetadataJsonSchema -> TxMetadata -> Value
- metadataValueFromJsonNoSchema :: Value -> Either TxMetadataJsonSchemaError TxMetadataValue
- metadataValueToJsonNoSchema :: TxMetadataValue -> Value
- data TxMetadataJsonError
- data TxMetadataJsonSchemaError
- = TxMetadataJsonNullNotAllowed
- | TxMetadataJsonBoolNotAllowed
- | TxMetadataJsonNumberNotInteger !Double
- | TxMetadataJsonNotObject !Value
- | TxMetadataJsonBadObject ![(Text, Value)]
- | TxMetadataJsonBadMapPair !Value
- | TxMetadataJsonTypeMismatch !Text !Value
- toShelleyMetadata :: Map Word64 TxMetadataValue -> Map Word64 Metadatum
- fromShelleyMetadata :: Map Word64 Metadatum -> Map Word64 TxMetadataValue
- toShelleyMetadatum :: TxMetadataValue -> Metadatum
- fromShelleyMetadatum :: Metadatum -> TxMetadataValue
- parseAll :: Parser a -> Text -> Maybe a
- pUnsigned :: Parser Integer
- pSigned :: Parser Integer
- pBytes :: Parser ByteString
- data family AsType t
Types
newtype TxMetadata Source #
Instances
Monoid TxMetadata Source # | |||||
Defined in Cardano.Api.TxMetadata mempty :: TxMetadata Source # mappend :: TxMetadata -> TxMetadata -> TxMetadata Source # mconcat :: [TxMetadata] -> TxMetadata Source # | |||||
Semigroup TxMetadata Source # | Merge metadata maps. When there are clashing entries the left hand side takes precedence. | ||||
Defined in Cardano.Api.TxMetadata (<>) :: TxMetadata -> TxMetadata -> TxMetadata Source # sconcat :: NonEmpty TxMetadata -> TxMetadata Source # stimes :: Integral b => b -> TxMetadata -> TxMetadata Source # | |||||
Show TxMetadata Source # | |||||
Defined in Cardano.Api.TxMetadata | |||||
HasTypeProxy TxMetadata Source # | |||||
Defined in Cardano.Api.TxMetadata
| |||||
SerialiseAsCBOR TxMetadata Source # | |||||
Defined in Cardano.Api.TxMetadata | |||||
Eq TxMetadata Source # | |||||
Defined in Cardano.Api.TxMetadata (==) :: TxMetadata -> TxMetadata -> Bool Source # (/=) :: TxMetadata -> TxMetadata -> Bool Source # | |||||
data AsType TxMetadata Source # | |||||
Defined in Cardano.Api.TxMetadata |
Class
Constructing metadata
data TxMetadataValue Source #
TxMetaMap [(TxMetadataValue, TxMetadataValue)] | |
TxMetaList [TxMetadataValue] | |
TxMetaNumber Integer | |
TxMetaBytes ByteString | |
TxMetaText Text |
Instances
Show TxMetadataValue Source # | |
Defined in Cardano.Api.TxMetadata | |
Eq TxMetadataValue Source # | |
Defined in Cardano.Api.TxMetadata (==) :: TxMetadataValue -> TxMetadataValue -> Bool Source # (/=) :: TxMetadataValue -> TxMetadataValue -> Bool Source # | |
Ord TxMetadataValue Source # | |
Defined in Cardano.Api.TxMetadata compare :: TxMetadataValue -> TxMetadataValue -> Ordering Source # (<) :: TxMetadataValue -> TxMetadataValue -> Bool Source # (<=) :: TxMetadataValue -> TxMetadataValue -> Bool Source # (>) :: TxMetadataValue -> TxMetadataValue -> Bool Source # (>=) :: TxMetadataValue -> TxMetadataValue -> Bool Source # max :: TxMetadataValue -> TxMetadataValue -> TxMetadataValue Source # min :: TxMetadataValue -> TxMetadataValue -> TxMetadataValue Source # |
mergeTransactionMetadata :: (TxMetadataValue -> TxMetadataValue -> TxMetadataValue) -> TxMetadata -> TxMetadata -> TxMetadata Source #
metaTextChunks :: Text -> TxMetadataValue Source #
Create a TxMetadataValue
from a Text
as a list of chunks of an
acceptable size.
metaBytesChunks :: ByteString -> TxMetadataValue Source #
Create a TxMetadataValue
from a ByteString
as a list of chunks of an
accaptable size.
Validating metadata
validateTxMetadata :: TxMetadata -> Either [(Word64, TxMetadataRangeError)] () Source #
Validate transaction metadata. This is for use with existing constructed metadata values, e.g. constructed manually or decoded from CBOR directly.
data TxMetadataRangeError Source #
An error in transaction metadata due to an out-of-range value.
TxMetadataNumberOutOfRange !Integer | The number is outside the maximum range of |
TxMetadataTextTooLong !Int | The length of a text string metadatum value exceeds the maximum of 64 bytes as UTF8. |
TxMetadataBytesTooLong !Int | The length of a byte string metadatum value exceeds the maximum of 64 bytes. |
Instances
Conversion to/from JSON
data TxMetadataJsonSchema Source #
Tx metadata 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.
We provide two different mappings between tx metadata and JSON, useful for different purposes:
- A mapping that allows almost any JSON value to be converted into tx metadata. This does not require a specific JSON schema for the input. It does not expose the full representation capability of tx metadata.
- A mapping that exposes the full representation capability of tx metadata, 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 tx metadata 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 tx metadata 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 tx metadata in the form of a JSON schema. This means the full representation is available and can be controlled precisely. It also means any tx metadata can be converted into the JSON and back without loss. That is we can round-trip the tx metadata via the JSON and also round-trip schema-compliant JSON via tx metadata.
TxMetadataJsonNoSchema | Use the "no schema" mapping between JSON and tx metadata as described above. |
TxMetadataJsonDetailedSchema | Use the "detailed schema" mapping between JSON and tx metadata as described above. |
Instances
Show TxMetadataJsonSchema Source # | |
Defined in Cardano.Api.TxMetadata | |
Eq TxMetadataJsonSchema Source # | |
Defined in Cardano.Api.TxMetadata (==) :: TxMetadataJsonSchema -> TxMetadataJsonSchema -> Bool Source # (/=) :: TxMetadataJsonSchema -> TxMetadataJsonSchema -> Bool Source # |
metadataFromJson :: TxMetadataJsonSchema -> Value -> Either TxMetadataJsonError TxMetadata Source #
Convert a value from JSON into tx metadata, using the given choice of mapping between JSON and tx metadata.
This may fail with a conversion error if the JSON is outside the supported
subset for the chosen mapping. See TxMetadataJsonSchema
for the details.
metadataToJson :: TxMetadataJsonSchema -> TxMetadata -> Value Source #
Convert a tx metadata value into JSON , using the given choice of mapping between JSON and tx metadata.
This conversion is total but is not necessarily invertible.
See TxMetadataJsonSchema
for the details.
metadataValueToJsonNoSchema :: TxMetadataValue -> Value Source #
data TxMetadataJsonError Source #
TxMetadataJsonToplevelNotMap | |
TxMetadataJsonToplevelBadKey !Text | |
TxMetadataJsonSchemaError !Word64 !Value !TxMetadataJsonSchemaError | |
TxMetadataRangeError !Word64 !Value !TxMetadataRangeError |
Instances
data TxMetadataJsonSchemaError Source #
Instances
Internal conversion functions
Shared parsing utils
pBytes :: Parser ByteString 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.