Use latestPriceInfoPublishTime when possible (#377)
This commit is contained in:
parent
b23258112d
commit
8db2af6ee5
|
@ -195,16 +195,16 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
|
||||||
index += attestationSize;
|
index += attestationSize;
|
||||||
|
|
||||||
// Store the attestation
|
// Store the attestation
|
||||||
PythInternalStructs.PriceInfo memory latestPrice = latestPriceInfo(priceId);
|
uint64 latestPublishTime = latestPriceInfoPublishTime(priceId);
|
||||||
|
|
||||||
bool fresh = false;
|
bool fresh = false;
|
||||||
if(info.price.publishTime > latestPrice.price.publishTime) {
|
if(info.price.publishTime > latestPublishTime) {
|
||||||
freshPrices += 1;
|
freshPrices += 1;
|
||||||
fresh = true;
|
fresh = true;
|
||||||
setLatestPriceInfo(priceId, info);
|
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);
|
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) {
|
function priceFeedExists(bytes32 id) public override view returns (bool) {
|
||||||
PythInternalStructs.PriceInfo memory info = latestPriceInfo(id);
|
return (latestPriceInfoPublishTime(id) != 0);
|
||||||
return (info.price.publishTime != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValidTimePeriod() public override view returns (uint) {
|
function getValidTimePeriod() public override view returns (uint) {
|
||||||
|
|
|
@ -27,6 +27,10 @@ contract PythGetters is PythState {
|
||||||
return _state.latestPriceInfo[priceId];
|
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) {
|
function hashDataSource(PythInternalStructs.DataSource memory ds) public pure returns (bytes32) {
|
||||||
return keccak256(abi.encodePacked(ds.chainId, ds.emitterAddress));
|
return keccak256(abi.encodePacked(ds.chainId, ds.emitterAddress));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue