浏览代码

Use latestPriceInfoPublishTime when possible (#377)

Ali Behjati 3 年之前
父节点
当前提交
8db2af6ee5
共有 2 个文件被更改,包括 8 次插入5 次删除
  1. 4 5
      ethereum/contracts/pyth/Pyth.sol
  2. 4 0
      ethereum/contracts/pyth/PythGetters.sol

+ 4 - 5
ethereum/contracts/pyth/Pyth.sol

@@ -195,16 +195,16 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
             index += attestationSize;
 
             // Store the attestation
-            PythInternalStructs.PriceInfo memory latestPrice = latestPriceInfo(priceId);
+            uint64 latestPublishTime = latestPriceInfoPublishTime(priceId);
 
             bool fresh = false;
-            if(info.price.publishTime > latestPrice.price.publishTime) {
+            if(info.price.publishTime > latestPublishTime) {
                 freshPrices += 1;
                 fresh = true;
                 setLatestPriceInfo(priceId, info);
             }
 
-            emit PriceFeedUpdate(priceId, fresh, vm.emitterChainId, vm.sequence, latestPrice.price.publishTime,
+            emit PriceFeedUpdate(priceId, fresh, vm.emitterChainId, vm.sequence, latestPublishTime,
                 info.price.publishTime, info.price.price, info.price.conf);
         }
 
@@ -230,8 +230,7 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
     }
 
     function priceFeedExists(bytes32 id) public override view returns (bool) {
-        PythInternalStructs.PriceInfo memory info = latestPriceInfo(id);
-        return (info.price.publishTime != 0);
+        return (latestPriceInfoPublishTime(id) != 0);
     }
 
     function getValidTimePeriod() public override view returns (uint) {

+ 4 - 0
ethereum/contracts/pyth/PythGetters.sol

@@ -27,6 +27,10 @@ contract PythGetters is PythState {
         return _state.latestPriceInfo[priceId];
     }
 
+    function latestPriceInfoPublishTime(bytes32 priceId) public view returns (uint64) {
+        return _state.latestPriceInfo[priceId].price.publishTime;
+    }
+
     function hashDataSource(PythInternalStructs.DataSource memory ds) public pure returns (bytes32) {
         return keccak256(abi.encodePacked(ds.chainId, ds.emitterAddress));
     }