I had trouble with the same thing, just going the opposite direction, Slot -> TokenName
(Slot
is just an Integer
under the hood). After a bunch of pain I ended up just coding my own parsing logic:
-- Simplified business code here:
{-# INLINEABLE dcForSlot #-}
tokenNameForSlot :: Slot -> TokenName
tokenNameForSlot slot = TokenName $ Builtins.encodeUtf8 $ intToString $ getSlot slot
{-# INLINEABLE intToString #-}
intToString :: Integer -> Builtins.String
intToString i = Prelude.foldr Builtins.appendString "" strings
where
ints = intToInts i
strings = map (Builtins.charToString . intToChar) ints
{-# INLINEABLE intToInts #-}
intToInts :: Integer -> [Integer]
intToInts i
| (Builtins.equalsInteger a 0) = [b]
| otherwise = (intToInts a) ++ [b]
where
(a, b) = divMod i 10
{-# INLINEABLE intToChar #-}
intToChar :: Integer -> Haskell.Char
intToChar i
| (Builtins.equalsInteger i 0) = '0'
| (Builtins.equalsInteger i 1) = '1'
| (Builtins.equalsInteger i 2) = '2'
| (Builtins.equalsInteger i 3) = '3'
| (Builtins.equalsInteger i 4) = '4'
| (Builtins.equalsInteger i 5) = '5'
| (Builtins.equalsInteger i 6) = '6'
| (Builtins.equalsInteger i 7) = '7'
| (Builtins.equalsInteger i 8) = '8'
| (Builtins.equalsInteger i 9) = '9'
| otherwise = '0' -- Fix this
Feel free to try and reverse this to get what you want. It might be easier going the other direction, I don't have time rn to figure out what it would look like but I feel your pain, so I thought I'd share.