I'm not sure is relevant but the code in question is for a generic Validator (with Datums and Redeemers) used to get a forwarded minting policy
the problem should be clear from the title, I can't get to construct a TokenName
value starting form a ``ByteString```
I assume the rror is dued to the plutus-tx-plugin
library so all the ghc-options
specified in the troubleshooting section for the Plutus documentation are enabled (without much success)
the error I get is the following
GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.Char#
Context: Compiling type: GHC.Prim.Char#
Context: Compiling data constructor type: GHC.Types.C#
Context: Compiling type: GHC.Types.Char
Context: Compiling type: GHC.Base.String
Context: Compiling expr: PlutusTx.Base.$ @ GHC.Base.String
Context: Compiling expr: PlutusTx.Base.$
@ GHC.Base.String @ Plutus.V1.Ledger.Value.TokenName
Context: Compiling expr: PlutusTx.Base.$
@ GHC.Base.String
@ Plutus.V1.Ledger.Value.TokenName
(PlutusTx.Base..
@ Data.ByteString.Internal.ByteString
@ Plutus.V1.Ledger.Value.TokenName
@ GHC.Base.String
Plutus.V1.Ledger.Value.tokenName
Data.ByteString.Char8.pack)
and keeps expanding for a while...
I know for sure (by commenting out) the code causing this is the following:
NOTE: I've commented out everything related to
collectionCurrencySymbol
from the moment that is causing problems too and I'll likely change it, any idea is welcome but is not the main point of the question
expectedTokenName :: Value.TokenName
expectedTokenName = Value.tokenName $ "My Awesome NFT collection #" <> integerToBS8 datumCounter
-- collectionCurrencySymbol :: Value.CurrencySymbol
-- collectionCurrencySymbol = (Value.mpsSymbol . Ledger.mintingPolicyHash . mkForwardingMintingPolicy ) (Ctx.ownHash ctx)
singleTokenMinted :: PTxP.Bool
singleTokenMinted =
case Value.flattenValue (txInfoMint ( Ctx.scriptContextTxInfo ctx) ) of
[( mintedCurrencySym , mintedTokenName , mintedAmount )] ->
-- mintedCurrencySym == collectionCurrencySymbol PTxP.&&
mintedTokenName == expectedTokenName PTxP.&&
mintedAmount == 1
_ ->
traceError "minting more than 1 AssetClass"
where integerToBS8
is as simple as :
{-# INLINEABLE integerToBS8 #-}
integerToBS8 :: Integer -> BS8.ByteString
integerToBS8 int
| int == 0 = BS8.pack "0"
| int == 1 = BS8.pack "1"
| int == 2 = BS8.pack "2"
| int == 3 = BS8.pack "3"
| int == 4 = BS8.pack "4"
| int == 5 = BS8.pack "5"
| int == 6 = BS8.pack "6"
| int == 7 = BS8.pack "7"
| int == 8 = BS8.pack "8"
| int == 9 = BS8.pack "9"
| otherwise = integerToBS8 ( int `div` 10 ) <> integerToBS8 ( int `mod` 10 )
some conventions I use
import qualified Data.ByteString.Char8 as BS8
import qualified Ledger.Contexts as Ctx
import qualified Ledger.Value as Value
import qualified Ledger
import PlutusTx.Prelude as PTxP
It seems to me GHC
just doesn't like raw strings (since OverloadedStrings
is just adding silently a bunch of pack
form the IsString
typeclass where needed)
any idea on what's wrong?