Chainlink 선택기에 인수를 전달하는 방법은 무엇입니까?

Nov 30 2020

정수 키와 구조체 값이있는 매핑이 있습니다.

mapping (int => Client) public customers;

각 고객에게는 Chainlink API 호출로 업데이트하려는 자체 증명 인수가 있습니다. 여기 내 구조체가 있습니다.

struct Client {
    int id,
    bool proof;
}

API get 호출을 요청하는 방법은 다음과 같습니다.

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

이 기능은 다음 기능을 트리거합니다.

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

고객 ID를 사용하여 내 Construct의 증명 인수를 업데이트하려면 어떻게해야합니까? 예를 들면 :

customers[<customer_id>].proof = _isProofCorrect;

답변

1 PatrickCollins Nov 30 2020 at 22:17

모든 Chainlink API 호출 에 대해 fulfil메서드는 2 개의 인수 만 사용합니다.

  • bytes32 _requestIdrequestId체인 링크의 API 호출.
  • <type> _data_data체인 링크의 API 호출에 의해 반환된다.

이는 3 개의 매개 변수를 전달할 수 없음을 의미합니다.

이것이 의미하는 바는 귀하의 가치에 매핑requestId 할 수 있다는 것입니다. 그러면 다음과 같이 보일 것입니다.

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