|
| 1 | +{-# LANGUAGE ConstraintKinds #-} |
| 2 | +{-# LANGUAGE DataKinds #-} |
| 3 | +{-# LANGUAGE DerivingVia #-} |
| 4 | +{-# LANGUAGE FlexibleContexts #-} |
| 5 | +{-# LANGUAGE GADTs #-} |
| 6 | +{-# LANGUAGE OverloadedLabels #-} |
| 7 | +{-# LANGUAGE QuantifiedConstraints #-} |
| 8 | +{-# LANGUAGE RankNTypes #-} |
| 9 | +{-# LANGUAGE ScopedTypeVariables #-} |
| 10 | +{-# LANGUAGE TypeApplications #-} |
| 11 | + |
| 12 | +module Cardano.Rpc.Server.Internal.Node |
| 13 | + ( getEraMethod |
| 14 | + , getProtocolParamsJsonMethod |
| 15 | + ) |
| 16 | +where |
| 17 | + |
| 18 | +import Cardano.Api |
| 19 | +import Cardano.Api.Experimental.Era |
| 20 | +import Cardano.Rpc.Proto.Api.Node qualified as Rpc |
| 21 | +import Cardano.Rpc.Server.Internal.Error |
| 22 | +import Cardano.Rpc.Server.Internal.Monad |
| 23 | +import Cardano.Rpc.Server.Internal.Orphans () |
| 24 | + |
| 25 | +import RIO hiding (toList) |
| 26 | + |
| 27 | +import Data.Aeson qualified as A |
| 28 | +import Data.ByteString.Lazy qualified as BL |
| 29 | +import Data.Default |
| 30 | +import Data.ProtoLens (defMessage) |
| 31 | +import Network.GRPC.Spec |
| 32 | + |
| 33 | +import Proto.Google.Protobuf.Empty |
| 34 | + |
| 35 | +getEraMethod :: MonadRpc e m => Proto Empty -> m (Proto Rpc.CurrentEra) |
| 36 | +getEraMethod _ = pure . Proto $ defMessage & #era .~ Rpc.Conway |
| 37 | + |
| 38 | +getProtocolParamsJsonMethod :: MonadRpc e m => Proto Empty -> m (Proto Rpc.ProtocolParamsJson) |
| 39 | +getProtocolParamsJsonMethod _ = do |
| 40 | + nodeConnInfo <- grab |
| 41 | + AnyCardanoEra era <- liftIO . throwExceptT $ determineEra nodeConnInfo |
| 42 | + eon <- forEraInEon @Era era (error "getProtocolParamsJsonMethod: Minimum Conway era required") pure |
| 43 | + let sbe = convert eon |
| 44 | + |
| 45 | + let target = VolatileTip |
| 46 | + pparams <- |
| 47 | + liftIO . (throwEither =<<) $ |
| 48 | + executeLocalStateQueryExpr nodeConnInfo target $ |
| 49 | + throwEither =<< throwEither =<< queryProtocolParameters sbe |
| 50 | + |
| 51 | + let pparamsJson = obtainCommonConstraints eon $ A.encode pparams |
| 52 | + |
| 53 | + pure $ |
| 54 | + def |
| 55 | + & #json .~ BL.toStrict pparamsJson |
0 commit comments