Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type RelayURL = Text
- newtype EventId =
- EventId
- { getEventId :: ByteString
- }
- deriving (Eq)
- instance Show EventId where
- showsPrec _ = shows . B16.encodeBase16 . getEventId
- instance ToJSON EventId where
- toJSON e = AesonTypes.String $ pack $ exportEventId e
- instance FromJSON EventId where
- parseJSON = withObject "EventId" $ \i -> do
- i' <- i .: "id"
- case eventId' i' of
- Just e -> return e
- _ -> fail "invalid event id"
- eventId' :: Text -> Maybe EventId
- eventId' t = do
- bs <- Schnorr.decodeHex t
- case BS.length bs of
- 32 -> Just $ EventId bs
- _ -> Nothing
- instance FromJSON XOnlyPubKey where
- parseJSON = withObject "XOnlyPubKey" $ \i -> do
- i' <- i .: "id"
- case xOnlyPubKey' i' of
- Just e -> return e
- _ -> fail "invalid XOnlyPubKey"
- xOnlyPubKey' :: Text -> Maybe XOnlyPubKey
- xOnlyPubKey' t = do
- bs <- Schnorr.decodeHex t
- case BS.length bs of
- 32 -> Schnorr.xOnlyPubKey bs
- _ -> Nothing
- data Tag
- = ETag (EventId, RelayURL)
- | PTag (XOnlyPubKey, RelayURL)
- deriving (Eq, Show)
- newtype TagList = TagList [Tag] deriving (Show)
- instance FromJSON TagList where
- parseJSON (AesonTypes.Object o) =
- TagList <$> (o .: "tags")
- parseJSON _ = mzero
- instance FromJSON Tag where
- parseJSON (AesonTypes.Array v)
- | V.length v == 3 = do
- t <- parseJSON $ v V.! 0
- case t of
- "e" -> do
- e <- parseJSON $ v V.! 1
- r <- parseJSON $ v V.! 2
- return $ ETag (e, r)
- "p" -> do
- x <- parseJSON $ v V.! 1
- r <- parseJSON $ v V.! 2
- return $ PTag (x, r)
- _ -> mzero
- | otherwise = mzero
- parseJSON _ = mzero
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement