Skip to content

Commit

Permalink
[ADP-3215] Add getScriptValidity to read (#4741)
Browse files Browse the repository at this point in the history
This pull request adds a function `getScriptValidity` to the
`Cardano.Wallet.Read` module hierarchy. We re-export the type `IsValid`
from the Shelley ledger codebase, as it works well.

### Issue Number

ADP-3215
  • Loading branch information
HeinrichApfelmus authored Aug 19, 2024
2 parents 999ab4b + 98d6a5a commit da79c6c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/read/cardano-wallet-read.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ library
Cardano.Wallet.Read.Tx.Gen.Shelley
Cardano.Wallet.Read.Tx.Gen.TxParameters
Cardano.Wallet.Read.Tx.Inputs
Cardano.Wallet.Read.Tx.ScriptValidity
Cardano.Wallet.Read.Tx.TxId
Cardano.Wallet.Read.Tx.TxIn
Cardano.Wallet.Read.Value
Expand Down
53 changes: 53 additions & 0 deletions lib/read/lib/Cardano/Wallet/Read/Tx/ScriptValidity.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}

{- |
Copyright: © 2024 IOHK
License: Apache-2.0
Script validity of a transaction.
-}
module Cardano.Wallet.Read.Tx.ScriptValidity
( IsValid (IsValid)
, getScriptValidity
) where

import Prelude

import Cardano.Ledger.Alonzo.Tx
( IsValid (..)
)
import Cardano.Read.Ledger.Tx.ScriptValidity
( ScriptValidity (..)
, ScriptValidityType
, getEraScriptValidity
)
import Cardano.Wallet.Read.Eras
( Era (..)
, IsEra (..)
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)

{-# INLINABLE getScriptValidity #-}
getScriptValidity :: forall era. IsEra era => Tx era -> IsValid
getScriptValidity = case theEra :: Era era of
Byron -> onScriptValidity trueValid
Shelley -> onScriptValidity trueValid
Allegra -> onScriptValidity trueValid
Mary -> onScriptValidity trueValid
Alonzo -> onScriptValidity id
Babbage -> onScriptValidity id
Conway -> onScriptValidity id
where
trueValid = const (IsValid True)

-- Helper function for type inference.
onScriptValidity
:: IsEra era
=> (ScriptValidityType era -> t)
-> Tx era -> t
onScriptValidity f x =
case getEraScriptValidity x of
ScriptValidity v -> f v

0 comments on commit da79c6c

Please sign in to comment.