如何解决我的Chainlink作业没有被调用我可能做错了什么?
我在Kovan测试网上有一个Chainlink节点。我正在按照https://docs.chain.link/docs/fulfilling-requests页上的说明进行操作,并尝试通过Kovan上的Testnet Consumer测试我的工作。
Oracle合同部署成功。 Testnet消费者合同部署成功。 requestEthereumPrice调用成功。
但是currentPrice显示为0。
这是我的代码。
pragma solidity 0.4.24;
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.4/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.4/vendor/Ownable.sol";
contract ATestnetConsumer is ChainlinkClient,Ownable {
uint256 constant private ORACLE_PAYMENT = 1 * LINK;
uint256 public currentPrice;
int256 public changeDay;
bytes32 public lastMarket;
event RequestEthereumPriceFulfilled(
bytes32 indexed requestId,uint256 indexed price
);
event RequestEthereumChangeFulfilled(
bytes32 indexed requestId,int256 indexed change
);
event RequestEthereumLastMarket(
bytes32 indexed requestId,bytes32 indexed market
);
constructor() public Ownable() {
setPublicChainlinkToken();
}
function requestEthereumPrice(address _oracle,string _jobId)
public
onlyOwner
{
Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId),this,this.fulfillEthereumPrice.selector);
req.add("get","https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD");
req.add("path","USD");
req.addInt("times",100);
sendChainlinkRequestTo(_oracle,req,ORACLE_PAYMENT);
}
function requestEthereumChange(address _oracle,this.fulfillEthereumChange.selector);
req.add("get","https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
req.add("path","RAW.ETH.USD.CHANGEPCTDAY");
req.addInt("times",1000000000);
sendChainlinkRequestTo(_oracle,ORACLE_PAYMENT);
}
function requestEthereumLastMarket(address _oracle,this.fulfillEthereumLastMarket.selector);
req.add("get","https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
string[] memory path = new string[](4);
path[0] = "RAW";
path[1] = "ETH";
path[2] = "USD";
path[3] = "LASTMARKET";
req.addStringArray("path",path);
sendChainlinkRequestTo(_oracle,ORACLE_PAYMENT);
}
function fulfillEthereumPrice(bytes32 _requestId,uint256 _price)
public
recordChainlinkFulfillment(_requestId)
{
emit RequestEthereumPriceFulfilled(_requestId,_price);
currentPrice = _price;
}
function fulfillEthereumChange(bytes32 _requestId,int256 _change)
public
recordChainlinkFulfillment(_requestId)
{
emit RequestEthereumChangeFulfilled(_requestId,_change);
changeDay = _change;
}
function fulfillEthereumLastMarket(bytes32 _requestId,bytes32 _market)
public
recordChainlinkFulfillment(_requestId)
{
emit RequestEthereumLastMarket(_requestId,_market);
lastMarket = _market;
}
function getChainlinkToken() public view returns (address) {
return chainlinkTokenAddress();
}
function withdrawLink() public onlyOwner {
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
require(link.transfer(msg.sender,link.balanceOf(address(this))),"Unable to transfer");
}
function cancelRequest(
bytes32 _requestId,uint256 _payment,bytes4 _callbackFunctionId,uint256 _expiration
)
public
onlyOwner
{
cancelChainlinkRequest(_requestId,_payment,_callbackFunctionId,_expiration);
}
function stringToBytes32(string memory source) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}
assembly { // solhint-disable-line no-inline-assembly
result := mload(add(source,32))
}
}
}
我们将非常感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。