{-# LANGUAGE GADTs              #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings  #-}
{-| Some useful constants related to the cardano network.
-}
module Convex.Constants(
  alonzoMainnet,
  recent,
  lessRecent
  ) where

import           Cardano.Api (AsType (AsHash), BlockHeader, ChainPoint (..))
import qualified Cardano.Api as CAPI
import           Data.Proxy  (Proxy (..))

-- | Start of the Alonzo era on mainnet.
-- https://explorer.cardano.org/en/block?id=8959c0323b94cc670afe44222ab8b4e72cfcad3b5ab665f334bbe642dc6e9ef4
alonzoMainnet :: ChainPoint
alonzoMainnet :: ChainPoint
alonzoMainnet = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => [Char] -> a
error forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Semigroup a => a -> a -> a
(<>) [Char]
"alonzoMainnet: parse failed: " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) forall a. a -> a
id forall a b. (a -> b) -> a -> b
$ do
  Hash BlockHeader
hsh <- forall a.
SerialiseAsRawBytes a =>
AsType a -> ByteString -> Either RawBytesHexError a
CAPI.deserialiseFromRawBytesHex (forall a. AsType a -> AsType (Hash a)
AsHash (forall t. HasTypeProxy t => Proxy t -> AsType t
CAPI.proxyToAsType (forall {k} (t :: k). Proxy t
Proxy :: Proxy BlockHeader))) ByteString
"8959c0323b94cc670afe44222ab8b4e72cfcad3b5ab665f334bbe642dc6e9ef4"
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ SlotNo -> Hash BlockHeader -> ChainPoint
ChainPoint SlotNo
39_916_975 Hash BlockHeader
hsh

-- | A recent block (1 November 2022, 5.42pm)
-- https://explorer.cardano.org/en/block?id=22e8b5455623ff8e75a79499bada55c3b0b259db33ddf4b94efaac858a40c4ed
recent :: ChainPoint
recent :: ChainPoint
recent = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => [Char] -> a
error forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Semigroup a => a -> a -> a
(<>) [Char]
"recent: parse failed: " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) forall a. a -> a
id forall a b. (a -> b) -> a -> b
$ do
  Hash BlockHeader
hsh <- forall a.
SerialiseAsRawBytes a =>
AsType a -> ByteString -> Either RawBytesHexError a
CAPI.deserialiseFromRawBytesHex (forall a. AsType a -> AsType (Hash a)
AsHash (forall t. HasTypeProxy t => Proxy t -> AsType t
CAPI.proxyToAsType (forall {k} (t :: k). Proxy t
Proxy :: Proxy BlockHeader))) ByteString
"22e8b5455623ff8e75a79499bada55c3b0b259db33ddf4b94efaac858a40c4ed"
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ SlotNo -> Hash BlockHeader -> ChainPoint
ChainPoint SlotNo
75_758_280 Hash BlockHeader
hsh

-- | A less recent block (2 September 2022, 9.42pm)
-- https://explorer.cardano.org/en/block?id=bee4dff659bdd2091343c23e10d4bc9f9c74e8aa4c805bf18ccb3f779c79e787
lessRecent :: ChainPoint
lessRecent :: ChainPoint
lessRecent = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => [Char] -> a
error forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Semigroup a => a -> a -> a
(<>) [Char]
"recent: parse failed: " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) forall a. a -> a
id forall a b. (a -> b) -> a -> b
$ do
  Hash BlockHeader
hsh <- forall a.
SerialiseAsRawBytes a =>
AsType a -> ByteString -> Either RawBytesHexError a
CAPI.deserialiseFromRawBytesHex (forall a. AsType a -> AsType (Hash a)
AsHash (forall t. HasTypeProxy t => Proxy t -> AsType t
CAPI.proxyToAsType (forall {k} (t :: k). Proxy t
Proxy :: Proxy BlockHeader))) ByteString
"bee4dff659bdd2091343c23e10d4bc9f9c74e8aa4c805bf18ccb3f779c79e787"
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ SlotNo -> Hash BlockHeader -> ChainPoint
ChainPoint SlotNo
70_588_643 Hash BlockHeader
hsh