Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e92200a
commit 1d014e8
Showing
8 changed files
with
181 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
import Cardano.Api | ||
import Control.Monad.Except (runExceptT) | ||
import Plutus.Streaming (ChainSyncEvent (..), EventStreamResult, SimpleChainSyncEvent, withSimpleChainSyncEventStream) | ||
import Plutus.Streaming.LedgerState (ledgerState') | ||
import Streaming.Prelude qualified as S | ||
|
||
deriving instance Show InitialLedgerStateError | ||
|
||
deriving instance Show GenesisConfigError | ||
|
||
main :: IO () | ||
main = do | ||
ils <- runExceptT (initialLedgerState "/home/andrea/work/cardano-mainnet/config/mainnet-config.json") | ||
case ils of | ||
(Left e) -> error $ show e | ||
(Right (env, ls)) -> do | ||
r <- | ||
withSimpleChainSyncEventStream | ||
"/home/andrea/work/cardano-mainnet/socket/node.socket" | ||
Mainnet | ||
ChainPointAtGenesis $ | ||
consume . ledgerState' env ls FullValidation | ||
print r | ||
|
||
consume :: | ||
S.Stream (S.Of (SimpleChainSyncEvent, (LedgerState, [LedgerEvent]))) IO EventStreamResult -> | ||
IO EventStreamResult | ||
consume = S.mapM_ g | ||
|
||
g :: (SimpleChainSyncEvent, (LedgerState, [LedgerEvent])) -> IO () | ||
g (RollForward (BlockInMode blk _eim) _, _) = print cp | ||
where | ||
(Block (BlockHeader sn ha _bn) _) = blk | ||
cp = ChainPoint sn ha | ||
g (rb@(RollBackward _ _), _) = print rb |
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,20 @@ | ||
import Cardano.Api | ||
import Plutus.Streaming (ChainSyncEvent, ChainSyncEventWithLedgerState, withChainSyncEventStreamWithLedgerState) | ||
import Streaming.Prelude qualified as S | ||
|
||
main :: IO () | ||
main = do | ||
r <- | ||
withChainSyncEventStreamWithLedgerState | ||
"/home/andrea/work/cardano-mainnet/config/mainnet-config.json" | ||
"/home/andrea/work/cardano-mainnet/socket/node.socket" | ||
Mainnet | ||
ChainPointAtGenesis | ||
$ S.print . S.map f | ||
print r | ||
|
||
f :: ChainSyncEventWithLedgerState -> ChainSyncEvent ChainPoint | ||
f = fmap g | ||
|
||
g :: (BlockInMode CardanoMode, Either LedgerStateError (LedgerState, [LedgerEvent])) -> ChainPoint | ||
g (BlockInMode (Block (BlockHeader sn ha _bn) _eim) _ct, _) = ChainPoint sn ha |
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,37 @@ | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
import Cardano.Api | ||
import Control.Monad.Except (runExceptT) | ||
import Data.Time.LocalTime | ||
|
||
deriving instance Show InitialLedgerStateError | ||
|
||
deriving instance Show FoldBlocksError | ||
|
||
deriving instance Show GenesisConfigError | ||
|
||
main :: IO () | ||
main = do | ||
r <- | ||
runExceptT $ | ||
foldBlocks | ||
"/home/andrea/work/cardano-mainnet/config/mainnet-config.json" | ||
"/home/andrea/work/cardano-mainnet/socket/node.socket" | ||
FullValidation | ||
() | ||
myfold | ||
print r | ||
|
||
myfold :: | ||
Env -> | ||
LedgerState -> | ||
[LedgerEvent] -> | ||
BlockInMode CardanoMode -> | ||
() -> | ||
IO () | ||
myfold _env _ls _le (BlockInMode blk _eim) _ = do | ||
t <- getZonedTime | ||
putStrLn $ show t <> " " <> show cp | ||
where | ||
(Block (BlockHeader sn ha _bn) _) = blk | ||
cp = ChainPoint sn ha |
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