Skip to content

Commit 8db2af6

Browse files
authored
Use latestPriceInfoPublishTime when possible (#377)
1 parent b232581 commit 8db2af6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ethereum/contracts/pyth/Pyth.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,16 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
195195
index += attestationSize;
196196

197197
// Store the attestation
198-
PythInternalStructs.PriceInfo memory latestPrice = latestPriceInfo(priceId);
198+
uint64 latestPublishTime = latestPriceInfoPublishTime(priceId);
199199

200200
bool fresh = false;
201-
if(info.price.publishTime > latestPrice.price.publishTime) {
201+
if(info.price.publishTime > latestPublishTime) {
202202
freshPrices += 1;
203203
fresh = true;
204204
setLatestPriceInfo(priceId, info);
205205
}
206206

207-
emit PriceFeedUpdate(priceId, fresh, vm.emitterChainId, vm.sequence, latestPrice.price.publishTime,
207+
emit PriceFeedUpdate(priceId, fresh, vm.emitterChainId, vm.sequence, latestPublishTime,
208208
info.price.publishTime, info.price.price, info.price.conf);
209209
}
210210

@@ -230,8 +230,7 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
230230
}
231231

232232
function priceFeedExists(bytes32 id) public override view returns (bool) {
233-
PythInternalStructs.PriceInfo memory info = latestPriceInfo(id);
234-
return (info.price.publishTime != 0);
233+
return (latestPriceInfoPublishTime(id) != 0);
235234
}
236235

237236
function getValidTimePeriod() public override view returns (uint) {

ethereum/contracts/pyth/PythGetters.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ contract PythGetters is PythState {
2727
return _state.latestPriceInfo[priceId];
2828
}
2929

30+
function latestPriceInfoPublishTime(bytes32 priceId) public view returns (uint64) {
31+
return _state.latestPriceInfo[priceId].price.publishTime;
32+
}
33+
3034
function hashDataSource(PythInternalStructs.DataSource memory ds) public pure returns (bytes32) {
3135
return keccak256(abi.encodePacked(ds.chainId, ds.emitterAddress));
3236
}

0 commit comments

Comments
 (0)