-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #664 from IntersectMBO/show-redeemer
Display redeemers in `transaction view`
- Loading branch information
Showing
12 changed files
with
232 additions
and
36 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
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,82 @@ | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Cardano.CLI.Types.MonadWarning | ||
-- | ||
-- This module defines the 'MonadWarning' type class, which provides a common | ||
-- interface for monads that support reporting warning messages without | ||
-- aborting the computation (unlike with exceptions, Either, or MonadFail, | ||
-- which either fail or return a value). | ||
-- | ||
-- It also includes two functions that instantiate it into either a 'MonadIO' | ||
-- ('runWarningIO') or a 'StateT' monad with a '[String]' as state | ||
-- ('runWarningStateT') respectively. | ||
-- | ||
-- In the case of 'MonadIO', warnings are printed to 'stderr'. | ||
-- In the case of 'StateT', with a '[String]' state, warnings are added to the | ||
-- list in the state. | ||
-- | ||
-- By using the 'MonadWarning' type class, users can write code that remains | ||
-- agnostic to the specific monad in which it operates, and to easily change | ||
-- it at a later stage if necessary. | ||
-- | ||
-- Example usage: | ||
-- | ||
-- @ | ||
-- computeWithWarning :: (MonadWarning m) => Int -> m Int | ||
-- computeWithWarning x = do | ||
-- when (x < 0) $ reportIssue "Input value is negative!" | ||
-- return (x * 2) | ||
-- | ||
-- -- Using 'IO' monad to perform computation and report warnings. | ||
-- main :: IO () | ||
-- main = do | ||
-- result <- runWarningIO $ computeWithWarning (-4) | ||
-- putStrLn $ "Result: " ++ show result | ||
-- @ | ||
----------------------------------------------------------------------------- | ||
|
||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE InstanceSigs #-} | ||
|
||
module Cardano.CLI.Types.MonadWarning | ||
( MonadWarning(..) | ||
, eitherToWarning | ||
, runWarningIO | ||
, runWarningStateT | ||
) where | ||
|
||
import Control.Monad.IO.Class (MonadIO, liftIO) | ||
import Control.Monad.State (MonadState (..)) | ||
import Control.Monad.Trans.State (StateT) | ||
import System.IO (hPutStrLn, stderr) | ||
|
||
-- | Type class for monads that support reporting warnings. | ||
class Monad m => MonadWarning m where | ||
-- | Report a warning issue. | ||
reportIssue :: String -- ^ The warning message to report. | ||
-> m () -- ^ The action that reports the warning. | ||
|
||
-- | Wrapper newtype for 'MonadIO' with 'MonadWarning' instance. | ||
-- We need to have wrapper to avoid overlapping instances. | ||
newtype WarningIO m a = WarningIO { runWarningIO :: m a } | ||
deriving (Functor, Applicative, Monad, MonadIO) | ||
|
||
-- | This instance prints the issue to the 'stderr'. | ||
instance MonadIO m => MonadWarning (WarningIO m) where | ||
reportIssue :: String -> WarningIO m () | ||
reportIssue issue = liftIO (hPutStrLn stderr issue) | ||
|
||
-- | Wrapper newtype for 'StateT [String]' with 'MonadWarning' instance. | ||
newtype WarningStateT m a = WarningStateT { runWarningStateT :: StateT [String] m a } | ||
deriving (Functor, Applicative, Monad, MonadState [String]) | ||
|
||
-- | This instance adds the issue to the '[String]' in the state. | ||
instance Monad m => MonadWarning (WarningStateT m) where | ||
reportIssue :: String -> WarningStateT m () | ||
reportIssue issue = state (\ x -> ((), issue : x)) | ||
|
||
-- | Convert an 'Either' into a 'MonadWarning'. If 'Either' is 'Left' | ||
-- it returns the default value (first parameter) and reports the value | ||
-- as an error. -- If 'Either' is 'Right' it just returns the value. | ||
eitherToWarning :: MonadWarning m => a -> Either String a -> m a | ||
eitherToWarning def = either (\issue -> do {reportIssue issue; return def}) return |
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
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
26 changes: 26 additions & 0 deletions
26
cardano-cli/test/cardano-cli-golden/files/golden/babbage/transaction-view-redeemer.out
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,26 @@ | ||
auxiliary scripts: null | ||
certificates: null | ||
collateral inputs: | ||
- c9765d7d0e3955be8920e6d7a38e1f3f2032eac48c7c59b0b9193caa87727e7e#256 | ||
era: Babbage | ||
fee: 213 Lovelace | ||
inputs: | ||
- ed7c8f68c194cc763ee65ad22ef0973e26481be058c65005fd39fb93f9c43a20#213 | ||
metadata: null | ||
mint: null | ||
outputs: [] | ||
redeemers: | ||
- - 0 | ||
- 0 | ||
- 42 | ||
- - 200 | ||
- 100 | ||
reference inputs: [] | ||
required signers (payment key hashes needed for scripts): null | ||
return collateral: null | ||
total collateral: null | ||
update proposal: null | ||
validity range: | ||
lower bound: null | ||
upper bound: null | ||
withdrawals: null |
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
5 changes: 5 additions & 0 deletions
5
cardano-cli/test/cardano-cli-golden/files/input/AlwaysSucceeds.plutus
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,5 @@ | ||
{ | ||
"type": "PlutusScriptV1", | ||
"description": "", | ||
"cborHex": "4e4d01000033222220051200120011" | ||
} |
Oops, something went wrong.