Skip to content

Commit 0f11d04

Browse files
committed
Removed TxField
1 parent 4f05c43 commit 0f11d04

File tree

10 files changed

+250
-329
lines changed

10 files changed

+250
-329
lines changed

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxWits.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ import Cardano.Ledger.Shelley.TxWits (
131131
import Control.DeepSeq (NFData)
132132
import Control.Monad (when, (>=>))
133133
import Data.Bifunctor (Bifunctor (first))
134+
import Data.Foldable (Foldable (..))
134135
import qualified Data.List.NonEmpty as NE
135136
import Data.Map.Strict (Map)
136137
import qualified Data.Map.Strict as Map
@@ -142,6 +143,7 @@ import Data.Set (Set)
142143
import qualified Data.Set as Set
143144
import Data.Typeable (Typeable)
144145
import GHC.Generics (Generic)
146+
import GHC.IsList (IsList (..))
145147
import Lens.Micro
146148
import NoThunks.Class (NoThunks)
147149

@@ -399,6 +401,11 @@ instance Era era => Monoid (TxDats era) where
399401
-- | Encodes memoized bytes created upon construction.
400402
instance Era era => EncCBOR (TxDats era)
401403

404+
instance Era era => IsList (TxDats era) where
405+
type Item (TxDats era) = Data era
406+
fromList = foldr' (\x -> (TxDats (Map.singleton (hashData x) x) <>)) mempty
407+
toList (TxDats m) = Map.elems m
408+
402409
-- | Upgrade 'TxDats' from one era to another. The underlying data structure
403410
-- will remain identical, but the memoised serialisation may change to reflect
404411
-- the versioned serialisation of the new era.

libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoAPI.hs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE FlexibleInstances #-}
66
{-# LANGUAGE GADTs #-}
77
{-# LANGUAGE MultiParamTypeClasses #-}
8+
{-# LANGUAGE OverloadedLists #-}
89
{-# LANGUAGE OverloadedStrings #-}
910
{-# LANGUAGE ScopedTypeVariables #-}
1011
{-# LANGUAGE TypeApplications #-}
@@ -14,14 +15,18 @@
1415

1516
module Test.Cardano.Ledger.Examples.AlonzoAPI (tests) where
1617

17-
import Cardano.Ledger.Alonzo.Tx (alonzoMinFeeTx)
18+
import Cardano.Ledger.Alonzo.Tx (alonzoMinFeeTx, hashData)
19+
import Cardano.Ledger.Alonzo.TxWits (TxDats (..))
1820
import Cardano.Ledger.BaseTypes (ProtVer (..), inject, natVersion)
1921
import Cardano.Ledger.Coin (Coin (..))
22+
import Cardano.Ledger.Conway.Core (AlonzoEraTxWits (..))
23+
import Cardano.Ledger.Core (EraTx (..), EraTxWits (..), hashScript)
2024
import Cardano.Ledger.Plutus (ExUnits (..))
2125
import Cardano.Ledger.Plutus.Data (Data (..))
2226
import Cardano.Ledger.Plutus.Language (Language (..))
2327
import Cardano.Ledger.SafeHash (hashAnnotated)
2428
import Cardano.Ledger.Tools (estimateMinFeeTx)
29+
import Lens.Micro ((&), (.~))
2530
import qualified PlutusLedgerApi.V1 as PV1
2631
import Test.Cardano.Ledger.Core.KeyPair (mkWitnessVKey)
2732
import Test.Cardano.Ledger.Examples.STSTestUtils (
@@ -34,9 +39,7 @@ import Test.Cardano.Ledger.Examples.STSTestUtils (
3439
import Test.Cardano.Ledger.Generic.Fields (
3540
PParamsField (..),
3641
TxBodyField (..),
37-
TxField (..),
3842
TxOutField (..),
39-
WitnessesField (..),
4043
)
4144
import Test.Cardano.Ledger.Generic.GenState (PlutusPurposeTag (..))
4245
import Test.Cardano.Ledger.Generic.Proof
@@ -62,27 +65,16 @@ testEstimateMinFee =
6265
where
6366
pf = Alonzo
6467
pparams = newPParams pf $ defaultPPs ++ [MinfeeA (Coin 1)]
68+
script = always 3 pf
69+
dat = Data (PV1.I 123)
6570
validatingTxNoWits =
66-
newTx
67-
pf
68-
[ Body validatingBody
69-
, WitnessesI
70-
[ ScriptWits' [always 3 pf]
71-
, DataWits' [Data (PV1.I 123)]
72-
, RdmrWits redeemers
73-
]
74-
]
71+
mkBasicTx validatingBody
72+
& witsTxL . scriptTxWitsL .~ [(hashScript script, script)]
73+
& witsTxL . datsTxWitsL .~ TxDats [(hashData dat, dat)]
74+
& witsTxL . rdmrsTxWitsL .~ redeemers
7575
validatingTx =
76-
newTx
77-
pf
78-
[ Body validatingBody
79-
, WitnessesI
80-
[ AddrWits' [mkWitnessVKey (hashAnnotated validatingBody) (someKeys pf)]
81-
, ScriptWits' [always 3 pf]
82-
, DataWits' [Data (PV1.I 123)]
83-
, RdmrWits redeemers
84-
]
85-
]
76+
validatingTxNoWits
77+
& witsTxL . addrTxWitsL .~ [mkWitnessVKey (hashAnnotated validatingBody) (someKeys pf)]
8678
validatingBody =
8779
newTxBody
8880
pf

0 commit comments

Comments
 (0)