Comment passer l'argument au sélecteur Chainlink?

Nov 30 2020

J'ai un mappage avec des clés entières et des valeurs de struct.

mapping (int => Client) public customers;

Chaque client a son propre argument de preuve que j'essaie de mettre à jour avec un appel d'API Chainlink. Voici ma structure.

struct Client {
    int id,
    bool proof;
}

Voici comment je demande un appel à l'API

   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);
}

Et cette fonction déclenche la fonction suivante

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

Comment puis-je mettre à jour l'argument de preuve de ma construction à l'aide de l'ID client. Par exemple:

customers[<customer_id>].proof = _isProofCorrect;

Réponses

1 PatrickCollins Nov 30 2020 at 22:17

Pour tous les appels d'API Chainlink , la fulfilméthode ne prend que 2 arguments.

  • bytes32 _requestIdL' requestIdappel de l'API Chainlink.
  • <type> _dataLe _dataqui est renvoyé par l'appel d'API Chainlink.

Cela signifie que vous ne pouvez pas passer 3 paramètres.

Ce que cela signifie, c'est que vous pouvez mapper votre requestIdà votre valeur , et cela ressemblera à quelque chose comme ça.

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;  
}