-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- [x] Add `Deposit.IO.Network.NodeToClient` module with `fromNetworkLayer` function - [x] Make `Cardano.Wallet.Application` use a real `NetworkEnv`, translated with `fromNetworkLayer` ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-3487
- Loading branch information
Showing
9 changed files
with
148 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/IO/Network/NodeToClient.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
-- | | ||
-- Copyright: © 2024 Cardano Foundation | ||
-- License: Apache-2.0 | ||
-- | ||
-- Real implementation of a 'NetworkEnv'. | ||
module Cardano.Wallet.Deposit.IO.Network.NodeToClient | ||
( fromNetworkLayer | ||
, NetworkLayer | ||
, CardanoBlock | ||
, StandardCrypto | ||
) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Ledger.Api | ||
( StandardCrypto | ||
) | ||
import Cardano.Wallet.Deposit.IO.Network.Type | ||
( ErrPostTx (..) | ||
, NetworkEnv (..) | ||
, mapBlock | ||
) | ||
import Cardano.Wallet.Deposit.Time | ||
( toTimeTranslation | ||
) | ||
import Cardano.Wallet.Network | ||
( NetworkLayer | ||
, mapChainFollower | ||
) | ||
import Cardano.Wallet.Primitive.Ledger.Shelley | ||
( CardanoBlock | ||
) | ||
import Cardano.Wallet.Primitive.Slotting | ||
( snapshot | ||
) | ||
import Cardano.Wallet.Read | ||
( chainPointFromChainTip | ||
) | ||
import Control.Monad.Trans.Except | ||
( runExceptT | ||
, withExceptT | ||
) | ||
import Control.Tracer | ||
( nullTracer | ||
) | ||
|
||
import qualified Cardano.Read.Ledger.Block.Block as Read | ||
import qualified Cardano.Wallet.Deposit.Read as Read | ||
import qualified Cardano.Wallet.Deposit.Time as Time | ||
import qualified Cardano.Wallet.Network as NetworkLayer | ||
|
||
{----------------------------------------------------------------------------- | ||
NodeToClient 'NetworkEnv' | ||
------------------------------------------------------------------------------} | ||
|
||
-- | Translate the old NetworkLayer to the new NetworkEnv interface | ||
fromNetworkLayer | ||
:: NetworkLayer.NetworkLayer IO Read.ConsensusBlock | ||
-> NetworkEnv IO (Read.EraValue Read.Block) | ||
fromNetworkLayer nl = mapBlock Read.fromConsensusBlock $ | ||
NetworkEnv | ||
{ chainSync = \_tr follower -> do | ||
-- TODO: Connect tracer | ||
let follower' = mapChainFollower id id chainPointFromChainTip id follower | ||
NetworkLayer.chainSync nl nullTracer follower' | ||
return $ error "impossible: chainSync returned" | ||
-- TODO: We can change the error type of 'NetworkLayer.postTx' it | ||
-- doesn't need the ErrPostTxEraUnsupported case | ||
, postTx = runExceptT . withExceptT translateErrPostTx . NetworkLayer.postTx nl | ||
, currentPParams = | ||
NetworkLayer.currentPParams nl | ||
, getTimeTranslation = toTimeTranslation (NetworkLayer.timeInterpreter nl) | ||
, slotToUTCTime = Time.slotToUTCTime <$> snapshot ti | ||
} | ||
|
||
where | ||
ti = NetworkLayer.timeInterpreter nl | ||
|
||
translateErrPostTx :: NetworkLayer.ErrPostTx -> ErrPostTx | ||
translateErrPostTx = \case | ||
NetworkLayer.ErrPostTxValidationError errorText -> ErrPostTxValidationError errorText | ||
NetworkLayer.ErrPostTxMempoolFull -> ErrPostTxMempoolFull | ||
NetworkLayer.ErrPostTxEraUnsupported _era -> | ||
error "translateErrPostTx: ErrPostTxEraUnsupported should be impossible" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters