This repository was archived by the owner on Aug 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathSettings.hs
51 lines (40 loc) · 1.84 KB
/
Settings.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-# LANGUAGE LambdaCase #-}
module Cardano.Wallet.WalletLayer.Kernel.Settings (
getNodeSettings
) where
import Universum
import qualified Data.Text as T
import Data.Time.Units (Millisecond)
import Pos.Core (TxFeePolicy (..))
import qualified Pos.Node.API as Node
import Pos.Util.CompileInfo (CompileTimeInfo, ctiGitRevision)
import Cardano.Wallet.API.V1.Types (V1 (..))
import qualified Cardano.Wallet.API.V1.Types as V1
import qualified Cardano.Wallet.Kernel.Internal as Kernel
import Cardano.Wallet.Kernel.NodeStateAdaptor (NodeStateAdaptor)
import qualified Cardano.Wallet.Kernel.NodeStateAdaptor as KNode
import Paths_cardano_wallet (version)
getNodeSettings :: MonadIO m => Kernel.PassiveWallet -> m V1.NodeSettings
getNodeSettings w = liftIO $
V1.NodeSettings
<$> (V1 <$> KNode.getTipSlotId node)
<*> (mkSlotDuration <$> KNode.getNextEpochSlotDuration node)
<*> (V1 <$> KNode.getSlotCount node)
<*> (V1 <$> KNode.curSoftwareVersion node)
<*> pure (V1 version)
<*> (mkGitRevision <$> KNode.compileInfo node)
<*> (Node.mkMaxTxSize . fromIntegral <$> KNode.getMaxTxSize node)
<*> (Node.fromCorePolicy <$> (KNode.getFeePolicy node >>= mkFeePolicy))
<*> (mkSecurityParameter <$> KNode.getSecurityParameter node)
where
mkSlotDuration :: Millisecond -> V1.SlotDuration
mkSlotDuration = V1.mkSlotDuration . fromIntegral
mkGitRevision :: CompileTimeInfo -> Text
mkGitRevision = T.replace "\n" mempty . ctiGitRevision
mkSecurityParameter (KNode.SecurityParameter i) =
Node.SecurityParameter i
mkFeePolicy = \case
TxFeePolicyTxSizeLinear a -> return a
_ -> fail "getNodeSettings: Unsupported / Unknown fee policy."
node :: NodeStateAdaptor IO
node = w ^. Kernel.walletNode