-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |