Copyright | © 2018-2021 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
A client used to query asset metadata from the Cardano metadata-server.
The OpenAPI specification is here: https://github.com/input-output-hk/metadata-server/blob/master/specifications/api/openapi.yaml
An important consideration is that cardano-wallet should not trust the metadata-server operator to produce correct, valid, authentic, or even non-malicious data.
In future, signatures of property values will be checked to determine authenticity. The exact details are not yet specified.
In any case, we should not rely on the validation that the metadata-server may or may not have applied to the user-supplied metadata.
Synopsis
- fillMetadata :: ( Foldable t, Functor t) => TokenMetadataClient IO -> t AssetId -> ( Either TokenMetadataError ( Maybe AssetMetadata ) -> AssetId -> a) -> IO (t a)
- data TokenMetadataClient m
- newMetadataClient :: Tracer IO TokenMetadataLog -> Maybe TokenMetadataServer -> IO ( TokenMetadataClient IO )
- getTokenMetadata :: TokenMetadataClient IO -> [ AssetId ] -> IO ( Either TokenMetadataError [( AssetId , AssetMetadata )])
- data TokenMetadataError
- data TokenMetadataLog
- metadataClient :: Tracer IO TokenMetadataLog -> TokenMetadataServer -> Manager -> BatchRequest -> IO ( Either TokenMetadataError BatchResponse )
-
data
BatchRequest
=
BatchRequest
{
- subjects :: [ Subject ]
- properties :: [ PropertyName ]
- newtype BatchResponse = BatchResponse { }
- data SubjectProperties = SubjectProperties { }
-
data
Property
name =
Property
{
- value :: Either ( String , Value ) ( PropertyValue name)
- signatures :: [ Signature ]
- sequenceNumber :: Int
- newtype PropertyName = PropertyName { }
- propertyName :: forall name. KnownSymbol name => Property name -> PropertyName
- type family PropertyValue (name :: Symbol ) :: Type
- newtype Subject = Subject { }
- data Signature = Signature { }
- metadataFromProperties :: SubjectProperties -> Maybe AssetMetadata
Associating metadata with assets
fillMetadata :: ( Foldable t, Functor t) => TokenMetadataClient IO -> t AssetId -> ( Either TokenMetadataError ( Maybe AssetMetadata ) -> AssetId -> a) -> IO (t a) Source #
Helper for adding metadata to sets of assets.
Token Metadata Client
data TokenMetadataClient m Source #
Represents a client for the metadata server.
:: Tracer IO TokenMetadataLog |
Logging |
-> Maybe TokenMetadataServer |
URL of metadata server, if enabled. |
-> IO ( TokenMetadataClient IO ) |
Construct a
TokenMetadataClient
for use with
getTokenMetadata
.
getTokenMetadata :: TokenMetadataClient IO -> [ AssetId ] -> IO ( Either TokenMetadataError [( AssetId , AssetMetadata )]) Source #
Fetches metadata for a list of assets using the given client.
data TokenMetadataError Source #
The possible errors which can occur when fetching metadata.
TokenMetadataClientError ( LoggedException SomeException ) |
Unhandled exception |
TokenMetadataFetchError ( LoggedException HttpException ) |
Error with HTTP request |
TokenMetadataJSONParseError ByteString String |
Error from aeson decoding of JSON |
Instances
Logging
data TokenMetadataLog Source #
Instances
Eq TokenMetadataLog Source # | |
Defined in Cardano.Wallet.TokenMetadata (==) :: TokenMetadataLog -> TokenMetadataLog -> Bool Source # (/=) :: TokenMetadataLog -> TokenMetadataLog -> Bool Source # |
|
Show TokenMetadataLog Source # | |
Defined in Cardano.Wallet.TokenMetadata |
|
ToText TokenMetadataLog Source # | |
Defined in Cardano.Wallet.TokenMetadata toText :: TokenMetadataLog -> Text Source # |
|
HasPrivacyAnnotation TokenMetadataLog Source # | |
Defined in Cardano.Wallet.TokenMetadata getPrivacyAnnotation :: TokenMetadataLog -> PrivacyAnnotation |
|
HasSeverityAnnotation TokenMetadataLog Source # | |
Defined in Cardano.Wallet.TokenMetadata getSeverityAnnotation :: TokenMetadataLog -> Severity |
Generic metadata server client
metadataClient :: Tracer IO TokenMetadataLog -> TokenMetadataServer -> Manager -> BatchRequest -> IO ( Either TokenMetadataError BatchResponse ) Source #
data BatchRequest Source #
Models a request to the
POST
metadata
query
endpoint of the metadata
server -- the only one that we need.
BatchRequest | |
|
Instances
newtype BatchResponse Source #
Models the response from the
POST
metadata
query
endpoint of the
metadata server. This should contain properties each subject in the
BatchRequest
.
Instances
data SubjectProperties Source #
Property values and signatures for a given subject.
Instances
A property value and its signatures.
Property | |
|
Instances
Eq ( PropertyValue name) => Eq ( Property name) Source # | |
Show ( PropertyValue name) => Show ( Property name) Source # | |
Generic ( Property name) Source # | |
ToJSON ( PropertyValue name) => ToJSON ( Property name) Source # | |
(HasValidator name, FromJSON ( PropertyValue name)) => FromJSON ( Property name) Source # | |
type Rep ( Property name) Source # | |
Defined in Cardano.Wallet.TokenMetadata
type
Rep
(
Property
name) =
D1
('
MetaData
"Property" "Cardano.Wallet.TokenMetadata" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" '
False
) (
C1
('
MetaCons
"Property" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"value") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
(
Either
(
String
,
Value
) (
PropertyValue
name)))
:*:
(
S1
('
MetaSel
('
Just
"signatures") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
[
Signature
])
:*:
S1
('
MetaSel
('
Just
"sequenceNumber") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
Int
))))
|
newtype PropertyName Source #
Metadata property identifier.
Instances
propertyName :: forall name. KnownSymbol name => Property name -> PropertyName Source #
type family PropertyValue (name :: Symbol ) :: Type Source #
The type of a given property name.
Instances
type PropertyValue "decimals" Source # | |
Defined in Cardano.Wallet.TokenMetadata |
|
type PropertyValue "description" Source # | |
Defined in Cardano.Wallet.TokenMetadata |
|
type PropertyValue "logo" Source # | |
Defined in Cardano.Wallet.TokenMetadata |
|
type PropertyValue "name" Source # | |
Defined in Cardano.Wallet.TokenMetadata |
|
type PropertyValue "ticker" Source # | |
Defined in Cardano.Wallet.TokenMetadata |
|
type PropertyValue "url" Source # | |
Defined in Cardano.Wallet.TokenMetadata |
A metadata server subject, which can be any string.
Instances
Eq Subject Source # | |
Ord Subject Source # | |
Defined in Cardano.Wallet.TokenMetadata |
|
Show Subject Source # | |
IsString Subject Source # | |
Defined in Cardano.Wallet.TokenMetadata fromString :: String -> Subject Source # |
|
Generic Subject Source # | |
Hashable Subject Source # | |
ToJSON Subject Source # | |
FromJSON Subject Source # | |
type Rep Subject Source # | |
Defined in Cardano.Wallet.TokenMetadata |
Will be used in future for checking integrity and authenticity of metadata.
Instances
Eq Signature Source # | |
Show Signature Source # | |
Generic Signature Source # | |
ToJSON Signature Source # | |
FromJSON Signature Source # | |
type Rep Signature Source # | |
Defined in Cardano.Wallet.TokenMetadata
type
Rep
Signature
=
D1
('
MetaData
"Signature" "Cardano.Wallet.TokenMetadata" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" '
False
) (
C1
('
MetaCons
"Signature" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"signature") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
ByteString
)
:*:
S1
('
MetaSel
('
Just
"publicKey") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
ByteString
)))
|
Parsing
metadataFromProperties :: SubjectProperties -> Maybe AssetMetadata Source #
Convert metadata server properties response into an
AssetMetadata
record.
Only the values are taken. Signatures are ignored (for now).