小编Cry*_*o D的帖子

有人知道为什么 Chainlink 的 PriceFeed 返回“int”类型的价格值,而价格应该始终 >= 0?

PriceFeed中获取最新价格的代码是:


pragma solidity ^0.6.7;

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

contract PriceConsumerV3 {

    AggregatorV3Interface internal priceFeed;

    /**
     * Network: Kovan
     * Aggregator: ETH/USD
     * Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
     */
    constructor() public {
        priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
    }

    /**
     * Returns the latest price
     */
    function getThePrice() public view returns (int) {
        (
            uint80 roundID, 
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();
        return price;
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,在 function 中getThePrice,为什么 Chainlink在价格上int price使用类型?int为什么不直接uint打字呢?Chainlink PriceFeed 是否有可能获得负价格?

chainlink

7
推荐指数
1
解决办法
1002
查看次数

标签 统计

chainlink ×1