module Cooked.Pretty.Options
( PrettyCookedOpts (..),
PrettyCookedHashOpts (..),
PCOptTxOutRefs (..),
hashNamesFromList,
defaultHashNames,
)
where
import Cooked.Conversion.ToHash
import Cooked.Currencies (permanentCurrencySymbol, quickCurrencySymbol)
import Cooked.Wallet (wallet)
import Data.Bifunctor (first)
import Data.Default
import Data.Map (Map)
import Data.Map qualified as Map
import PlutusLedgerApi.V3 qualified as Api
data PrettyCookedOpts = PrettyCookedOpts
{
PrettyCookedOpts -> Bool
pcOptPrintTxHashes :: Bool,
PrettyCookedOpts -> PCOptTxOutRefs
pcOptPrintTxOutRefs :: PCOptTxOutRefs,
PrettyCookedOpts -> Bool
pcOptPrintDefaultTxOpts :: Bool,
PrettyCookedOpts -> Bool
pcOptNumericUnderscores :: Bool,
PrettyCookedOpts -> PrettyCookedHashOpts
pcOptHashes :: PrettyCookedHashOpts,
PrettyCookedOpts -> Bool
pcOptPrintLog :: Bool
}
deriving (PrettyCookedOpts -> PrettyCookedOpts -> Bool
(PrettyCookedOpts -> PrettyCookedOpts -> Bool)
-> (PrettyCookedOpts -> PrettyCookedOpts -> Bool)
-> Eq PrettyCookedOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PrettyCookedOpts -> PrettyCookedOpts -> Bool
== :: PrettyCookedOpts -> PrettyCookedOpts -> Bool
$c/= :: PrettyCookedOpts -> PrettyCookedOpts -> Bool
/= :: PrettyCookedOpts -> PrettyCookedOpts -> Bool
Eq, Int -> PrettyCookedOpts -> ShowS
[PrettyCookedOpts] -> ShowS
PrettyCookedOpts -> String
(Int -> PrettyCookedOpts -> ShowS)
-> (PrettyCookedOpts -> String)
-> ([PrettyCookedOpts] -> ShowS)
-> Show PrettyCookedOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PrettyCookedOpts -> ShowS
showsPrec :: Int -> PrettyCookedOpts -> ShowS
$cshow :: PrettyCookedOpts -> String
show :: PrettyCookedOpts -> String
$cshowList :: [PrettyCookedOpts] -> ShowS
showList :: [PrettyCookedOpts] -> ShowS
Show)
instance Default PrettyCookedOpts where
def :: PrettyCookedOpts
def =
PrettyCookedOpts
{ pcOptPrintTxHashes :: Bool
pcOptPrintTxHashes = Bool
False,
pcOptPrintTxOutRefs :: PCOptTxOutRefs
pcOptPrintTxOutRefs = PCOptTxOutRefs
PCOptTxOutRefsHidden,
pcOptPrintDefaultTxOpts :: Bool
pcOptPrintDefaultTxOpts = Bool
False,
pcOptNumericUnderscores :: Bool
pcOptNumericUnderscores = Bool
True,
pcOptHashes :: PrettyCookedHashOpts
pcOptHashes = PrettyCookedHashOpts
forall a. Default a => a
def,
pcOptPrintLog :: Bool
pcOptPrintLog = Bool
True
}
data PCOptTxOutRefs
=
PCOptTxOutRefsHidden
|
PCOptTxOutRefsFull
|
PCOptTxOutRefsPartial
deriving (PCOptTxOutRefs -> PCOptTxOutRefs -> Bool
(PCOptTxOutRefs -> PCOptTxOutRefs -> Bool)
-> (PCOptTxOutRefs -> PCOptTxOutRefs -> Bool) -> Eq PCOptTxOutRefs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PCOptTxOutRefs -> PCOptTxOutRefs -> Bool
== :: PCOptTxOutRefs -> PCOptTxOutRefs -> Bool
$c/= :: PCOptTxOutRefs -> PCOptTxOutRefs -> Bool
/= :: PCOptTxOutRefs -> PCOptTxOutRefs -> Bool
Eq, Int -> PCOptTxOutRefs -> ShowS
[PCOptTxOutRefs] -> ShowS
PCOptTxOutRefs -> String
(Int -> PCOptTxOutRefs -> ShowS)
-> (PCOptTxOutRefs -> String)
-> ([PCOptTxOutRefs] -> ShowS)
-> Show PCOptTxOutRefs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PCOptTxOutRefs -> ShowS
showsPrec :: Int -> PCOptTxOutRefs -> ShowS
$cshow :: PCOptTxOutRefs -> String
show :: PCOptTxOutRefs -> String
$cshowList :: [PCOptTxOutRefs] -> ShowS
showList :: [PCOptTxOutRefs] -> ShowS
Show)
data PrettyCookedHashOpts = PrettyCookedHashOpts
{
PrettyCookedHashOpts -> Int
pcOptHashLength :: Int,
PrettyCookedHashOpts -> Map BuiltinByteString String
pcOptHashNames :: Map Api.BuiltinByteString String,
PrettyCookedHashOpts -> Bool
pcOptHashVerbose :: Bool
}
deriving (PrettyCookedHashOpts -> PrettyCookedHashOpts -> Bool
(PrettyCookedHashOpts -> PrettyCookedHashOpts -> Bool)
-> (PrettyCookedHashOpts -> PrettyCookedHashOpts -> Bool)
-> Eq PrettyCookedHashOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PrettyCookedHashOpts -> PrettyCookedHashOpts -> Bool
== :: PrettyCookedHashOpts -> PrettyCookedHashOpts -> Bool
$c/= :: PrettyCookedHashOpts -> PrettyCookedHashOpts -> Bool
/= :: PrettyCookedHashOpts -> PrettyCookedHashOpts -> Bool
Eq, Int -> PrettyCookedHashOpts -> ShowS
[PrettyCookedHashOpts] -> ShowS
PrettyCookedHashOpts -> String
(Int -> PrettyCookedHashOpts -> ShowS)
-> (PrettyCookedHashOpts -> String)
-> ([PrettyCookedHashOpts] -> ShowS)
-> Show PrettyCookedHashOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PrettyCookedHashOpts -> ShowS
showsPrec :: Int -> PrettyCookedHashOpts -> ShowS
$cshow :: PrettyCookedHashOpts -> String
show :: PrettyCookedHashOpts -> String
$cshowList :: [PrettyCookedHashOpts] -> ShowS
showList :: [PrettyCookedHashOpts] -> ShowS
Show)
instance Default PrettyCookedHashOpts where
def :: PrettyCookedHashOpts
def =
PrettyCookedHashOpts
{ pcOptHashLength :: Int
pcOptHashLength = Int
7,
pcOptHashNames :: Map BuiltinByteString String
pcOptHashNames = Map BuiltinByteString String
defaultHashNames,
pcOptHashVerbose :: Bool
pcOptHashVerbose = Bool
False
}
defaultHashNames :: Map Api.BuiltinByteString String
defaultHashNames :: Map BuiltinByteString String
defaultHashNames =
[(CurrencySymbol, String)] -> Map BuiltinByteString String
forall a. ToHash a => [(a, String)] -> Map BuiltinByteString String
hashNamesFromList
[ (BuiltinByteString -> CurrencySymbol
Api.CurrencySymbol BuiltinByteString
"", String
"Lovelace"),
(CurrencySymbol
quickCurrencySymbol, String
"Quick"),
(CurrencySymbol
permanentCurrencySymbol, String
"Permanent")
]
Map BuiltinByteString String
-> Map BuiltinByteString String -> Map BuiltinByteString String
forall a. Semigroup a => a -> a -> a
<> [(Wallet, String)] -> Map BuiltinByteString String
forall a. ToHash a => [(a, String)] -> Map BuiltinByteString String
hashNamesFromList
((\Integer
i -> (Integer -> Wallet
wallet Integer
i, String
"wallet " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Integer -> String
forall a. Show a => a -> String
show Integer
i)) (Integer -> (Wallet, String)) -> [Integer] -> [(Wallet, String)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Integer
1 .. Integer
10])
hashNamesFromList :: (ToHash a) => [(a, String)] -> Map Api.BuiltinByteString String
hashNamesFromList :: forall a. ToHash a => [(a, String)] -> Map BuiltinByteString String
hashNamesFromList = [(BuiltinByteString, String)] -> Map BuiltinByteString String
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(BuiltinByteString, String)] -> Map BuiltinByteString String)
-> ([(a, String)] -> [(BuiltinByteString, String)])
-> [(a, String)]
-> Map BuiltinByteString String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, String) -> (BuiltinByteString, String))
-> [(a, String)] -> [(BuiltinByteString, String)]
forall a b. (a -> b) -> [a] -> [b]
map ((a -> BuiltinByteString)
-> (a, String) -> (BuiltinByteString, String)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> BuiltinByteString
forall a. ToHash a => a -> BuiltinByteString
toHash)