Closed tdiesler closed 3 years ago
I'm generally having a hard time comparing variants of string
-- GHC Core to PLC plugin: E043:Error: Reference to a name which is not a local, a builtin, or an external INLINABLE function: Variable GHC.List.$wlenAcc
("abc" :: ByteString) == ("abc" :: ByteString)
-- No instance for (Eq Char) arising from a use of ‘==’
("abc" :: String) == ("abc" :: String)
-- No instance for (Eq Text) arising from a use of ‘==’
("abc" :: Text) == ("abc" :: Text)
PlutusTx.==
instead of Prelude.==
.TokenName
is a newtype around Builtins.ByteString
which has PlutusTx.Eq
instance.
-- GHC Core to PLC plugin: E043:Error: Reference to a name which is not a local, a builtin, or an external INLINABLE function: Variable GHC.List.$wlenAcc ("abc" :: ByteString) == ("abc" :: ByteString)
This error happens because ByteString
literals are not supported yet (#3156). Will be fixed in the future.
3.
-- No instance for (Eq Char) arising from a use of ‘==’ ("abc" :: String) == ("abc" :: String)
The error happens here because there is no instance PlutusTx.Eq
for Prelude.Char
since String = [Char]
in Prelude
. And there is no way to compare two String
's yet. It should be implemented in the future. Thanks for raising the priority of that!
4.
-- No instance for (Eq Text) arising from a use of ‘==’ ("abc" :: Text) == ("abc" :: Text)
Yeah, Text
is unsupported (there is no instance for PlutusTx.Eq
class. Only ByteString
and String
.
I have ...
import qualified PlutusTx as PlutusTx
import PlutusTx.Prelude hiding (Semigroup(..))
import Prelude (Semigroup (..))
and later ...
This gives me ...
Could you perhaps show me how to construct a TokenName from a String and an Integer and then compare that to the TokenName that the caller provided?
The code is here ... https://github.com/tdiesler/plutus-pioneer-program/blob/pl3246b/code/payout/src/Astor/Payout.hs#L287
==
is exported by PlutusTx.Prelude
, not PlutusTx
.
So it should be:
import qualified PlutusTx.Prelude as Plutus
import Prelude (Semigroup (..))
...
Plutus.==
TokenName
is constructed by calling TokenName
constructor (from Ledger
module) applied to ByteString
:
exptn :: TokenName
exptn = TokenName "Astor260"
"Astor260"
here should be ByteString
.
Could you perhaps show me how to construct a TokenName from a String and an Integer and then compare that to the TokenName that the caller provided?
It's not possible yet unfortunately. There is no way to transform integer into String
or ByteString
.
You may try to declare a pair (ByteString, Integer)
and compare tuples.
Thanks. Could I perhaps extract the Integer suffix from the caller provided TokenName? For example, everything after the first five bytes should read
as an Integer.
Well, there is dropByteString
that allows to get the suffix as a ByteString
. And then you can compare it to other ByteString
s.
I have a 260 :: Integer
and need to validate that the caller provides an "Astor260" :: TokenName
.
I would either need to turn the TokenName suffix into an Integer and compare the two Integers or the Integer that I have into a BytesString and then compare those. From what we said above, it is not (yet) possible construct a TokenName from a String prefix plus Integer - like this ("Astor" ++ (show 260)) :: TokenName
so that I could simple compare two TokenNames.
How would you validate the given TokenName?
Again, it's not possible to convert Integer
to any string yet in on-chain code.
You can take the suffix and parse it for example:
let suffix = dropByteString 5 "Astor260" in
case suffix of
"260" -> handleTheSituationWhenSuffixIs260
_ -> ...
How about this ...
I can construct the token name from String+Integer in off-chain code and put it in the Datum. In on-chain code, I now have both, the epoch Integer and the associated TokenName (which I cannot construct in on-chain code).
merci
Area
[] Plutus Foundation Related to the GHC plugin, Haskell-to-Plutus compiler, on-chain code
Summary
Simple equality of a token name does not compile
System info (please complete the following information):