@filip @dan-i I am having issues using provable_newRandomDSQuery function, as you can see in my code below I am trying to save the query_id in a mapping mapping(address => bytes32) userQuery;
and trying to compare it in _callback function to match with current user to get the random number.
But the quryId received in _callback is not matching to one that is stored when provable_newRandomDSQuery function called if(userQuery[msg.sender] == _queryId). I couldn’t find what is wrong here can you please help?
Thanks
bytes32 calledQueryId;
event LogNewProvableQuery(string description);
event generatedRandomNumber(uint256 randomNumber);
event coinFlipped(uint _coinState);
mapping(address => bytes32) userQuery;
function __callback(bytes32 _queryId, string memory _result, bytes memory _proof) public {
require(msg.sender == provable_cbAddress());
proof = _proof;
if(userQuery[msg.sender] == _queryId) {
uint256 randomNumber = uint256(keccak256(abi.encodePacked(_result))) % 2;
latestNumber = randomNumber;
emit generatedRandomNumber(randomNumber);
} else {
//in case it doesn't match set latestNumber to 0 to make it work remove it after testing.
latestNumber = 0;
}
}
function update() payable public {
uint256 QUERY_EXECUTION_DELAY = 0;
uint256 GAS_FOR_CALLBACK = 200000;
address user = msg.sender;
calledQueryId = provable_newRandomDSQuery(QUERY_EXECUTION_DELAY, NUM_RANDOM_BYTES_REQUESTED, GAS_FOR_CALLBACK);
userQuery[user] = calledQueryId;
emit LogNewProvableQuery("Provable query was sent, standing by for the answer");
}