IntersectMBO / plutus-apps

The Plutus application platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

invoking endpoint leads to HTTP 400 error on `cardano-wallet` transaction-balance endpoint

extramileit opened this issue · comments

Summary

I'm trying to run the guessing game with lock and guess endpoints- IOHK plutus-starter repo against testnet backed. When I try to call the lock endpoint with JSON request body, the response from PAB gives an error having to do with bad request

Steps to reproduce

Steps to reproduce the behavior:

  1. Sync cardano-node to testnet
  2. index with plutus-chain-index
  3. run cardano-wallet server and sync
  4. run game contract bundled with PAB and sync
  5. Set up 2 wallets-- one with funds for calling lock endpoint and one without funds for calling guess endpoint
  6. Activate each of the wallets successfully
  7. Set up a JSON request: {"amount":{"getValue":[[{"unCurrencySymbol":""},[[{"unTokenName":""},90]]]]},"secretWord":"eagle"}
  8. POST to lock endpoint with JSON body
  9. Error received as follows.
[pab:Info:662] [2021-11-29 20:53:23.69 UTC] c3f3f116-3133-452c-b796-5cf6c4179076: "Pay Value (Map [(,Map [(\"\",90)])]) to the script"
[pab:Warning:662] [2021-11-29 20:53:23.70 UTC] WalletClientError "FailureResponse (Request {requestPath = (BaseUrl {baseUrlScheme = Http, baseUrlHost = \"localhost\", baseUrlPort = 8090, baseUrlPath = \"\"},\"/v2/wallets/9e076253925172656de562da94bb79f303492299/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, 29 Nov 2021 20:53:23 GMT\"),(\"Server\",\"Warp/3.3.17\"),(\"Content-Type\",\"application/json;charset=utf-8\")], responseHttpVersion = HTTP/1.1, responseBody = \"{\\\"code\\\":\\\"bad_request\\\",\\\"message\\\":\\\"Error in $.transaction: parsing HashMap ~Text failed, expected Object, but encountered String\\\"}\"})"

Code

lock :: Promise () GameSchema GameError ()
lock = endpoint @"lock" @LockParams $ \(LockParams secret amt) -> do
    logInfo @Haskell.String $ "Pay " <> Haskell.show amt <> " to the script"
    let tx         = Constraints.mustPayToTheScript (hashString secret) amt
    void (submitTxConstraints gameInstance tx)

Expected behavior

A clear and concise description of what you expected to happen.

System info (please complete the following information):

  • OS: [e.g. Ubuntu]
  • Version [e.g. 20.04]
  • Plutus version or commit hash

Screenshots and attachments

  • If applicable, add screenshots, config files and/or logs to help explain the problem.
  • If the issue is related to the Plutus Playground, please include a link to a gist that reproduces the issue

Additional context

Add any other context about the problem here.

Thanks for the issue!

Could you please share what commit are you using?

Hi there.

This is not an issue related to the JSON you used, which looks fine, but an issue between PAB and Wallet. It seems at first glance that the proxy wallet used by PAB is not aligned with the version of cardano-wallet you are running.

Hope this could help.

Hello,
I'm running the same cardano-wallet as used in the tag v2021-11-05 and tag v2021-11-22.

location: https://github.com/j-mueller/cardano-wallet
tag: 6be73ab852c0592713dfe78218856d4a8a0ee69e

Can you tell me more specifically how to fix the alignment issue of proxy-wallet to cardano-wallet? Does this mean I need to change the version of cardano-wallet or something else?

Here is my project, which is based on v2021-11-05 tag of plutus-apps. PAB-setup-guide. I will cut it over to your new tag v2021-11-22 as I just noticed it. But, I bet I run into the same issue.

Thank you

I also updated to v2021-11-22 plutus-apps tag and rebuilt my bundled game contract with the PAB services. I got the same error of HTTP 400/Bad Request as before. I verified I'm using the j-mueller cardano-wallet. It definitely appears the wallet and PAB code are not aligned, but not sure how to fix.

Try to align them through cabal file, I think that is what I have done on our pab project

Thanks for the suggestion.
Might you be able to share the appropriate tags to use for the plutus-apps and cardano-wallet source-repository packages? I'm currently using the same tags as those found in v2021-11-22 tag of `plutus-apps'. As I recall, even the integration test example in the plutus-apps project gives the same error.

Here is my cabal.project file: https://github.com/woofpool/PAB-starter-app-setup/blob/master/cabal.project
Thanks

I change a lot of thing in the cabal projet to align to plutus-apps as starter is/was not linked at all to pab beta.

I'll have a look at it tomorrow morning.

I appreciate your help. These kinds of things are highly frustrating, especially for somebody new to Haskell. I'm assuming it's something wrong I'm doing.

I saw you did not use Nix, please take time to learn and use it as it is really bringing a lot of benefits.

Still by using Nix you will have to edit manually the haskell.nix to point to the right sha1 + nix custom checksum for each/every cabal dependency (which is overwhelming for new people, even me sometimes, I could agree on).

Anyway this might not be your issue and your cabal seems okay even if we stayed on v2021-11-05 in our project.

Question are you running the input-output-hk or j-mueller project? I used the input-output-hk one (difference has been tracked and should be fixed) which could be related to our differences (even if j-muller is referenced in cabal files it should work)

It would be interesting to known if you have the "right endpoints version in your wallet server". Everything should be something like /v2/... https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/balanceTransaction

curl --location --request GET 'http://localhost:8090/v2/network/information

Thanks Benjamin,
I'm now running the cardano-wallet server using the latest release tag from the IOHK repo instead of using the J-Mueller one. This wallet server allows me to post to the contract endpoints.

However, one thing I notice is that in order to build my project, I still need the J-Mueller cardano-wallet dependency. I tried to put in the source-package-repo for IOHK cardano-wallet, but couldn't figure out how to compile things. I think there may still be some transitive dependency of J-Mueller cardano-wallet, even though running that wallet server won't work. That is not very ideal imo.

Now, I'm facing new issue where the guess endpoint fails to validate successfully for a matching secret word. I can run the repl and verify the goodGuess function is working, so I'm thinking the PAB is not finding the hashed guess word among the UTXOs at the script address. I'll keep trying to debug.

@woofpool great, and yes you steel need jmueller at least for now, not very clean but working.

And yes, guess does not work ... you get hash instead of a datum and you cannot get anything from it. More information here #139.

Seeing as the main issue you are experiencing is resolved I will be closing this issue, glad you could get your wallet issues worked out.

Fortunately the other issue you are experiencing with the Datum should be fixed by this pull request here.