Skip to content
This repository has been archived by the owner on Oct 24, 2020. It is now read-only.

Faucet needs to validate amount as int #29

Open
danaki opened this issue Apr 27, 2017 · 2 comments
Open

Faucet needs to validate amount as int #29

danaki opened this issue Apr 27, 2017 · 2 comments

Comments

@danaki
Copy link

danaki commented Apr 27, 2017

POST https://api.blockcypher.com/v1/bcy/test/faucet?token=MY_TOKEN

Request: string(62) "{"address":"BvngfRB42j2125T6U84hAWUphYDjJg4zpp","amount":"10"}"

Response:
string(453) "HTTP/1.1 400 Bad Request
Server: nginx/1.11.10
Date: Tue, 25 Apr 2017 13:18:49 GMT
Content-Type: application/json
Content-Length: 97
Connection: keep-alive
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Origin: *
X-Ratelimit-Remaining: 192

{"error": "Error decoding faucet info, json: cannot unmarshal string into Go value of type int."}"

Thank you.

P.S. I'm using official php client, that validates address and amount before issue the request. So it might be client validation bug (must also check for correct type) or backend's bug because it seems nothing special to convert "10" to 10 even in Go.

@josecelano
Copy link
Contributor

Hi @danaki Sorry for the delay I've been very busy. Did you see this sample?:

https://github.com/blockcypher/php-client/blob/master/sample/introduction/FundAddressWithFaucetEndpoint.php#L19

I have not tried to reproduce it yet but it could be becuase you are using an string for the amount instead of an integer. Could you tried casting to integer if that is the case?

I think the problem must be in the client. The request body should be:

{
  "address":"BvngfRB42j2125T6U84hAWUphYDjJg4zpp",
  "amount":10
}

@danaki
Copy link
Author

danaki commented May 8, 2017

Yes, but seems that this

NumericValidator::validate($amount, 'amount');
passes string thru just because http://php.net/manual/en/function.is-numeric.php is_numeric — Finds whether a variable is a number or a numeric string.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants