Skip to content
Permalink
Browse files

wip

  • Loading branch information...
Anviking committed Jun 12, 2019
1 parent 2975565 commit 8631719625db43093e241500993b49eb18eb5990
Showing with 24 additions and 2 deletions.
  1. +24 −2 lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs
@@ -41,11 +41,13 @@ import Cardano.Wallet.Network
, NetworkLayer (..)
)
import Cardano.Wallet.Primitive.Types
( Block (..), Hash (..) )
( Block (..), BlockHeader (..), Hash (..) )
import Control.Arrow
( left )
import Control.Exception
( Exception )
import Control.Monad
( forM )
import Control.Monad.Catch
( throwM )
import Control.Monad.Trans.Except
@@ -97,12 +99,32 @@ mkNetworkLayer j = NetworkLayer
ErrNetworkTipNetworkUnreachable e
return $ header b

, nextBlocks = error "nextBlocks to be implemented"
, nextBlocks = \tipHeader -> do
getBlocksAfter j (prevBlockHash tipHeader) 1000

, postTx = error "postTx to be implemented"
}
where
mappingError = flip withExceptT


getBlocksAfter
:: Monad m
=> JormungandrLayer m
-> Hash "BlockHeader"
-> Word
-> ExceptT ErrGetBlock m [Block]
getBlocksAfter j blockHeader count = do
ids <- getDescendantIds j blockHeader count `mappingError` \case
ErrGetDescendantsNetworkUnreachable e ->
ErrGetBlockNetworkUnreachable e
ErrGetDescendantsParentNotFound e ->
ErrGetBlockNotFound . T.pack . show $ e
forM ids getBlock'
where
mappingError = flip withExceptT
getBlock' = getBlock j

{-------------------------------------------------------------------------------
Jormungandr Client
-------------------------------------------------------------------------------}

0 comments on commit 8631719

Please sign in to comment.
You can’t perform that action at this time.