Copyright | (c) 2024 GYELD GMBH |
---|---|
License | Apache 2.0 |
Maintainer | [email protected] |
Stability | develop |
Safe Haskell | None |
Language | GHC2021 |
GeniusYield.Types.TxMetadata
Description
Transaction metadata types and functions for working with transaction metadata.
Synopsis
- newtype GYTxMetadata = GYTxMetadata (Map Word64 GYTxMetadataValue)
- txMetadataFromApi :: TxMetadata -> GYTxMetadata
- txMetadataToApi :: GYTxMetadata -> TxMetadata
- data GYTxMetadataValue
- txMetadataValueToApi :: GYTxMetadataValue -> TxMetadataValue
- txMetadataValueFromApi :: TxMetadataValue -> GYTxMetadataValue
- constructTxMetadataMap :: [(GYTxMetadataValue, GYTxMetadataValue)] -> GYTxMetadataValue
- constructTxMetadataList :: [GYTxMetadataValue] -> GYTxMetadataValue
- constructTxMetadataNumber :: Integer -> Maybe GYTxMetadataValue
- constructTxMetadataBytes :: ByteString -> Maybe GYTxMetadataValue
- constructTxMetadataText :: Text -> Maybe GYTxMetadataValue
- constructTxMetadataBytesChunks :: ByteString -> GYTxMetadataValue
- constructTxMetadataTextChunks :: Text -> GYTxMetadataValue
- mergeTxMetadata :: (GYTxMetadataValue -> GYTxMetadataValue -> GYTxMetadataValue) -> GYTxMetadata -> GYTxMetadata -> GYTxMetadata
- metadataMsg :: Text -> Maybe GYTxMetadata
- metadataMsgs :: [Text] -> Maybe GYTxMetadata
Documentation
newtype GYTxMetadata #
Constructors
GYTxMetadata (Map Word64 GYTxMetadataValue) |
Instances
Semigroup GYTxMetadata # | |
Defined in GeniusYield.Types.TxMetadata Methods (<>) :: GYTxMetadata -> GYTxMetadata -> GYTxMetadata # sconcat :: NonEmpty GYTxMetadata -> GYTxMetadata # stimes :: Integral b => b -> GYTxMetadata -> GYTxMetadata # | |
Show GYTxMetadata # | |
Defined in GeniusYield.Types.TxMetadata Methods showsPrec :: Int -> GYTxMetadata -> ShowS # show :: GYTxMetadata -> String # showList :: [GYTxMetadata] -> ShowS # | |
Eq GYTxMetadata # | |
Defined in GeniusYield.Types.TxMetadata |
data GYTxMetadataValue #
A value in the transaction metadata.
Instances
Show GYTxMetadataValue # | |
Defined in GeniusYield.Types.TxMetadata.Internal Methods showsPrec :: Int -> GYTxMetadataValue -> ShowS # show :: GYTxMetadataValue -> String # showList :: [GYTxMetadataValue] -> ShowS # | |
Eq GYTxMetadataValue # | |
Defined in GeniusYield.Types.TxMetadata.Internal Methods (==) :: GYTxMetadataValue -> GYTxMetadataValue -> Bool # (/=) :: GYTxMetadataValue -> GYTxMetadataValue -> Bool # | |
Ord GYTxMetadataValue # | |
Defined in GeniusYield.Types.TxMetadata.Internal Methods compare :: GYTxMetadataValue -> GYTxMetadataValue -> Ordering # (<) :: GYTxMetadataValue -> GYTxMetadataValue -> Bool # (<=) :: GYTxMetadataValue -> GYTxMetadataValue -> Bool # (>) :: GYTxMetadataValue -> GYTxMetadataValue -> Bool # (>=) :: GYTxMetadataValue -> GYTxMetadataValue -> Bool # max :: GYTxMetadataValue -> GYTxMetadataValue -> GYTxMetadataValue # min :: GYTxMetadataValue -> GYTxMetadataValue -> GYTxMetadataValue # |
constructTxMetadataMap :: [(GYTxMetadataValue, GYTxMetadataValue)] -> GYTxMetadataValue #
Construct a GYTxMetadataValue
from a list of key-value pairs.
constructTxMetadataList :: [GYTxMetadataValue] -> GYTxMetadataValue #
Construct a GYTxMetadataValue
from a list of GYTxMetadataValue
s.
constructTxMetadataNumber :: Integer -> Maybe GYTxMetadataValue #
Construct a GYTxMetadataValue
from an Integer
. Returning Nothing
if the given Integer
is not in the range -(2^64-1) .. 2^64-1
.
constructTxMetadataBytes :: ByteString -> Maybe GYTxMetadataValue #
Construct a GYTxMetadataValue
from a ByteString
. Returning Nothing
if the given ByteString
is longer than 64 bytes.
constructTxMetadataText :: Text -> Maybe GYTxMetadataValue #
Construct a GYTxMetadataValue
from a Text
. Returning Nothing
if the given Text
is longer than 64 bytes when UTF-8 encoded.
constructTxMetadataBytesChunks :: ByteString -> GYTxMetadataValue #
Construct a GYTxMetadataValue
from a ByteString
as a list of chunks (bytestrings) of acceptable sizes, splitting at 64th byte as maximum length allowed is 64 bytes.
constructTxMetadataTextChunks :: Text -> GYTxMetadataValue #
Construct a GYTxMetadataValue
from a Text
as a list of chunks (strings) of acceptable sizes. Note that maximum length allowed is 64 bytes, when given string is UTF-8 encoded. Splitting is slightly involved here as single character (in a text string) may be represented by multiple bytes in UTF-8 encoding, and hence, we split if adding the byte representation of the char exceeds the 64 byte limit.
mergeTxMetadata :: (GYTxMetadataValue -> GYTxMetadataValue -> GYTxMetadataValue) -> GYTxMetadata -> GYTxMetadata -> GYTxMetadata #
Merge two GYTxMetadata
s, controlling how to handle the respective GYTxMetadataValue
s in case of label collision.
metadataMsg :: Text -> Maybe GYTxMetadata #
Adds a single message (comment/memo) as transaction metadata following CIP 020 specification.
See metadataMsgs
for examples.
metadataMsgs :: [Text] -> Maybe GYTxMetadata #
Adds multiple messages (comments/memos) as transaction metadata following CIP 020 specification.
>>>
metadataMsgs ["Hello, World!", "This is a test message."]
Just (fromList [(674,GYTxMetaMap [(GYTxMetaText "msg",GYTxMetaList [GYTxMetaText "Hello, World!",GYTxMetaText "This is a test message."])])])
>>>
metadataMsgs [""]
Nothing
>>>
metadataMsgs []
Nothing
>>>
metadataMsgs ["Hello, World!", "This one is a reaaaaaaaally long message, so long that it exceeds the 64 byte limit, so it will be split into multiple chunks.", "do you see that?"]
Just (fromList [(674,GYTxMetaMap [(GYTxMetaText "msg",GYTxMetaList [GYTxMetaText "Hello, World!",GYTxMetaText "This one is a reaaaaaaaally long message, so long that it exceed",GYTxMetaText "s the 64 byte limit, so it will be split into multiple chunks.",GYTxMetaText "do you see that?"])])])