2
2
{-# LANGUAGE FlexibleContexts #-}
3
3
{-# LANGUAGE OverloadedStrings #-}
4
4
{-# LANGUAGE RankNTypes #-}
5
+ {-# LANGUAGE ScopedTypeVariables #-}
5
6
{-# LANGUAGE TypeApplications #-}
6
7
{-# LANGUAGE TypeFamilies #-}
7
8
{-# LANGUAGE NoImplicitPrelude #-}
@@ -14,10 +15,10 @@ module Cardano.DbSync.Era.Shelley.Generic.Block (
14
15
fromMaryBlock ,
15
16
fromAlonzoBlock ,
16
17
fromBabbageBlock ,
18
+ fromConwayBlock ,
19
+ getTxs ,
17
20
blockHash ,
18
21
blockPrevHash ,
19
- alonzoBlockTxs ,
20
- babbageBlockTxs ,
21
22
) where
22
23
23
24
import qualified Cardano.Api.Shelley as Api
@@ -33,8 +34,6 @@ import qualified Cardano.Ledger.Core as Ledger
33
34
import Cardano.Ledger.Crypto (Crypto , StandardCrypto )
34
35
import Cardano.Ledger.Era (EraSegWits (.. ))
35
36
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
38
37
import Cardano.Prelude
39
38
import qualified Cardano.Protocol.TPraos.BHeader as TPraos
40
39
import qualified Cardano.Protocol.TPraos.OCert as TPraos
@@ -43,11 +42,12 @@ import Ouroboros.Consensus.Cardano.Block (
43
42
StandardAllegra ,
44
43
StandardAlonzo ,
45
44
StandardBabbage ,
45
+ StandardConway ,
46
46
StandardMary ,
47
47
StandardShelley ,
48
48
)
49
49
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 )
51
51
import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus
52
52
import Ouroboros.Consensus.Shelley.Protocol.Abstract
53
53
import Ouroboros.Network.Block (BlockNo (.. ))
@@ -81,7 +81,7 @@ fromAllegraBlock blk =
81
81
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
82
82
, blkOpCert = blockOpCertKeyTPraos blk
83
83
, blkOpCertCounter = blockOpCertCounterTPraos blk
84
- , blkTxs = map fromAllegraTx (blockTxs blk)
84
+ , blkTxs = map fromAllegraTx (getTxs blk)
85
85
}
86
86
87
87
fromShelleyBlock :: ShelleyBlock TPraosStandard StandardShelley -> Block
@@ -98,7 +98,7 @@ fromShelleyBlock blk =
98
98
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
99
99
, blkOpCert = blockOpCertKeyTPraos blk
100
100
, blkOpCertCounter = blockOpCertCounterTPraos blk
101
- , blkTxs = map fromShelleyTx (blockTxs blk)
101
+ , blkTxs = map fromShelleyTx (getTxs blk)
102
102
}
103
103
104
104
fromMaryBlock :: ShelleyBlock TPraosStandard StandardMary -> Block
@@ -115,7 +115,7 @@ fromMaryBlock blk =
115
115
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
116
116
, blkOpCert = blockOpCertKeyTPraos blk
117
117
, blkOpCertCounter = blockOpCertCounterTPraos blk
118
- , blkTxs = map fromMaryTx (blockTxs blk)
118
+ , blkTxs = map fromMaryTx (getTxs blk)
119
119
}
120
120
121
121
fromAlonzoBlock :: Bool -> Maybe Prices -> ShelleyBlock TPraosStandard StandardAlonzo -> Block
@@ -132,7 +132,7 @@ fromAlonzoBlock iope mprices blk =
132
132
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
133
133
, blkOpCert = blockOpCertKeyTPraos blk
134
134
, blkOpCertCounter = blockOpCertCounterTPraos blk
135
- , blkTxs = map (fromAlonzoTx iope mprices) (alonzoBlockTxs blk)
135
+ , blkTxs = map (fromAlonzoTx iope mprices) (getTxs blk)
136
136
}
137
137
138
138
fromBabbageBlock :: Bool -> Maybe Prices -> ShelleyBlock PraosStandard StandardBabbage -> Block
@@ -149,16 +149,30 @@ fromBabbageBlock iope mprices blk =
149
149
, blkVrfKey = blockVrfKeyView $ blockVrfVkPraos blk
150
150
, blkOpCert = blockOpCertKeyPraos blk
151
151
, blkOpCertCounter = blockOpCertCounterPraos blk
152
- , blkTxs = map (fromBabbageTx iope mprices) (babbageBlockTxs blk)
152
+ , blkTxs = map (fromBabbageTx iope mprices) (getTxs blk)
153
153
}
154
154
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
+ }
156
171
157
- babbageBlockTxs :: ShelleyBlock p StandardBabbage -> [(Word64 , Ledger. Tx StandardBabbage )]
158
- babbageBlockTxs = zip [0 .. ] . toList . fromTxSeq @ StandardBabbage . Ledger. bbody . Consensus. shelleyBlockRaw
172
+ -- -------------------------------------------------------------------------------------------------
159
173
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
162
176
163
177
blockHeader :: ShelleyBlock p era -> ShelleyProtocolHeader p
164
178
blockHeader = Ledger. bheader . Consensus. shelleyBlockRaw
@@ -205,15 +219,6 @@ blockProtoVersionPraos = Praos.hbProtVer . getHeaderBodyPraos . blockHeader
205
219
blockSize :: ProtocolHeaderSupportsEnvelope p => ShelleyBlock p era -> Word64
206
220
blockSize = fromIntegral . pHeaderSize . blockHeader
207
221
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
-
217
222
blockVrfKeyView :: VerKeyVRF StandardCrypto -> Text
218
223
blockVrfKeyView = Api. serialiseToBech32 . Api. VrfVerificationKey
219
224
@@ -234,12 +239,3 @@ blockIssuer = hashKey . pHeaderIssuer . blockHeader
234
239
235
240
slotNumber :: ShelleyProtocol p => ShelleyBlock p era -> SlotNo
236
241
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
0 commit comments