I want to check on-chain if a given TokenName
is of a specific pattern, for example:
aaa1
aaa2
aaa3
I have something like this, but it throws an interpreter exception:
checkValidMint :: TokenName -> Integer -> Bool
checkValidMint tn count = tn == (TokenName $ "aaa" <> (integerToByteString count))
integerToByteString :: Integer -> BuiltinByteString
integerToByteString n
| n == 0 = "0"
| n == 1 = "1"
| n == 2 = "2"
| n == 3 = "3"
| n == 4 = "4"
| n == 5 = "5"
| n == 6 = "6"
| n == 7 = "7"
| n == 8 = "8"
| n == 9 = "9"
| otherwise = integerToByteString (n `P.divide` 10) P.<> integerToByteString (n `P.modulo` 10)
Update 2 Also tried:
integerToByteString n
| (Builtins.equalsInteger n 0) = "0"
| (Builtins.equalsInteger n 1) = "1"
| (Builtins.equalsInteger n 2) = "2"
| (Builtins.equalsInteger n 3) = "3"
| (Builtins.equalsInteger n 4) = "4"
| (Builtins.equalsInteger n 5) = "5"
| (Builtins.equalsInteger n 6) = "6"
| (Builtins.equalsInteger n 7) = "7"
| (Builtins.equalsInteger n 8) = "8"
| (Builtins.equalsInteger n 9) = "9"
| otherwise = integerToByteString (n `PlutusTx.Prelude.divide` 10) PP.<> integerToByteString (n `PlutusTx.Prelude.modulo` 10)
I keep getting an interpreter error:
GHC Core to PLC plugin: E042:Error: Unsupported feature: Use of Haskell Integer equality, possibly via the Haskell Eq typeclass Context: Compiling expr: GHC.Integer.Type.eqInteger# Context: Compiling expr: GHC.Integer.Type.eqInteger# x Context: Compiling expr: GHC.Integer.Type.eqInteger# x y Context: Compiling expr: case GHC.Integer.Type.eqInteger# x y of wild [Occ=Once] { __DEFAULT -> GHC.Prim.tagToEnum# @ GHC.Types.Bool wild } Context: Compiling expr: \ (y [Occ=Once] :: GHC.Integer.Type.Integer) -> case GHC.Integer.Type.eqInteger# x y of ...