Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Revert Node Settings Decoupling #4045

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wallet/cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ library
Cardano.Wallet.WalletLayer.Kernel.Conv
Cardano.Wallet.WalletLayer.Kernel.Info
Cardano.Wallet.WalletLayer.Kernel.Internal
Cardano.Wallet.WalletLayer.Kernel.Settings
Cardano.Wallet.WalletLayer.Kernel.Transactions
Cardano.Wallet.WalletLayer.Kernel.Wallets
other-modules:
Expand Down
6 changes: 2 additions & 4 deletions wallet/src/Cardano/Wallet/Kernel/NodeStateAdaptor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}

-- needed for SecurityParameter
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Cardano.Wallet.Kernel.NodeStateAdaptor (
WithNodeState -- opaque
, NodeStateAdaptor -- opaque
Expand Down Expand Up @@ -94,7 +91,6 @@ import qualified Pos.Infra.Shutdown.Logic as Shutdown
import qualified Pos.Infra.Slotting.Impl.Simple as S
import qualified Pos.Infra.Slotting.Util as Slotting
import Pos.Launcher.Resource (NodeResources (..))
import Pos.Node.API (SecurityParameter (..))
import Pos.Util (CompileTimeInfo, HasCompileInfo, HasLens (..),
lensOf', withCompileInfo)
import qualified Pos.Util as Util
Expand All @@ -107,6 +103,8 @@ import Test.Pos.Configuration (withDefConfiguration,
Additional types
-------------------------------------------------------------------------------}

newtype SecurityParameter = SecurityParameter Int

deriveSafeCopy 1 'base ''SecurityParameter

-- | Returned by 'getSlotStart' when requesting info about an unknown epoch
Expand Down
3 changes: 2 additions & 1 deletion wallet/src/Cardano/Wallet/WalletLayer/Kernel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import qualified Cardano.Wallet.WalletLayer.Kernel.Active as Active
import qualified Cardano.Wallet.WalletLayer.Kernel.Addresses as Addresses
import qualified Cardano.Wallet.WalletLayer.Kernel.Info as Info
import qualified Cardano.Wallet.WalletLayer.Kernel.Internal as Internal
import qualified Cardano.Wallet.WalletLayer.Kernel.Settings as Settings
import qualified Cardano.Wallet.WalletLayer.Kernel.Transactions as Transactions
import qualified Cardano.Wallet.WalletLayer.Kernel.Wallets as Wallets

Expand Down Expand Up @@ -141,7 +142,7 @@ bracketPassiveWallet pm mode logFunction keystore node fInjects f = do
, validateAddress = \txt -> ro $ Addresses.validateAddress txt
, getTransactions = Transactions.getTransactions w
, getTxFromMeta = Transactions.toTransaction w
, getNodeSettings = error "TODO (we need cherry pick of https://github.com/input-output-hk/cardano-wallet/pull/196/files)"
, getNodeSettings = Settings.getNodeSettings w
}
where
-- Read-only operations
Expand Down
51 changes: 51 additions & 0 deletions wallet/src/Cardano/Wallet/WalletLayer/Kernel/Settings.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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