Browse Source

Fix for issue causing tradeTimestamp to report as 0 for trades in archived blocks.

mempow-testing
CalDescent 3 years ago
parent
commit
1fbd5f7922
  1. 6
      src/main/java/org/qortal/api/resource/CrossChainResource.java
  2. 9
      src/main/java/org/qortal/repository/BlockArchiveRepository.java
  3. 14
      src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockArchiveRepository.java

6
src/main/java/org/qortal/api/resource/CrossChainResource.java

@ -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 {
}
}
}
}

9
src/main/java/org/qortal/repository/BlockArchiveRepository.java

@ -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.
*/

14
src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockArchiveRepository.java

@ -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…
Cancel
Save