module Blockfrost.Types.Cardano.Blocks
( Block (..)
) where
import Data.Text (Text)
import Data.Aeson
import Data.Aeson.Types (explicitParseField)
import qualified Data.Vector
import Deriving.Aeson
import Servant.Docs (ToSample (..), singleSample)
import Blockfrost.Types.Shared
data Block = Block
{ Block -> POSIXTime
_blockTime :: POSIXTime
, Block -> Maybe Integer
_blockHeight :: Maybe Integer
, Block -> BlockHash
_blockHash :: BlockHash
, Block -> Maybe Slot
_blockSlot :: Maybe Slot
, Block -> Maybe Epoch
_blockEpoch :: Maybe Epoch
, Block -> Maybe Integer
_blockEpochSlot :: Maybe Integer
, Block -> Text
_blockSlotLeader :: Text
, Block -> Integer
_blockSize :: Integer
, Block -> Integer
_blockTxCount :: Integer
, Block -> Maybe Lovelaces
_blockOutput :: Maybe Lovelaces
, Block -> Maybe Lovelaces
_blockFees :: Maybe Lovelaces
, Block -> Maybe Text
_blockBlockVrf :: Maybe Text
, Block -> Maybe Text
_blockOpCert :: Maybe Text
, Block -> Maybe Quantity
_blockOpCertCounter :: Maybe Quantity
, Block -> Maybe BlockHash
_blockPreviousBlock :: Maybe BlockHash
, Block -> Maybe BlockHash
_blockNextBlock :: Maybe BlockHash
, Block -> Integer
_blockConfirmations :: Integer
}
deriving stock (Int -> Block -> ShowS
[Block] -> ShowS
Block -> String
(Int -> Block -> ShowS)
-> (Block -> String) -> ([Block] -> ShowS) -> Show Block
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Block -> ShowS
showsPrec :: Int -> Block -> ShowS
$cshow :: Block -> String
show :: Block -> String
$cshowList :: [Block] -> ShowS
showList :: [Block] -> ShowS
Show, Block -> Block -> Bool
(Block -> Block -> Bool) -> (Block -> Block -> Bool) -> Eq Block
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Block -> Block -> Bool
== :: Block -> Block -> Bool
$c/= :: Block -> Block -> Bool
/= :: Block -> Block -> Bool
Eq, (forall x. Block -> Rep Block x)
-> (forall x. Rep Block x -> Block) -> Generic Block
forall x. Rep Block x -> Block
forall x. Block -> Rep Block x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Block -> Rep Block x
from :: forall x. Block -> Rep Block x
$cto :: forall x. Rep Block x -> Block
to :: forall x. Rep Block x -> Block
Generic)
deriving (Maybe Block
Value -> Parser [Block]
Value -> Parser Block
(Value -> Parser Block)
-> (Value -> Parser [Block]) -> Maybe Block -> FromJSON Block
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Block
parseJSON :: Value -> Parser Block
$cparseJSONList :: Value -> Parser [Block]
parseJSONList :: Value -> Parser [Block]
$comittedField :: Maybe Block
omittedField :: Maybe Block
FromJSON, [Block] -> Value
[Block] -> Encoding
Block -> Bool
Block -> Value
Block -> Encoding
(Block -> Value)
-> (Block -> Encoding)
-> ([Block] -> Value)
-> ([Block] -> Encoding)
-> (Block -> Bool)
-> ToJSON Block
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Block -> Value
toJSON :: Block -> Value
$ctoEncoding :: Block -> Encoding
toEncoding :: Block -> Encoding
$ctoJSONList :: [Block] -> Value
toJSONList :: [Block] -> Value
$ctoEncodingList :: [Block] -> Encoding
toEncodingList :: [Block] -> Encoding
$comitField :: Block -> Bool
omitField :: Block -> Bool
ToJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "_block", CamelToSnake]] Block
instance ToSample Block where
toSamples :: Proxy Block -> [(Text, Block)]
toSamples Proxy Block
_ = Block -> [(Text, Block)]
forall a. a -> [(Text, a)]
singleSample (Block -> [(Text, Block)]) -> Block -> [(Text, Block)]
forall a b. (a -> b) -> a -> b
$ Block
{ $sel:_blockTime:Block :: POSIXTime
_blockTime = POSIXTime
1641338934
, $sel:_blockHeight:Block :: Maybe Integer
_blockHeight = Integer -> Maybe Integer
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer
15243593
, $sel:_blockHash:Block :: BlockHash
_blockHash = BlockHash
"4ea1ba291e8eef538635a53e59fddba7810d1679631cc3aed7c8e6c4091a516a"
, $sel:_blockSlot:Block :: Maybe Slot
_blockSlot = Slot -> Maybe Slot
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Slot
412162133
, $sel:_blockEpoch:Block :: Maybe Epoch
_blockEpoch = Epoch -> Maybe Epoch
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Epoch
425
, $sel:_blockEpochSlot:Block :: Maybe Integer
_blockEpochSlot = Integer -> Maybe Integer
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer
12
, $sel:_blockSlotLeader:Block :: Text
_blockSlotLeader = Text
"pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2qnikdy"
, $sel:_blockSize:Block :: Integer
_blockSize = Integer
3
, $sel:_blockTxCount:Block :: Integer
_blockTxCount = Integer
1
, $sel:_blockOutput:Block :: Maybe Lovelaces
_blockOutput = Discrete' "ADA" '(1000000, 1)
-> Maybe (Discrete' "ADA" '(1000000, 1))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Discrete' "ADA" '(1000000, 1)
128314491794
, $sel:_blockFees:Block :: Maybe Lovelaces
_blockFees = Discrete' "ADA" '(1000000, 1)
-> Maybe (Discrete' "ADA" '(1000000, 1))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Discrete' "ADA" '(1000000, 1)
592661
, $sel:_blockBlockVrf:Block :: Maybe Text
_blockBlockVrf = Text -> Maybe Text
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"vrf_vk1wf2k6lhujezqcfe00l6zetxpnmh9n6mwhpmhm0dvfh3fxgmdnrfqkms8ty"
, $sel:_blockOpCert:Block :: Maybe Text
_blockOpCert = Text -> Maybe Text
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"da905277534faf75dae41732650568af545134ee08a3c0392dbefc8096ae177c"
, $sel:_blockOpCertCounter:Block :: Maybe Quantity
_blockOpCertCounter = Quantity -> Maybe Quantity
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Quantity
18
, $sel:_blockPreviousBlock:Block :: Maybe BlockHash
_blockPreviousBlock = BlockHash -> Maybe BlockHash
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BlockHash
"43ebccb3ac72c7cebd0d9b755a4b08412c9f5dcb81b8a0ad1e3c197d29d47b05"
, $sel:_blockNextBlock:Block :: Maybe BlockHash
_blockNextBlock = BlockHash -> Maybe BlockHash
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BlockHash
"8367f026cf4b03e116ff8ee5daf149b55ba5a6ec6dec04803b8dc317721d15fa"
, $sel:_blockConfirmations:Block :: Integer
_blockConfirmations = Integer
4698
}
instance {-# OVERLAPS #-} ToJSON (Address, [TxHash]) where
toJSON :: (Address, [TxHash]) -> Value
toJSON (Address
addr, [TxHash]
txs) = [Pair] -> Value
object [
Key
"address" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Address -> Value
forall a. ToJSON a => a -> Value
toJSON Address
addr
, Key
"transactions" Key -> [Value] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (TxHash -> Value) -> [TxHash] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map (\TxHash
tx -> [Pair] -> Value
object [ Key
"tx_hash" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxHash -> Value
forall a. ToJSON a => a -> Value
toJSON TxHash
tx ]) [TxHash]
txs
]
instance {-# OVERLAPS #-} FromJSON (Address, [TxHash]) where
parseJSON :: Value -> Parser (Address, [TxHash])
parseJSON = String
-> (Object -> Parser (Address, [TxHash]))
-> Value
-> Parser (Address, [TxHash])
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"addrTxs" ((Object -> Parser (Address, [TxHash]))
-> Value -> Parser (Address, [TxHash]))
-> (Object -> Parser (Address, [TxHash]))
-> Value
-> Parser (Address, [TxHash])
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Address
addr <- Object
o Object -> Key -> Parser Address
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
[TxHash]
txs <- (Value -> Parser [TxHash]) -> Object -> Key -> Parser [TxHash]
forall a. (Value -> Parser a) -> Object -> Key -> Parser a
explicitParseField
(String -> (Array -> Parser [TxHash]) -> Value -> Parser [TxHash]
forall a. String -> (Array -> Parser a) -> Value -> Parser a
withArray String
"a" ((Array -> Parser [TxHash]) -> Value -> Parser [TxHash])
-> (Array -> Parser [TxHash]) -> Value -> Parser [TxHash]
forall a b. (a -> b) -> a -> b
$ \Array
a -> (Value -> Parser TxHash) -> [Value] -> Parser [TxHash]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (String -> (Object -> Parser TxHash) -> Value -> Parser TxHash
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"txHashes" ((Object -> Parser TxHash) -> Value -> Parser TxHash)
-> (Object -> Parser TxHash) -> Value -> Parser TxHash
forall a b. (a -> b) -> a -> b
$ \Object
to -> Object
to Object -> Key -> Parser TxHash
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tx_hash") (Array -> [Value]
forall a. Vector a -> [a]
Data.Vector.toList Array
a))
Object
o
Key
"transactions"
(Address, [TxHash]) -> Parser (Address, [TxHash])
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Address
addr, [TxHash]
txs)