5

为什么Chainlink的喂价PriceFeed返回的价格数据类型是int类型呢?

 3 years ago
source link: https://learnblockchain.cn/question/1979
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
为什么Chainlink的喂价PriceFeed返回的价格数据类型是int类型呢? | 登链社区 | 技术问答

为什么Chainlink的喂价PriceFeed返回的价格数据类型是int类型呢?

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

代码中,price的类型是int类型,为什么用的是包含负数的类型来表示价格数据呢?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK