Skip to content

Commit 1dc84fd

Browse files
committed
Introduce Conway block and simplify getTx
1 parent 3fba987 commit 1dc84fd

File tree

7 files changed

+63
-41
lines changed

7 files changed

+63
-41
lines changed

cabal.project

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ repository cardano-haskell-packages
1010
d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee
1111

1212
index-state:
13-
, hackage.haskell.org 2023-05-10T10:34:57Z
14-
, cardano-haskell-packages 2023-06-06T08:18:38Z
13+
, hackage.haskell.org 2023-07-10T14:55:34Z
14+
, cardano-haskell-packages 2023-07-16T00:00:00Z
1515

1616
packages:
1717
cardano-db
@@ -24,6 +24,8 @@ packages:
2424

2525
constraints:
2626
persistent-postgresql >= 2.11.0.1,
27+
optparse-applicative >= 0.16.0 && < 0.16.1,
28+
cardano-api < 8.8.1
2729

2830
package cardano-db
2931
ghc-options: -Wall -Werror -Wredundant-constraints -Wincomplete-uni-patterns -Wincomplete-record-updates -Wpartial-fields -Wunused-imports -Wunused-packages

cardano-db-sync/cardano-db-sync.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ library
7474
Cardano.DbSync.Era.Shelley.Generic.Tx.Allegra
7575
Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo
7676
Cardano.DbSync.Era.Shelley.Generic.Tx.Babbage
77+
Cardano.DbSync.Era.Shelley.Generic.Tx.Conway
7778
Cardano.DbSync.Era.Shelley.Generic.Tx.Mary
7879
Cardano.DbSync.Era.Shelley.Generic.Tx.Shelley
7980
Cardano.DbSync.Era.Shelley.Generic.Tx.Types

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Block.hs

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE FlexibleContexts #-}
33
{-# LANGUAGE OverloadedStrings #-}
44
{-# LANGUAGE RankNTypes #-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
56
{-# LANGUAGE TypeApplications #-}
67
{-# LANGUAGE TypeFamilies #-}
78
{-# LANGUAGE NoImplicitPrelude #-}
@@ -14,10 +15,10 @@ module Cardano.DbSync.Era.Shelley.Generic.Block (
1415
fromMaryBlock,
1516
fromAlonzoBlock,
1617
fromBabbageBlock,
18+
fromConwayBlock,
19+
getTxs,
1720
blockHash,
1821
blockPrevHash,
19-
alonzoBlockTxs,
20-
babbageBlockTxs,
2122
) where
2223

2324
import qualified Cardano.Api.Shelley as Api
@@ -33,8 +34,6 @@ import qualified Cardano.Ledger.Core as Ledger
3334
import Cardano.Ledger.Crypto (Crypto, StandardCrypto)
3435
import Cardano.Ledger.Era (EraSegWits (..))
3536
import Cardano.Ledger.Keys (KeyHash, KeyRole (..), VerKeyVRF, hashKey)
36-
import qualified Cardano.Ledger.Shelley.BlockChain as Shelley
37-
import qualified Cardano.Ledger.Shelley.Tx as Shelley
3837
import Cardano.Prelude
3938
import qualified Cardano.Protocol.TPraos.BHeader as TPraos
4039
import qualified Cardano.Protocol.TPraos.OCert as TPraos
@@ -43,11 +42,12 @@ import Ouroboros.Consensus.Cardano.Block (
4342
StandardAllegra,
4443
StandardAlonzo,
4544
StandardBabbage,
45+
StandardConway,
4646
StandardMary,
4747
StandardShelley,
4848
)
4949
import qualified Ouroboros.Consensus.Protocol.Praos.Header as Praos
50-
import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyBasedEra, ShelleyBlock)
50+
import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyBlock)
5151
import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus
5252
import Ouroboros.Consensus.Shelley.Protocol.Abstract
5353
import Ouroboros.Network.Block (BlockNo (..))
@@ -81,7 +81,7 @@ fromAllegraBlock blk =
8181
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
8282
, blkOpCert = blockOpCertKeyTPraos blk
8383
, blkOpCertCounter = blockOpCertCounterTPraos blk
84-
, blkTxs = map fromAllegraTx (blockTxs blk)
84+
, blkTxs = map fromAllegraTx (getTxs blk)
8585
}
8686

8787
fromShelleyBlock :: ShelleyBlock TPraosStandard StandardShelley -> Block
@@ -98,7 +98,7 @@ fromShelleyBlock blk =
9898
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
9999
, blkOpCert = blockOpCertKeyTPraos blk
100100
, blkOpCertCounter = blockOpCertCounterTPraos blk
101-
, blkTxs = map fromShelleyTx (blockTxs blk)
101+
, blkTxs = map fromShelleyTx (getTxs blk)
102102
}
103103

104104
fromMaryBlock :: ShelleyBlock TPraosStandard StandardMary -> Block
@@ -115,7 +115,7 @@ fromMaryBlock blk =
115115
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
116116
, blkOpCert = blockOpCertKeyTPraos blk
117117
, blkOpCertCounter = blockOpCertCounterTPraos blk
118-
, blkTxs = map fromMaryTx (blockTxs blk)
118+
, blkTxs = map fromMaryTx (getTxs blk)
119119
}
120120

121121
fromAlonzoBlock :: Bool -> Maybe Prices -> ShelleyBlock TPraosStandard StandardAlonzo -> Block
@@ -132,7 +132,7 @@ fromAlonzoBlock iope mprices blk =
132132
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
133133
, blkOpCert = blockOpCertKeyTPraos blk
134134
, blkOpCertCounter = blockOpCertCounterTPraos blk
135-
, blkTxs = map (fromAlonzoTx iope mprices) (alonzoBlockTxs blk)
135+
, blkTxs = map (fromAlonzoTx iope mprices) (getTxs blk)
136136
}
137137

138138
fromBabbageBlock :: Bool -> Maybe Prices -> ShelleyBlock PraosStandard StandardBabbage -> Block
@@ -149,16 +149,30 @@ fromBabbageBlock iope mprices blk =
149149
, blkVrfKey = blockVrfKeyView $ blockVrfVkPraos blk
150150
, blkOpCert = blockOpCertKeyPraos blk
151151
, blkOpCertCounter = blockOpCertCounterPraos blk
152-
, blkTxs = map (fromBabbageTx iope mprices) (babbageBlockTxs blk)
152+
, blkTxs = map (fromBabbageTx iope mprices) (getTxs blk)
153153
}
154154

155-
-- -------------------------------------------------------------------------------------------------
155+
fromConwayBlock :: Bool -> Maybe Prices -> ShelleyBlock PraosStandard StandardConway -> Block
156+
fromConwayBlock iope mprices blk =
157+
Block
158+
{ blkEra = Babbage
159+
, blkHash = blockHash blk
160+
, blkPreviousHash = blockPrevHash blk
161+
, blkSlotLeader = blockIssuer blk
162+
, blkSlotNo = slotNumber blk
163+
, blkBlockNo = blockNumber blk
164+
, blkSize = blockSize blk
165+
, blkProto = blockProtoVersionPraos blk
166+
, blkVrfKey = blockVrfKeyView $ blockVrfVkPraos blk
167+
, blkOpCert = blockOpCertKeyPraos blk
168+
, blkOpCertCounter = blockOpCertCounterPraos blk
169+
, blkTxs = map (fromConwayTx iope mprices) (getTxs blk)
170+
}
156171

157-
babbageBlockTxs :: ShelleyBlock p StandardBabbage -> [(Word64, Ledger.Tx StandardBabbage)]
158-
babbageBlockTxs = zip [0 ..] . toList . fromTxSeq @StandardBabbage . Ledger.bbody . Consensus.shelleyBlockRaw
172+
-- -------------------------------------------------------------------------------------------------
159173

160-
alonzoBlockTxs :: ShelleyBlock p StandardAlonzo -> [(Word64, Ledger.Tx StandardAlonzo)]
161-
alonzoBlockTxs = zip [0 ..] . toList . fromTxSeq @StandardAlonzo . Ledger.bbody . Consensus.shelleyBlockRaw
174+
getTxs :: forall p era. EraSegWits era => ShelleyBlock p era -> [(Word64, Ledger.Tx era)]
175+
getTxs = zip [0 ..] . toList . fromTxSeq @era . Ledger.bbody . Consensus.shelleyBlockRaw
162176

163177
blockHeader :: ShelleyBlock p era -> ShelleyProtocolHeader p
164178
blockHeader = Ledger.bheader . Consensus.shelleyBlockRaw
@@ -205,15 +219,6 @@ blockProtoVersionPraos = Praos.hbProtVer . getHeaderBodyPraos . blockHeader
205219
blockSize :: ProtocolHeaderSupportsEnvelope p => ShelleyBlock p era -> Word64
206220
blockSize = fromIntegral . pHeaderSize . blockHeader
207221

208-
blockTxs ::
209-
( ShelleyBasedEra era
210-
, Ledger.TxSeq era ~ Shelley.ShelleyTxSeq era
211-
, Ledger.Tx era ~ Shelley.ShelleyTx era
212-
) =>
213-
ShelleyBlock p era ->
214-
[(Word64, Shelley.ShelleyTx era)]
215-
blockTxs = zip [0 ..] . unTxSeq . Ledger.bbody . Consensus.shelleyBlockRaw
216-
217222
blockVrfKeyView :: VerKeyVRF StandardCrypto -> Text
218223
blockVrfKeyView = Api.serialiseToBech32 . Api.VrfVerificationKey
219224

@@ -234,12 +239,3 @@ blockIssuer = hashKey . pHeaderIssuer . blockHeader
234239

235240
slotNumber :: ShelleyProtocol p => ShelleyBlock p era -> SlotNo
236241
slotNumber = pHeaderSlot . blockHeader
237-
238-
unTxSeq ::
239-
( ShelleyBasedEra era
240-
, Ledger.TxSeq era ~ Shelley.ShelleyTxSeq era
241-
, Ledger.Tx era ~ Shelley.ShelleyTx era
242-
) =>
243-
Shelley.ShelleyTxSeq era ->
244-
[Shelley.ShelleyTx era]
245-
unTxSeq = toList . Ledger.fromTxSeq

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ module Cardano.DbSync.Era.Shelley.Generic.Tx (
44
fromMaryTx,
55
fromAlonzoTx,
66
fromBabbageTx,
7+
fromConwayTx,
78
module X,
89
) where
910

1011
import Cardano.DbSync.Era.Shelley.Generic.Tx.Allegra
1112
import Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo
1213
import Cardano.DbSync.Era.Shelley.Generic.Tx.Babbage
14+
import Cardano.DbSync.Era.Shelley.Generic.Tx.Conway
1315
import Cardano.DbSync.Era.Shelley.Generic.Tx.Mary
1416
import Cardano.DbSync.Era.Shelley.Generic.Tx.Shelley
1517
import Cardano.DbSync.Era.Shelley.Generic.Tx.Types as X
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE GADTs #-}
3+
{-# LANGUAGE RankNTypes #-}
4+
{-# LANGUAGE ScopedTypeVariables #-}
5+
{-# LANGUAGE TypeApplications #-}
6+
{-# LANGUAGE NoImplicitPrelude #-}
7+
8+
9+
module Cardano.DbSync.Era.Shelley.Generic.Tx.Conway (
10+
fromConwayTx,
11+
) where
12+
13+
import Prelude
14+
import qualified Cardano.Ledger.Core as Core
15+
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
16+
import Ouroboros.Consensus.Cardano.Block (StandardConway)
17+
import Data.Word (Word64)
18+
import Cardano.DbSync.Era.Shelley.Generic.Tx.Types
19+
20+
fromConwayTx :: Bool -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardConway) -> Tx
21+
fromConwayTx = undefined

cardano-db-sync/src/Cardano/DbSync/Fix/PlutusDataBytes.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ fixPlutusData tracer cblk fds = do
252252
scrapDatumsBlock :: CardanoBlock -> Map ByteString ByteString
253253
scrapDatumsBlock cblk = case cblk of
254254
BlockConway _blk -> panic "TODO: Conway 4"
255-
BlockBabbage blk -> Map.unions $ scrapDatumsTxBabbage . snd <$> babbageBlockTxs blk
256-
BlockAlonzo blk -> Map.unions $ scrapDatumsTxAlonzo . snd <$> alonzoBlockTxs blk
255+
BlockBabbage blk -> Map.unions $ scrapDatumsTxBabbage . snd <$> getTxs blk
256+
BlockAlonzo blk -> Map.unions $ scrapDatumsTxAlonzo . snd <$> getTxs blk
257257
BlockByron _ -> error "No Datums in Byron"
258258
BlockShelley _ -> error "No Datums in Shelley"
259259
BlockAllegra _ -> error "No Datums in Allegra"
@@ -288,8 +288,8 @@ scrapDatumsTxAlonzo tx =
288288
scrapRedeemerDataBlock :: CardanoBlock -> Map ByteString ByteString
289289
scrapRedeemerDataBlock cblk = case cblk of
290290
BlockConway _blk -> panic "TODO: Conway 5"
291-
BlockBabbage blk -> Map.unions $ scrapRedeemerDataTx . snd <$> babbageBlockTxs blk
292-
BlockAlonzo blk -> Map.unions $ scrapRedeemerDataTx . snd <$> alonzoBlockTxs blk
291+
BlockBabbage blk -> Map.unions $ scrapRedeemerDataTx . snd <$> getTxs blk
292+
BlockAlonzo blk -> Map.unions $ scrapRedeemerDataTx . snd <$> getTxs blk
293293
BlockByron _ -> error "No RedeemerData in Byron"
294294
BlockShelley _ -> error "No RedeemerData in Shelley"
295295
BlockAllegra _ -> error "No RedeemerData in Allegra"

cardano-db-sync/src/Cardano/DbSync/Fix/PlutusScripts.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ fixPlutusScripts tracer cblk fpss = do
141141

142142
scrapScriptBlock :: CardanoBlock -> Map ByteString ByteString
143143
scrapScriptBlock cblk = case cblk of
144-
BlockBabbage blk -> Map.unions $ scrapScriptTxBabbage . snd <$> babbageBlockTxs blk
145-
BlockAlonzo blk -> Map.unions $ scrapScriptTxAlonzo . snd <$> alonzoBlockTxs blk
144+
BlockBabbage blk -> Map.unions $ scrapScriptTxBabbage . snd <$> getTxs blk
145+
BlockAlonzo blk -> Map.unions $ scrapScriptTxAlonzo . snd <$> getTxs blk
146146
BlockByron _ -> error "No Plutus Scripts in Byron"
147147
BlockShelley _ -> error "No Plutus Scripts in Shelley"
148148
BlockAllegra _ -> error "No Plutus Scripts in Allegra"

0 commit comments

Comments
 (0)