Solidity

從未呼叫過Chainlink鬧鐘的填充方法?

  • April 1, 2021

使用Chainlink 鬧鐘,我的fulfill()方法似乎永遠不會被呼叫。因此,對於文件範例(如下),votingLive時間結束後永遠不會設置回 false。其他一切都有效,我已經使用rinkeby 和 kovan oracles在 remix 和本地都遇到了同樣的問題。

問題…

沒有添加時間延遲,並且沒有執行功能。

程式碼…

pragma solidity ^0.6.0;

import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";


contract ChainlinkTimedVote is ChainlinkClient
{
 uint private oraclePayment;
 address private oracle;
 bytes32 private jobId;
 uint private yesCount;
 uint private noCount;
 bool private votingLive;
 mapping(address => bool) public voters;

 //only the contract owner should be able to start voting
 address payable owner;
 modifier onlyOwner {
 require(msg.sender == owner);
 _;
 }

 constructor() public {
     setPublicChainlinkToken();
     owner = msg.sender;
     oraclePayment = 0.1 * 10 ** 18; // 0.1 LINK
     //Rinkeby alarm oracle
     oracle = 0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e; 
     jobId = "4fff47c3982b4babba6a7dd694c9b204";
     //initialize votes
     yesCount = 0;
     noCount = 0;
     votingLive = false;
 }

 function startVote(uint voteMinutes) public onlyOwner {
     Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
     req.addUint("until", now + voteMinutes * 1 minutes);
     //Start voting window then submit request to sleep for $voteMinutes
     votingLive = true;
     sendChainlinkRequestTo(oracle, req, oraclePayment);
 }

 //Callback for startVote request
 function fulfill(bytes32 _requestId) public recordChainlinkFulfillment(_requestId) {
     //$voteMinutes minutes have elapsed, stop voting
     votingLive = false;
 }

 //Increments appropriate vote counter if voting is live
 function vote(bool voteCast) public {
   require(!voters[msg.sender], "already Voted!");
   //if voting is live and address hasn't voted yet, count vote  
     if(voteCast) {yesCount++;}
     if(!voteCast) {noCount++;}
     //address has voted, mark them as such
     voters[msg.sender] = true;
  }
  
  //Outputs current vote counts
 function getVotes() public view returns (uint yesVotes, uint noVotes) {
     return(yesCount, noCount);
 }
 
 function isVotingLive() public view returns (bool) {
     return votingLive;
 }

 //Lets user know if their vote has been counted
 function haveYouVoted() public view returns (bool) {
     return voters[msg.sender];
 }
}

想法…

也許我正在建構錯誤的請求?

     Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
     req.addUint("until", now + voteMinutes * 1 minutes);

翻轉

     votingLive = true;
     sendChainlinkRequestTo(oracle, req, oraclePayment);

     sendChainlinkRequestTo(oracle, req, oraclePayment);
     votingLive = true;

我還注意到沒有添加時間延遲。

目前 Chainlink 文件中的節點似乎存在問題。試試這個節點(在 Kovan 上)和工作:

Oracle地址 = 0xAA1DC356dc4B18f30C347798FD5379F3D77ABC5b

工作 ID = 982105d690504c5d9ce374d040c08654

為了將來參考,我在 market.link 上搜尋了類似的工作: https ://market.link/search/all?network=42&search=Alarm%20Clock

文件將被更新。

引用自:https://ethereum.stackexchange.com/questions/96531