Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTextDecodingError = 'TokenName is not hex-encoded: base16 #4236

Closed
volodyad opened this issue Nov 22, 2021 · 7 comments
Closed

getTextDecodingError = 'TokenName is not hex-encoded: base16 #4236

volodyad opened this issue Nov 22, 2021 · 7 comments
Assignees

Comments

@volodyad
Copy link

Got error on token minting and sending to own wallet

 let tokenName = fromString stringTokenName

<> Constraints.mustPayToPubKey ownPK forgedValue
<> Constraints.mustMintValue forgedValue

[pab:Warning:15473] [2021-11-22 22:09:08.04 UTC] WalletClientError "FailureResponse (Request {requestPath = (BaseUrl {baseUrlScheme = Http, baseUrlHost = \"localhost\", baseUrlPort = 8090, baseUrlPath = \"\"},\"/v2/wallets/b530fd5bb69e88f92e066ba40b4fae5b843dc7cb/transactions-balance\"), requestQueryString = fromList [], requestBody = Just ((),application/json;charset=utf-8), requestAccept = fromList [application/json;charset=utf-8,application/json], requestHeaders = fromList []), requestHttpVersion = HTTP/1.1, requestMethod = \"POST\"} (Response {responseStatusCode = Status {statusCode = 400, statusMessage = \"Bad Request\"}, responseHeaders = fromList [(\"Transfer-Encoding\",\"chunked\"),(\"Date\",\"Mon, 22 Nov 2021 22:09:07 GMT\"),(\"Server\",\"Warp/3.3.17\"),(\"Content-Type\",\"application/json;charset=utf-8\")], responseHttpVersion = HTTP/1.1, responseBody = \"{\\\"message\\\":\\\"Error in $.inputs[0].assets[0]['asset_name']: TextDecodingError {getTextDecodingError = 'TokenName is not hex-encoded: base16: input: invalid encoding at offset: 0'}\\\",\\\"code\\\":\\\"bad_request\\\"}\"})"

@ak3n
Copy link
Contributor

ak3n commented Nov 24, 2021

Could you please show more code? What is stringTokenName? forgedValue?

@volodyad
Copy link
Author

let stringTokenName :: String = "metadata"

I have managed to convert to Cardano wallet token name via

import qualified Cardano.Wallet.Primitive.Types.TokenPolicy as TK
import qualified Data.ByteString.Char8            as B
import qualified Data.ByteString.Base16         as B16
import qualified Data.Text                      as T
import qualified Data.Text.Encoding             as T

    let cpTokenName :: String = "metadata"
    let tokenNameE :: Either TextDecodingError TK.TokenName = fromText . T.decodeUtf8 . B16.encode . B.pack $  cpTokenName
    case tokenNameE of
      Right t -> do
        putStrLn $ "Token name: " ++ show t
      Left e -> do
        putStrLn $ "No Token name: " ++ show e

Ideally would be good if Plutus.V1.Ledger.Value fromString will handle this

instance IsString TokenName where
    fromString = fromText . Text.pack

@ak3n ak3n transferred this issue from IntersectMBO/plutus-apps Nov 24, 2021
@ak3n ak3n self-assigned this Nov 25, 2021
@volodyad
Copy link
Author

volodyad commented Nov 26, 2021

Now I am encode token, but for some reason on balancing it encrypts it once more

I have create unique market on start and eccode to base16
"marketVal: Value (Map [(b45e5c5e6f791fa8afbaa7a5352dac88d0760173a26fda416f077928,Map [(\"4e46544d61726b6574706c616365\",1)])])"
4e46544d61726b6574706c616365 = NFTMarketplace in base16

Now on token create method I find this utxo consume it and sand back,

create market CreateParams{..} = do
...
let marketInst = marketInstance market
     mrScript = marketScript market
     marketFactoryData   = Factory $ nftMetadata : nftMetas
     nftMetadataData   = NFTMeta nftMetadata
     marketVal    = assetClassValue (marketId market) 1

     lookups  = Constraints.typedValidatorLookups marketInst 
                <> Constraints.otherScript mrScript
                <> Constraints.unspentOutputs (Map.singleton oref o)
                <> Constraints.mintingPolicy nftTokenPolicy
                <> Constraints.mintingPolicy nftTokenMetaPolicy

     tx       = Constraints.mustPayToTheScript marketFactoryData marketVal
                <> Constraints.mustPayToTheScript nftMetadataData nftTokenMetaForgedValue
                <> Constraints.mustSpendScriptOutput oref (Redeemer $ PlutusTx.toBuiltinData $ Create nftMetadata)
                <> Constraints.mustPayToPubKey ownPK nftTokenForgedValue
                <> Constraints.mustMintValue nftTokenForgedValue
                <> Constraints.mustMintValue nftTokenMetaForgedValue
 logInfo @String $ "marketVal-current : " ++ show marketVal  

seems it encode token name once more
token: 34653436353434643631373236623635373437303663363136333635

although in marketVal-current log - 4e46544d61726b6574706c616365

[pab:Info:51875] [2021-11-26 20:34:06.76 UTC] 8d9940d4-2857-4d6d-b8fe-efa2248f64ac: "marketVal-current: Value (Map [(b45e5c5e6f791fa8afbaa7a5352dac88d0760173a26fda416f077928,Map [(\"4e46544d61726b6574706c616365\",1)])])"

[pab:Warning:51875] [2021-11-26 20:34:06.81 UTC] WalletClientError "FailureResponse (Request {requestPath = (BaseUrl {baseUrlScheme = Http, baseUrlHost = \"localhost\", baseUrlPort = 8090, baseUrlPath = \"\"},\"/v2/wallets/88cc0e42b4a4f29d192c8b05967c386cb4c2aeaa/transactions-balance\"), requestQueryString = fromList [], requestBody = Just ((),application/json;charset=utf-8),
 requestAccept = fromList [application/json;charset=utf-8,application/json], requestHeaders = fromList []), requestHttpVersion = HTTP/1.1, requestMethod = \"POST\"} 
(Response {responseStatusCode = Status {statusCode = 403, statusMessage = \"Forbidden\"}, 
responseHeaders = fromList [(\"Transfer-Encoding\",\"chunked\"),(\"Date\",\"Fri, 26 Nov 2021 20:34:06 GMT\"),(\"Server\",\"Warp/3.3.17\"),(\"Content-Type\",\"application/json;charset=utf-8\")], 
responseHttpVersion = HTTP/1.1, 
responseBody = \"{\\\"message\\\":\\\"I can't process this payment as there are not enough funds available in the wallet. I am missing: coin: 0.000000 tokens:   - policy: b45e5c5e6f791fa8afbaa7a5352dac88d0760173a26fda416f077928     token: 34653436353434643631373236623635373437303663363136333635     quantity: 1 \\\",\\\"code\\\":\\\"not_enough_money\\\"}\"})"

you could check sources: on
https://github.com/input-output-hk/plutus-use-cases/blob/eleks/dev/eleks/nft/src/Contracts/NFT/OffChain.hs

@ak3n
Copy link
Contributor

ak3n commented Nov 29, 2021

Yep, that's correct. Plutus's TokenName is encoded automatically.

It's unclear how TokenName is not hex-encoded error was raised. The encoding should be done automatically, at least by Plutus.Contract.Wallet.extract.

@volodyad
Copy link
Author

volodyad commented Dec 4, 2021

Might be that I was running Cardano node from master (1.31.0), plutus apps points to 1.30 (b6ca519f97a0e795611a63174687e6bb70c9f752)

on master cardano-node --mint="1 $POLICY_ID.TOKEN_NAME" requires TOKEN_NAME to be base16, on 1.30 it can be string

@volodyad
Copy link
Author

volodyad commented Dec 6, 2021

No, same issue on 1.30 , on another contract
[pab:Warning:503] [2021-12-06 12:38:54.83 UTC] WalletClientError "FailureResponse (Request {requestPath = (BaseUrl {baseUrlScheme = Http, baseUrlHost = "localhost", baseUrlPort = 46493, baseUrlPath = ""},"/v2/wallets/2d4cc31a4b3116ab86bfe529d30d9c362acd0b44/transactions-balance"), requestQueryString = fromList [], requestBody = Just ((),application/json;charset=utf-8), requestAccept = fromList [application/json;charset=utf-8,application/json], requestHeaders = fromList []), requestHttpVersion = HTTP/1.1, requestMethod = "POST"} (Response {responseStatusCode = Status {statusCode = 400, statusMessage = "Bad Request"}, responseHeaders = fromList [("Transfer-Encoding","chunked"),("Date","Mon, 06 Dec 2021 12:38:54 GMT"),("Server","Warp/3.3.17"),("Content-Type","application/json;charset=utf-8")], responseHttpVersion = HTTP/1.1, responseBody = "{\"message\":\"Error in $.inputs[0].assets[0]['asset_name']: TextDecodingError {getTextDecodingError = 'TokenName is not hex-encoded: base16: input: invalid encoding at offset: 0'}\",\"code\":\"bad_request\"}"})"

@ak3n
Copy link
Contributor

ak3n commented Dec 15, 2021

Closing this because of IntersectMBO/plutus-apps#192 and turned out the problem is on plutus-apps side.

@ak3n ak3n closed this as completed Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants