1

I have a mapping with integer keys and struct values.

mapping (int => Client) public customers;

Each customer has its own proof argument which I am trying to update with a Chainlink API call. Here is my struct.

struct Client {
    int id,
    bool proof;
}

Here is how I request API get call

   function checkProof(string memory JobLocation, bytes32 JOBID) public {

      Chainlink.Request memory req = buildChainlinkRequest(JOBID, address(this), this.fulfill.selector);

      req.add("get",JobLocation);

      req.add("path", "proof");

      sendChainlinkRequestTo(ORACLE_ADDRESS, req, ORACLE_PAYMENT);
}

And this function triggers the following function

     function fulfill(bytes32 _requestId, bool _isProofCorrect, unit val) public recordChainlinkFulfillment(_requestId){
            customers[1].proof = _isProofCorrect;  
}

How can I update the proof argument of my Construct by using customer ID. For example:

customers[<customer_id>].proof = _isProofCorrect;
1

For all Chainlink API calls, the fulfil method only takes 2 arguments.

  • bytes32 _requestId The requestId of the Chainlink API call.
  • <type> _data The _data that is being returned by the Chainlink API call.

This means you can't pass 3 parameters.

What this means, is that you can map your requestId to your value, and it'll look something like this.

mapping (bytes32 => uint) public requestMapping;

function checkProof(string memory JobLocation, bytes32 JOBID) public {

      Chainlink.Request memory req = buildChainlinkRequest(JOBID, address(this), this.fulfill.selector);
      req.add("get", JobLocation);
      req.add("path", "proof");
      bytes32 requestId = sendChainlinkRequestTo(ORACLE_ADDRESS, req, ORACLE_PAYMENT);
      requestMapping[requestId] = customerId;
}

     function fulfill(bytes32 _requestId, bool _isProofCorrect, unit val) public recordChainlinkFulfillment(_requestId){
            uint256 value = requestMapping[_requestId]
            customers[value].proof = _isProofCorrect;  
}
2
  • 1
    Thank you so much! Nov 30 '20 at 16:19
  • Patrick, I asked another question regarding the Chainlink oracles. I would appreciate if you can give it a look if you get a chance. Dec 3 '20 at 15:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.