IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.56k stars 479 forks source link

Way to trace haskell types in on-chain code? #3960

Closed v0d1ch closed 2 years ago

v0d1ch commented 3 years ago

Area

[x] Plutus Foundation Related to the GHC plugin, Haskell-to-Plutus compiler, on-chain code [] Plutus Application Framework Related to the Plutus application backend (PAB), emulator, Plutus libraries [] Marlowe Related to Marlowe [] Other Any other topic (Playgrounds, etc.)

Is there a way to print datum/redeemer types in the script validator? My validator looks like this:

{-# INLINABLE mkContribValidator #-}
mkContribValidator :: FlemingDatum -> FlemingRedeemer -> ScriptContext -> P.Bool
mkContribValidator dat r scr = 
  case r of
    Contribute -> validateContribution dat r (scriptContextTxInfo scr)
    Payout     -> validateContribution dat r (scriptContextTxInfo scr)

When I use it unfortunately I get Plutus Error which doesn't give any context so I used just a dummy validator that always returns True and wanted to trace the datum/redeemer values like so:

mkContribValidator :: FlemingDatum -> FlemingRedeemer -> ScriptContext -> P.Bool
mkContribValidator dat _r _scr = traceIfTrue (pack (show dat)) True

So traceIfTrue accepts a BuiltinString and Bool and I am having some problems creating a BuiltinString from my datum type.

The module PlutusTx.Builtins.Internal is where the BuiltinString is defined but I don't see that data constructor is exported or any other helper function to create such value although it just wraps Text.

I even tried importing the internal module but that gives me GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.Char

So my question is how to go about this problem?

luigy commented 3 years ago

Reminds me of https://github.com/input-output-hk/plutus/issues/3164 and certainly has plenty value for debugging, but unfortunately there hasn't been bandwidth for anyone to get around to it yet last time I checked

ghost commented 2 years ago

I'm closing the issue as a duplicate and @luigy linked the original one.

And yeah, it won't happen anytime soon.