chainlink - 任何人都知道为什么 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;
}
}
请注意,在函数getThePrice
、行int price
中,为什么 Chainlinkint
在价格上使用类型?为什么不直接uint
打字?是否有可能从 Chainlink PriceFeed 获得负价格?
解决方案
Chainlink 数据馈送使用int
而不是uint
因为某些价格可能是负数,例如当石油期货跌至 0 以下时。
推荐阅读
- bash - BASH 中的单元测试(检查脚本输出)
- javascript - 无法在 Autodesk Forge 中获取 AEC 模型数据
- reactjs - 如何通过按下 echarts 中的图例选项来放大系列组
- python - 在 Plot.ly 条形图上显示徽标
- javascript - 管理状态和使用输入
- awk - awk 从配置文件路径获取 .ini 值
- r - 从 R 中的矩阵计算真/假阳性和真/假阴性值
- python - 在 Sympy 中更改 FormalPowerSeries 的索引符号
- mysql - SQL:如何为主键生成唯一值
- node.js - 在数组映射期间将剩余的数组对象从一个组件转移到另一个组件