Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: missing basic validation in route params #213

Merged
merged 6 commits into from
Aug 29, 2024

Conversation

ShookLyngs
Copy link
Collaborator

Changes

  • Add basic validation to route params (e.g. txid, hash should be 64-character hex string)
  • Write a custom validatorCompiler to promp only the first error if error instanceof ZodError

Related issues

Examples

Route: /rgbpp/v1/assets//

{
  "message": "Invalid btc_txid: should be a 64-character hex string"
}

Route /rgbpp/v1/assets/63e7de3c59b7f28cfc1eb840c8d617b2f557770d2576355cfc0263e1925ac116/

{
  "message": "Invalid vout: cannot be empty"
}

Route: /rgbpp/v1/assets/63e7de3c59b7f28cfc1eb840c8d617b2f557770d2576355cfc0263e1925ac116/-1

{
  "message": "Invalid vout: cannot be negative"
}

Copy link

vercel bot commented Aug 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
btc-assets-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 27, 2024 10:58am

src/app.ts Outdated Show resolved Hide resolved
src/app.ts Outdated Show resolved Hide resolved
@Flouse
Copy link
Contributor

Flouse commented Aug 27, 2024

Test Files 4 failed | 17 passed (21)
Tests 6 failed | 84 passed (90)

https://github.com/ckb-cell/btc-assets-api/actions/runs/10525967538/job/29165809518#step:7:805

@ShookLyngs
Copy link
Collaborator Author

ShookLyngs commented Aug 27, 2024

@Flouse @Dawn-githup Fixed PR-related issues today:

  • Should return { value: result.data } instead of result.data in the validatorCompiler() method
  • Should throw HttpErrors.badRequest() when the post rgbpp tx API params is invalid
  • Should update test snapshots

@Dawn-githup
Copy link
Collaborator

@Flouse @Dawn-githup Fixed PR-related issues today:

  • Should return { value: result.data } instead of result.data in the validatorCompiler() method
  • Should throw HttpErrors.badRequest() when the post rgbpp tx API params is invalid
  • Should update test snapshots

fixed:
#215

@Dawn-githup
Copy link
Collaborator

Dawn-githup commented Aug 27, 2024

get balance

curl --location --request GET 'https://213.assets-api-342ddd42.nip.io/rgbpp/v1/address/tb1qwzawvkyywkfcvtz9wu8ly9yfs06vn00j5x44su/balance?type_script=%7B%20%20%22codeHash%22:%20%220x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb%22,%20%20%22hashType%22:%20%22type%22,%20%20%22args%22:%20%22%22%7D&no_cache=false' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJteS1hcHAiLCJhdWQiOiJhcGkudGVzdG5ldC5yZ2JwcC5pbyIsImp0aSI6IjBiOTE5NGJhLTE4NzItNGMyZS1iMzgwLTBjNDBkNzA2ZjNiZSIsImlhdCI6MTcyNDc1ODAxNX0.nhuE7hVQbVVcwQQ2naqQ5LEpESM9pdIlyQkwlkLJKEo' \
--header 'origin: https://api.testnet.rgbpp.io' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: 213.assets-api-342ddd42.nip.io' \
--header 'Connection: keep-alive'

error message:

{
    "message": "socket hang up"
}

Description:

When attempting to call the get balance API, a socket hang up error occurred.

  • Deployment Issue: This error did not occur in previous tests, suggesting that the deployment might have used a different RPC address, or there may have been changes to the RPC service configuration.

Please help to check.

cc @Flouse @ShookLyngs

@Flouse
Copy link
Contributor

Flouse commented Aug 27, 2024

error message:

{
    "message": "socket hang up"
}

https://213.assets-api-342ddd42.nip.io/healthcheck

{
  "healthChecks": {
    "electrs": {
      "status": "FAIL",
      "reason": "Error: socket hang up"
    }
  },...
}

@mfuuzy is maintaining the BTC testnet bitcoind and electrs services on that server.

@Flouse
Copy link
Contributor

Flouse commented Aug 28, 2024

@Dawn-githup
Copy link
Collaborator

@utxostack utxostack deleted a comment from self-host-2024 bot Aug 28, 2024
@Flouse Flouse merged commit 38224cc into develop Aug 29, 2024
2 of 4 checks passed
@Flouse Flouse deleted the fix/210-empty-param-validation branch August 29, 2024 02:39
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error getting RGB++ assets through assets api
4 participants