Skip to content

Commit

Permalink
Addition of helper lens hashDataTxWitsL
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Mar 22, 2023
1 parent 40b875c commit a6b9976
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions eras/alonzo/impl/CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* Stop exporting an internal function `decodeBinaryData`
* Remove redundant `Redeemers'` pattern synonym.
* Move `Cardano.Ledger.Alonzo.Tools` module into `cardano-ledger-api:Cardano.Ledger.Api.Scripts`
* Add helper lens `hashDataTxWitsL`

###`testlib`

Expand Down
12 changes: 11 additions & 1 deletion eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxWits.hs
Expand Up @@ -43,6 +43,7 @@ module Cardano.Ledger.Alonzo.TxWits (
datsAlonzoTxWitsL,
rdmrsAlonzoTxWitsL,
AlonzoEraTxWits (..),
hashDataTxWitsL,
unTxDats,
nullDats,
)
Expand Down Expand Up @@ -92,7 +93,7 @@ import qualified Data.Set as Set
import Data.Typeable (Typeable)
import Data.Word (Word64)
import GHC.Generics (Generic)
import Lens.Micro (Lens')
import Lens.Micro
import NoThunks.Class (NoThunks)

-- ==========================================
Expand Down Expand Up @@ -430,6 +431,15 @@ instance (EraScript (AlonzoEra c), Crypto c) => AlonzoEraTxWits (AlonzoEra c) wh
rdmrsTxWitsL = rdmrsAlonzoTxWitsL
{-# INLINE rdmrsTxWitsL #-}

-- | This is a convenience Lens that will hash the `Data` when it is being added to the
-- `TxWits`. See `datsTxWitsL` for a version that aloows setting `TxDats` instead.
hashDataTxWitsL :: AlonzoEraTxWits era => Lens (TxWits era) (TxWits era) (TxDats era) [Data era]
hashDataTxWitsL =
lens
(\wits -> wits ^. datsTxWitsL)
(\wits ds -> wits & datsTxWitsL .~ TxDats (Map.fromList [(hashData d, d) | d <- ds]))
{-# INLINEABLE hashDataTxWitsL #-}

--------------------------------------------------------------------------------
-- Serialisation
--------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libs/cardano-ledger-api/CHANGELOG.md
Expand Up @@ -36,6 +36,7 @@
* Addition of `evalTxExUnits` and `evalTxExUnitsWithLogs`. Deprecated
`evaluateTransactionExecutionUnits` and `evaluateTransactionExecutionUnitsWithLogs` if
favor of the newly added ones.
* Export `hashDataTxWitsL`

## 1.0.0.0

Expand Down
2 changes: 2 additions & 0 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api/Tx/Wits.hs
Expand Up @@ -22,6 +22,7 @@ module Cardano.Ledger.Api.Tx.Wits (
-- * Alonzo onwards
AlonzoEraTxWits,
datsTxWitsL,
hashDataTxWitsL,
TxDats (..),
unTxDats,
rdmrsTxWitsL,
Expand All @@ -39,6 +40,7 @@ import Cardano.Ledger.Alonzo.TxWits (
Redeemers (..),
TxDats (..),
datsTxWitsL,
hashDataTxWitsL,
rdmrsTxWitsL,
unRedeemers,
unTxDats,
Expand Down

0 comments on commit a6b9976

Please sign in to comment.