@@ -40,14 +40,16 @@ import Control.Monad.Freer.Extras.Modify (raiseEnd)
4040import Control.Monad.Freer.Writer (Writer (Tell ))
4141import Control.Monad.Trans.Class (lift )
4242import Control.Monad.Trans.Either (EitherT , eitherT , firstEitherT , newEitherT )
43- import Data.Aeson (ToJSON , Value )
43+ import Data.Aeson (ToJSON , Value ( String , Number , Bool , Null , Array , Object ) )
4444import Data.Aeson.Extras (encodeByteString )
4545import Data.Either (fromRight )
4646import Data.Kind (Type )
4747import Data.Map qualified as Map
4848import Data.Row (Row )
4949import Data.Text (Text )
5050import Data.Text qualified as Text
51+ import qualified Data.Vector as V
52+ import qualified Data.HashMap.Strict as HM
5153import Ledger (POSIXTime )
5254import Ledger qualified
5355import Ledger.Address (PaymentPubKeyHash (PaymentPubKeyHash ))
@@ -73,7 +75,7 @@ import PlutusTx.Builtins (fromBuiltin)
7375import Wallet.Emulator.Error (WalletAPIError (.. ))
7476import Prelude
7577import Prettyprinter
76- import Data.String ( fromString )
78+ import qualified Prettyprinter as PP
7779
7880runContract ::
7981 forall (w :: Type ) (s :: Row Type ) (e :: Type ) (a :: Type ).
@@ -100,7 +102,22 @@ handleContract contractEnv =
100102 . raiseEnd
101103
102104instance Pretty Value where
103- pretty = fromString . show
105+ pretty (String s) = pretty s
106+ pretty (Number n) = pretty $ show n
107+ pretty (Bool b) = pretty b
108+ pretty (Array arr) = PP. list $ pretty <$> V. toList arr
109+ pretty (Object obj) = PP. group
110+ . PP. encloseSep (PP. flatAlt " { " " {" ) (PP. flatAlt " }" " }" ) " , "
111+ . map
112+ ( \ (k, v) ->
113+ PP. hang 2 $
114+ PP. sep
115+ [ pretty k <+> " : "
116+ , pretty v
117+ ]
118+ )
119+ $ HM. toList obj
120+ pretty Null = " null"
104121
105122handleWriter ::
106123 forall (w :: Type ) (effs :: [Type -> Type ]).
0 commit comments