Skip to content

Commit

Permalink
Block: remove reference to deprecated getTimeSeconds()
Browse files Browse the repository at this point in the history
  • Loading branch information
schildbach committed Sep 2, 2024
1 parent 1f79cb7 commit 0aee8a1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/org/bitcoinj/core/AbstractBlockChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private void connectBlock(final Block block, StoredBlock storedPrev, boolean exp
block.getHashAsString(), filteredTxHashList.size(), filteredTxn.size());
for (Sha256Hash hash : filteredTxHashList) log.debug(" matched tx {}", hash);
}
if (expensiveChecks && block.getTimeSeconds() <= getMedianTimestampOfRecentBlocks(head, blockStore))
if (expensiveChecks && block.time().getEpochSecond() <= getMedianTimestampOfRecentBlocks(head, blockStore))
throw new VerificationException("Block's timestamp is too early");

// BIP 66 & 65: Enforce block version 3/4 once they are a supermajority of blocks
Expand Down Expand Up @@ -774,9 +774,9 @@ private static long getMedianTimestampOfRecentBlocks(StoredBlock storedBlock,
BlockStore store) throws BlockStoreException {
long[] timestamps = new long[11];
int unused = 9;
timestamps[10] = storedBlock.getHeader().getTimeSeconds();
timestamps[10] = storedBlock.getHeader().time().getEpochSecond();
while (unused >= 0 && (storedBlock = storedBlock.getPrev(store)) != null)
timestamps[unused--] = storedBlock.getHeader().getTimeSeconds();
timestamps[unused--] = storedBlock.getHeader().time().getEpochSecond();

Arrays.sort(timestamps, unused+1, 11);
return timestamps[unused + (11-unused)/2];
Expand Down Expand Up @@ -832,7 +832,7 @@ private void handleNewBestChain(StoredBlock storedPrev, StoredBlock newChainHead
for (Iterator<StoredBlock> it = newBlocks.descendingIterator(); it.hasNext();) {
cursor = it.next();
Block cursorBlock = cursor.getHeader();
if (expensiveChecks && cursorBlock.getTimeSeconds() <= getMedianTimestampOfRecentBlocks(cursor.getPrev(blockStore), blockStore))
if (expensiveChecks && cursorBlock.time().getEpochSecond() <= getMedianTimestampOfRecentBlocks(cursor.getPrev(blockStore), blockStore))
throw new VerificationException("Block's timestamp is too early during reorg");
TransactionOutputChanges txOutChanges;
if (cursor != newChainHead || block == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public EnumSet<Block.VerifyFlag> getBlockVerificationFlags(final Block block,
public EnumSet<Script.VerifyFlag> getTransactionVerificationFlags(final Block block,
final Transaction transaction, final VersionTally tally, final Integer height) {
final EnumSet<Script.VerifyFlag> verifyFlags = EnumSet.noneOf(Script.VerifyFlag.class);
if (block.getTimeSeconds() >= NetworkParameters.BIP16_ENFORCE_TIME)
if (block.time().getEpochSecond() >= NetworkParameters.BIP16_ENFORCE_TIME)
verifyFlags.add(Script.VerifyFlag.P2SH);

// Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block
log.info("Difficulty transition traversal took {}", watch);

Block blockIntervalAgo = cursor.getHeader();
int timespan = (int) (prev.getTimeSeconds() - blockIntervalAgo.getTimeSeconds());
int timespan = (int) (prev.time().getEpochSecond() - blockIntervalAgo.time().getEpochSecond());
// Limit the adjustment step.
final int targetTimespan = this.getTargetTimespan();
if (timespan < targetTimespan / 4)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/params/TestNet3Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block
// After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty
// and then leaving, making it too hard to mine a block. On non-difficulty transition points, easy
// blocks are allowed if there has been a span of 20 minutes without one.
final long timeDelta = nextBlock.getTimeSeconds() - prev.getTimeSeconds();
final long timeDelta = nextBlock.time().getEpochSecond() - prev.time().getEpochSecond();
// There is an integer underflow bug in bitcoin-qt that means mindiff blocks are accepted when time
// goes backwards.
if (timeDelta >= 0 && timeDelta <= NetworkParameters.TARGET_SPACING * 2) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/org/bitcoinj/core/BlockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException
ByteUtils.writeInt32LE(getVersion(), stream);
stream.write(getPrevBlockHash().serialize());
stream.write(getMerkleRoot().serialize());
ByteUtils.writeInt32LE(getTimeSeconds(), stream);
ByteUtils.writeInt32LE(time().getEpochSecond(), stream);
ByteUtils.writeInt32LE(getDifficultyTarget(), stream);
ByteUtils.writeInt32LE(getNonce(), stream);

Expand Down

0 comments on commit 0aee8a1

Please sign in to comment.