Skip to content

Commit 4410ed1

Browse files
committed
Add singletons for STxType
1 parent 5ae5161 commit 4410ed1

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

eras/shelley/impl/src/Cardano/Ledger/Shelley/TxBody.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ instance EraTxBody ShelleyEra where
205205

206206
mkBasicTxBody = mkMemoizedEra @ShelleyEra basicShelleyTxBodyRaw
207207

208+
txBodyType txBody =
209+
case getMemoRawType txBody of
210+
ShelleyTxBodyRaw {} -> SFullTx
211+
208212
spendableInputsTxBodyF = inputsTxBodyL
209213
{-# INLINE spendableInputsTxBodyF #-}
210214

eras/shelley/impl/src/Cardano/Ledger/Shelley/UTxO.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,19 @@ instance EraUTxO ShelleyEra where
183183

184184
getConsumedValue pp lookupKeyDeposit _ = getConsumedCoin pp lookupKeyDeposit
185185

186-
getProducedValue = shelleyProducedValue
186+
getProducedValue pp isRegPoolId txBody =
187+
case txBodyType txBody of
188+
SFullTx -> shelleyProducedValue pp isRegPoolId txBody
187189

188190
getScriptsProvided _ tx = ScriptsProvided (tx ^. witsTxL . scriptTxWitsL)
189191

190192
getScriptsNeeded = getShelleyScriptsNeeded
191193

192194
getScriptsHashesNeeded (ShelleyScriptsNeeded scriptsHashes) = scriptsHashes
193195

194-
getWitsVKeyNeeded certState utxo = getShelleyWitsVKeyNeeded certState utxo
196+
getWitsVKeyNeeded certState utxo txBody =
197+
case txBodyType txBody of
198+
SFullTx -> getShelleyWitsVKeyNeeded certState utxo txBody
195199

196200
getMinFeeTxUtxo pp tx _ = getShelleyMinFeeTxUtxo pp tx
197201

libs/cardano-ledger-core/src/Cardano/Ledger/Core.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE DefaultSignatures #-}
55
{-# LANGUAGE FlexibleContexts #-}
66
{-# LANGUAGE FlexibleInstances #-}
7+
{-# LANGUAGE GADTs #-}
78
{-# LANGUAGE MultiParamTypeClasses #-}
89
{-# LANGUAGE OverloadedStrings #-}
910
{-# LANGUAGE PolyKinds #-}
@@ -27,6 +28,7 @@
2728
module Cardano.Ledger.Core (
2829
-- * Transaction types
2930
TxType (..),
31+
STxType (..),
3032
withTxType,
3133
applyTxType,
3234
applyFullTxType,
@@ -144,11 +146,11 @@ type data TxType = FullTx | SubTx
144146

145147
withTxType ::
146148
forall f t a era. Typeable t => f t era -> (f FullTx era -> a) -> (f SubTx era -> a) -> a
147-
withTxType txType withFullTxType withSubTxType =
149+
withTxType anyTxType withFullTxType withSubTxType =
148150
case eqT @t @FullTx of
149-
Just Refl -> withFullTxType txType
151+
Just Refl -> withFullTxType anyTxType
150152
Nothing -> case eqT @t @SubTx of
151-
Just Refl -> withSubTxType txType
153+
Just Refl -> withSubTxType anyTxType
152154
Nothing -> error $ "Impossible: Unrecognized TxType: " <> show (typeRep (Proxy @t))
153155

154156
applyTxType ::
@@ -168,6 +170,10 @@ applyFullTxType decFullTx =
168170
fail $
169171
"SubTx type is not supported for " <> show (typeRep (Proxy @f))
170172

173+
data STxType t where
174+
SFullTx :: STxType FullTx
175+
SSubTx :: STxType SubTx
176+
171177
-- | A transaction.
172178
class
173179
( EraTxBody era
@@ -186,6 +192,8 @@ class
186192
where
187193
data Tx (t :: TxType) era
188194

195+
txType :: Tx t era -> STxType t
196+
189197
mkBasicTx :: Typeable t => TxBody t era -> Tx t era
190198

191199
bodyTxL :: Lens' (Tx t era) (TxBody t era)
@@ -238,6 +246,8 @@ class
238246
-- | The body of a transaction.
239247
data TxBody (t :: TxType) era
240248

249+
txBodyType :: TxBody t era -> STxType t
250+
241251
mkBasicTxBody :: TxBody FullTx era
242252

243253
inputsTxBodyL :: Lens' (TxBody t era) (Set TxIn)

0 commit comments

Comments
 (0)