Having trouble with the submitOracleResponse inside the callback below:

    fromBlock: 0
  }, function (error, event) {
    if (error) console.log(error);
    let returnValues = event.returnValues;
    let index  = returnValues.index;
    let airline = returnValues.airline;
    let flightNum = returnValues.flight;
    let flightTime = returnValues.timestamp;
    let eventType = event.event;
    console.log(typeof flightTime);
    console.log(typeof airline);
    for (var i = 0; i < NUM_ORACLES; i++) {
      // Randomize status code
      let randomStatusCode = flightSuretyApp.methods.getRandomStatusCode(oracles[i]);
      randomStatusCode.call( (error, result) => {
         // console.log(error, result);
         flightSuretyApp.methods.submitOracleResponse(index, airline, flightTime, flightNum, result)
         .send({from: oracles[i]},
           ((error, result) => {
            console.log(error, result);
      } );

The error stack with some helpful console.log statements:


    throw error;
    at Object.callback (C:\Users\Raghav\Desktop\udacity-blockchain\FlightSurety\prod\server\server.js:1:437393)
    at sendTxCallback (C:\Users\Raghav\Desktop\udacity-blockchain\FlightSurety\node_modules\web3-core-method\src\index.js:484:29)
    at Object.<anonymous> (C:\Users\Raghav\Desktop\udacity-blockchain\FlightSurety\node_modules\web3-core-requestmanager\src\index.js:147:9)
    at C:\Users\Raghav\Desktop\udacity-blockchain\FlightSurety\node_modules\web3-providers-ws\src\index.js:121:44
    at Array.forEach (<anonymous>)
    at W3CWebSocket.WebsocketProvider.connection.onmessage (C:\Users\Raghav\Desktop\udacity-blockchain\FlightSurety\node_modules\web3-providers-ws\src\index.js:98:36)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\Raghav\Desktop\udacity-blockchain\FlightSurety\node_modules\yaeti\lib\EventTarget.js:107:17)
    at W3CWebSocket.onMessage (C:\Users\Raghav\Desktop\udacity-blockchain\FlightSurety\node_modules\web3-providers-ws\node_modules\websocket\lib\W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (C:\Users\Raghav\Desktop\udacity-blockchain\FlightSurety\node_modules\web3-providers-ws\node_modules\websocket\lib\W3CWebSocket.js:

For reference, here is the function definition for submitOracleRequest. I am posting this for clarity, but please do not read too much into it. I do not think it is the problem:

// Called by oracle when a response is available to an outstanding request.
    // For the response to be accepted, there must be a pending request that is open
    // and matches one of the three Indexes randomly assigned to the oracle at the
    // time of registration (i.e. uninvited oracles are not welcome)
    function submitOracleResponse
                            uint8 index,
                            address airline,
                            uint flightNum,
                            uint flightTime,
                            uint8 statusCode
        require((oracles[msg.sender].indexes[0] == index) || (oracles[msg.sender].indexes[1] == index) || (oracles[msg.sender].indexes[2] == index), "Index does not match oracle request");
        bytes32 key = keccak256(abi.encodePacked(index, airline, flightNum, flightTime));
        require(oracleResponses[key].isOpen, "Flight or timestamp do not match oracle request");
        // Information isn't considered verified until at least MIN_RESPONSES
        // oracles respond with the *** same *** information
        emit OracleReport(airline, flightNum, flightTime, statusCode);
        if (oracleResponses[key].responses[statusCode].length >= MIN_RESPONSES) {
            emit FlightStatusInfo(airline, flightNum, flightTime, statusCode);
            // Handle flight status as appropriate
            processFlightStatus(airline, flightNum, flightTime, statusCode);

I get a similar bug with the address. I have tried putting a zero address/zero timestamp and God knows how many combinations, but it doesn't seem to be working. Any help will be greatly appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.