Skip to content

Commit 5ae5161

Browse files
committed
Add withTxType
1 parent a36a718 commit 5ae5161

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockBody/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import Lens.Micro hiding (ix)
8282
import NoThunks.Class (AllowThunksIn (..), NoThunks (..))
8383

8484
data ShelleyBlockBody era = ShelleyBlockBodyInternal
85-
{ sbbTxs :: !(StrictSeq (Tx era))
85+
{ sbbTxs :: !(StrictSeq (Tx FullTx era))
8686
, sbbHash :: Hash.Hash HASH EraIndependentBlockBody
8787
-- ^ Memoized hash to avoid recomputation. Lazy on purpose.
8888
, sbbTxsBodyBytes :: BSL.ByteString

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ txinsScriptHashes txInps (UTxO u) = foldr add Set.empty txInps
103103
getShelleyScriptsNeeded ::
104104
EraTxBody era =>
105105
UTxO era ->
106-
TxBody era ->
106+
TxBody t era ->
107107
ShelleyScriptsNeeded era
108108
getShelleyScriptsNeeded u txBody =
109109
ShelleyScriptsNeeded
@@ -124,7 +124,7 @@ shelleyConsumed ::
124124
PParams era ->
125125
CertState era ->
126126
UTxO era ->
127-
TxBody era ->
127+
TxBody t era ->
128128
Value era
129129
shelleyConsumed pp certState =
130130
getConsumedValue
@@ -138,7 +138,7 @@ produced ::
138138
(EraUTxO era, EraCertState era) =>
139139
PParams era ->
140140
CertState era ->
141-
TxBody era ->
141+
TxBody t era ->
142142
Value era
143143
produced pp certState =
144144
getProducedValue pp (flip Map.member $ certState ^. certPStateL . psStakePoolsL)
@@ -148,7 +148,7 @@ shelleyProducedValue ::
148148
PParams era ->
149149
-- | Check whether a pool with a supplied PoolStakeId is already registered.
150150
(KeyHash 'StakePool -> Bool) ->
151-
TxBody era ->
151+
TxBody FullTx era ->
152152
Value era
153153
shelleyProducedValue pp isRegPoolId txBody =
154154
sumAllValue (txBody ^. outputsTxBodyL)
@@ -162,7 +162,7 @@ getConsumedCoin ::
162162
PParams era ->
163163
(Credential 'Staking -> Maybe Coin) ->
164164
UTxO era ->
165-
TxBody era ->
165+
TxBody t era ->
166166
Coin
167167
getConsumedCoin pp lookupRefund utxo txBody =
168168
{- balance (txins tx ◁ u) + wbalance (txwdrls tx) + keyRefunds dpstate tx -}
@@ -191,25 +191,28 @@ instance EraUTxO ShelleyEra where
191191

192192
getScriptsHashesNeeded (ShelleyScriptsNeeded scriptsHashes) = scriptsHashes
193193

194-
getWitsVKeyNeeded = getShelleyWitsVKeyNeeded
194+
getWitsVKeyNeeded certState utxo = getShelleyWitsVKeyNeeded certState utxo
195195

196196
getMinFeeTxUtxo pp tx _ = getShelleyMinFeeTxUtxo pp tx
197197

198198
-- We don't consider the reference scripts in the calculation before Conway
199-
getShelleyMinFeeTxUtxo :: EraTx era => PParams era -> Tx era -> Coin
199+
getShelleyMinFeeTxUtxo :: EraTx era => PParams era -> Tx t era -> Coin
200200
getShelleyMinFeeTxUtxo pparams tx = getMinFeeTx pparams tx 0
201201

202202
-- | Collect the set of hashes of keys that needs to sign a
203203
-- given transaction. This set consists of the txin owners,
204204
-- certificate authors, and withdrawal reward accounts.
205205
witsVKeyNeededGenDelegs ::
206-
forall era.
206+
forall era t.
207207
ShelleyEraTxBody era =>
208-
TxBody era ->
208+
TxBody FullTx era ->
209209
GenDelegs ->
210210
Set (KeyHash 'Witness)
211211
witsVKeyNeededGenDelegs txBody (GenDelegs genDelegs) =
212-
asWitness `Set.map` proposedUpdatesWitnesses (txBody ^. updateTxBodyL)
212+
withTxType
213+
txBody
214+
(\fullTxBody -> asWitness `Set.map` proposedUpdatesWitnesses (fullTxBody ^. updateTxBodyL))
215+
(const mempty)
213216
where
214217
-- Calculate the set of hash keys of the required witnesses for update
215218
-- proposals.
@@ -224,10 +227,10 @@ witsVKeyNeededGenDelegs txBody (GenDelegs genDelegs) =
224227
-- | Extract witnesses from UTxO and TxBody. Does not enforce witnesses for governance
225228
-- related Keys, i.e. `GenDelegs`
226229
getShelleyWitsVKeyNeededNoGov ::
227-
forall era.
230+
forall era t.
228231
EraTx era =>
229232
UTxO era ->
230-
TxBody era ->
233+
TxBody t era ->
231234
Set (KeyHash 'Witness)
232235
getShelleyWitsVKeyNeededNoGov utxo' txBody =
233236
certAuthors
@@ -276,7 +279,7 @@ getShelleyWitsVKeyNeeded ::
276279
(EraTx era, ShelleyEraTxBody era, EraCertState era) =>
277280
CertState era ->
278281
UTxO era ->
279-
TxBody era ->
282+
TxBody FullTx era ->
280283
Set (KeyHash 'Witness)
281284
getShelleyWitsVKeyNeeded certState utxo txBody =
282285
getShelleyWitsVKeyNeededNoGov utxo txBody

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
module Cardano.Ledger.Core (
2828
-- * Transaction types
2929
TxType (..),
30+
withTxType,
3031
applyTxType,
3132
applyFullTxType,
3233

@@ -141,6 +142,15 @@ import NoThunks.Class (NoThunks)
141142

142143
type data TxType = FullTx | SubTx
143144

145+
withTxType ::
146+
forall f t a era. Typeable t => f t era -> (f FullTx era -> a) -> (f SubTx era -> a) -> a
147+
withTxType txType withFullTxType withSubTxType =
148+
case eqT @t @FullTx of
149+
Just Refl -> withFullTxType txType
150+
Nothing -> case eqT @t @SubTx of
151+
Just Refl -> withSubTxType txType
152+
Nothing -> error $ "Impossible: Unrecognized TxType: " <> show (typeRep (Proxy @t))
153+
144154
applyTxType ::
145155
forall f t m era. (Typeable t, HasCallStack) => m (f FullTx era) -> m (f SubTx era) -> m (f t era)
146156
applyTxType decFullTx decSubTx =

0 commit comments

Comments
 (0)