forked from Qortal/qortal
Fix for issue causing tradeTimestamp to report as 0 for trades in archived blocks.
This commit is contained in:
parent
bbb71083ef
commit
1fbd5f7922
@ -222,6 +222,10 @@ public class CrossChainResource {
|
||||
|
||||
// We also need block timestamp for use as trade timestamp
|
||||
long timestamp = repository.getBlockRepository().getTimestampFromHeight(atState.getHeight());
|
||||
if (timestamp == 0) {
|
||||
// Try the archive
|
||||
timestamp = repository.getBlockArchiveRepository().getTimestampFromHeight(atState.getHeight());
|
||||
}
|
||||
|
||||
CrossChainTradeSummary crossChainTradeSummary = new CrossChainTradeSummary(crossChainTradeData, timestamp);
|
||||
crossChainTrades.add(crossChainTradeSummary);
|
||||
@ -421,4 +425,4 @@ public class CrossChainResource {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,15 @@ public interface BlockArchiveRepository {
|
||||
*/
|
||||
public int getHeightFromTimestamp(long timestamp) throws DataException;
|
||||
|
||||
/**
|
||||
* Returns block timestamp for a given height.
|
||||
*
|
||||
* @param height
|
||||
* @return timestamp, or 0 if height is out of bounds.
|
||||
* @throws DataException
|
||||
*/
|
||||
public long getTimestampFromHeight(int height) throws DataException;
|
||||
|
||||
/**
|
||||
* Returns block summaries for blocks signed by passed public key, or reward-share with minter with passed public key.
|
||||
*/
|
||||
|
@ -103,6 +103,20 @@ public class HSQLDBBlockArchiveRepository implements BlockArchiveRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestampFromHeight(int height) throws DataException {
|
||||
String sql = "SELECT minted_when FROM BlockArchive WHERE height = ?";
|
||||
|
||||
try (ResultSet resultSet = this.repository.checkedExecute(sql, height)) {
|
||||
if (resultSet == null)
|
||||
return 0;
|
||||
|
||||
return resultSet.getLong(1);
|
||||
} catch (SQLException e) {
|
||||
throw new DataException("Error obtaining block timestamp by height from BlockArchive repository", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockSummaryData> getBlockSummariesBySigner(byte[] signerPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||
StringBuilder sql = new StringBuilder(512);
|
||||
|
Loading…
x
Reference in New Issue
Block a user