I have the following Oraclize query which works (generates a random number between 1 and 5, with the API key encrypted):
oraclize_query(1, "nested", "[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random.data.0', '\\n{\"jsonrpc\":\"2.0\",\"method\":\"generateIntegers\",\"params\":{\"apiKey\":\"${[decrypt] BA3g1TNRkJ0lqv18s+v3chf2FoZEzUXuyhOUWCcoBDKrmv51clDqUvw36lLEDJizgDrCyX7GREX7YVOfctHAT/lhLiTZNQFNjw11mq/y9mJ2gXKWw+EP/13AUnvvtDcjLek7KaBsYxk2qYuKn78Nt+EAasij}\",\"n\":1,\"min\":1,\"max\":5,\"replacement\":true${[identity] \"}\"},\"id\":1${[identity] \"}\"}']");
If I have a uint number
variable, I want to be able to use this in the above query (as the 'max' value). Per Simplest way to use a variable in an Oraclize query? this is done with the strConcat
and uint2str
functions in the Oraclize contract. I got this working when the oraclize_query
isn't nested and the API key isn't encrypted, but can't seem to get it working with the above nested query with the API key encrypted.
This is what I've tried:
string string1 = '\\n{\"jsonrpc\":\"2.0\",\"method\":\"generateIntegers\",\"params\":{\"apiKey\":\"${[decrypt] BA3g1TNRkJ0lqv18s+v3chf2FoZEzUXuyhOUWCcoBDKrmv51clDqUvw36lLEDJizgDrCyX7GREX7YVOfctHAT/lhLiTZNQFNjw11mq/y9mJ2gXKWw+EP/13AUnvvtDcjLek7KaBsYxk2qYuKn78Nt+EAasij}\",\"n\":1,\"min\":1,\"max\":';
uint number = 5;
string string3 = ',\"replacement\":true${[identity] \"}\"},\"id\":1${[identity] \"}\"}';
oraclize_query(1, "nested", "[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random.data.0', strConcat(string1, uint2str(number), string3)]");
When testing this I'm using a new encrypted API key each time.