@@ -59,7 +59,7 @@ import Pos.Infra.Diffusion.Types (Diffusion)
59
59
import Pos.Binary.Class (biSize )
60
60
import Pos.Chain.Block (Block , Blund , HeaderHash , MainBlock , Undo ,
61
61
gbHeader , gbhConsensus , mainBlockSlot , mainBlockTxPayload ,
62
- mcdSlot )
62
+ mcdSlot , headerHash )
63
63
import Pos.Chain.Genesis as Genesis (Config (.. ), GenesisHash ,
64
64
configEpochSlots )
65
65
import Pos.Chain.Txp (Tx (.. ), TxAux , TxId , TxIn (.. ), TxMap ,
@@ -324,8 +324,8 @@ getBlockSummary
324
324
-> CHash
325
325
-> m CBlockSummary
326
326
getBlockSummary genesisConfig cHash = do
327
- headerHash <- unwrapOrThrow $ fromCHash cHash
328
- mainBlund <- getMainBlund (configGenesisHash genesisConfig) headerHash
327
+ hh <- unwrapOrThrow $ fromCHash cHash
328
+ mainBlund <- getMainBlund (configGenesisHash genesisConfig) hh
329
329
toBlockSummary (configEpochSlots genesisConfig) mainBlund
330
330
331
331
@@ -450,46 +450,27 @@ getBlockRange genesisConfig start stop = do
450
450
let txId = hash tx
451
451
txExtra <- getTxExtraOrFail txId
452
452
453
- -- Return transaction extra (txExtra) fields
454
- let mBlockchainPlace = teBlockchainPlace txExtra -- TODO, remove this, we already know which block
455
- blockchainPlace <- maybeThrow (Internal " No blockchain place." ) mBlockchainPlace
456
-
457
- let headerHashBP = fst blockchainPlace
458
- let txIndexInBlock = snd blockchainPlace
459
-
460
453
blkSlotStart <- getBlkSlotStart mb
461
454
462
- let blockHeight = fromIntegral $ mb ^. difficultyL
463
- let receivedTime = teReceivedTime txExtra
464
- let blockTime = timestampToPosix <$> blkSlotStart
465
-
466
- -- Get block epoch and slot index
467
- let blkHeaderSlot = mb ^. mainBlockSlot
468
- let epochIndex = getEpochIndex $ siEpoch blkHeaderSlot
469
- let slotIndex = getSlotIndex $ siSlot blkHeaderSlot
470
- let blkHash = toCHash headerHashBP
471
-
472
- tx <- maybeThrow (Internal " TxExtra return tx index that is out of bounds" ) $
473
- atMay (toList $ mb ^. mainBlockTxPayload . txpTxs) (fromIntegral txIndexInBlock)
474
-
475
- let inputOutputsMB = map (fmap toaOut) $ NE. toList $ teInputOutputs txExtra
476
- let txOutputs = convertTxOutputs . NE. toList $ _txOutputs tx
477
-
478
- let totalInputMB = unsafeIntegerToCoin . sumCoins . map txOutValue <$> sequence inputOutputsMB
479
- let totalOutput = unsafeIntegerToCoin $ sumCoins $ map snd txOutputs
455
+ let
456
+ blockTime = timestampToPosix <$> blkSlotStart
457
+ inputOutputsMB = map (fmap toaOut) $ NE. toList $ teInputOutputs txExtra
458
+ txOutputs = convertTxOutputs . NE. toList $ _txOutputs tx
459
+ totalInputMB = unsafeIntegerToCoin . sumCoins . map txOutValue <$> sequence inputOutputsMB
460
+ totalOutput = unsafeIntegerToCoin $ sumCoins $ map snd txOutputs
480
461
481
462
-- Verify that strange things don't happen with transactions
482
463
whenJust totalInputMB $ \ totalInput -> when (totalOutput > totalInput) $
483
464
throwM $ Internal " Detected tx with output greater than input"
484
465
485
466
pure $ CTxSummary
486
467
{ ctsId = toCTxId txId
487
- , ctsTxTimeIssued = timestampToPosix <$> receivedTime
468
+ , ctsTxTimeIssued = timestampToPosix <$> teReceivedTime txExtra
488
469
, ctsBlockTimeIssued = blockTime
489
- , ctsBlockHeight = Just blockHeight
490
- , ctsBlockEpoch = Just epochIndex
491
- , ctsBlockSlot = Just slotIndex
492
- , ctsBlockHash = Just blkHash
470
+ , ctsBlockHeight = Nothing
471
+ , ctsBlockEpoch = Nothing
472
+ , ctsBlockSlot = Nothing
473
+ , ctsBlockHash = Just $ toCHash $ headerHash mb
493
474
, ctsRelayedBy = Nothing
494
475
, ctsTotalInput = mkCCoinMB totalInputMB
495
476
, ctsTotalOutput = mkCCoin totalOutput
@@ -499,7 +480,7 @@ getBlockRange genesisConfig start stop = do
499
480
}
500
481
genesisHash = configGenesisHash genesisConfig
501
482
go :: ExplorerMode ctx m => HeaderHash -> CBlockRange -> m CBlockRange
502
- go hh state = do
483
+ go hh state1 = do
503
484
maybeBlund <- getBlund genesisHash hh
504
485
newState <- case maybeBlund of
505
486
Just (Right blk', undo) -> do
@@ -508,13 +489,13 @@ getBlockRange genesisConfig start stop = do
508
489
txs = blk' ^. mainBlockTxPayload . txpTxs
509
490
blockSum <- toBlockSummary (configEpochSlots genesisConfig) (blk',undo)
510
491
let
511
- state2 = state { cbrBlocks = blockSum : (cbrBlocks state ) }
492
+ state2 = state1 { cbrBlocks = blockSum : (cbrBlocks state1 ) }
512
493
iterateTx :: ExplorerMode ctx m => CBlockRange -> Tx -> m CBlockRange
513
494
iterateTx stateIn tx = do
514
495
txSummary <- getTxSummaryFromBlock blk' tx
515
496
pure $ stateIn { cbrTransactions = txSummary : (cbrTransactions stateIn) }
516
497
foldM iterateTx state2 txs
517
- _ -> pure state
498
+ _ -> pure state1
518
499
if hh == stopHeaderHash then
519
500
pure newState
520
501
else do
@@ -523,7 +504,11 @@ getBlockRange genesisConfig start stop = do
523
504
Nothing -> do
524
505
pure newState
525
506
Just nextHh' -> go nextHh' newState
526
- go startHeaderHash (CBlockRange [] [] )
507
+ backwards <- go startHeaderHash (CBlockRange [] [] )
508
+ pure $ CBlockRange
509
+ { cbrBlocks = reverse $ cbrBlocks backwards
510
+ , cbrTransactions = reverse $ cbrTransactions backwards
511
+ }
527
512
528
513
529
514
-- | Get transaction summary from transaction id. Looks at both the database
@@ -979,9 +964,8 @@ getBlundOrThrow
979
964
:: ExplorerMode ctx m
980
965
=> HeaderHash
981
966
-> m Blund
982
- getBlundOrThrow headerHash =
983
- getBlundFromHHCSLI headerHash >>=
984
- maybeThrow (Internal " Blund with hash cannot be found!" )
967
+ getBlundOrThrow hh =
968
+ getBlundFromHHCSLI hh >>= maybeThrow (Internal " Blund with hash cannot be found!" )
985
969
986
970
987
971
-- | Deserialize Cardano or RSCoin address and convert it to Cardano address.
0 commit comments