Oracles
如何將參數傳遞給 Chainlink 選擇器?
我有一個帶有整數鍵和結構值的映射。
mapping (int => Client) public customers;
每個客戶都有自己的證明論據,我試圖通過 Chainlink API 呼叫對其進行更新。這是我的結構。
struct Client { int id, bool proof; }
這是我請求 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); }
而這個函式會觸發下面的函式
function fulfill(bytes32 _requestId, bool _isProofCorrect, unit val) public recordChainlinkFulfillment(_requestId){ customers[1].proof = _isProofCorrect; }
如何使用客戶 ID 更新我的 Construct 的證明參數。例如:
customers[<customer_id>].proof = _isProofCorrect;
對於所有Chainlink API 呼叫,該
fulfil
方法只需要 2 個參數。
bytes32 _requestId``requestId
Chainlink API 呼叫的。<type> _data
由_data
Chainlink 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; }