mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-22 14:22:45 +01:00
BuildCheckpoints: migrate to java.time
API
This commit is contained in:
parent
9eef9094b5
commit
4ae610f9cd
1 changed files with 14 additions and 10 deletions
|
@ -42,7 +42,10 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.DigestOutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
|
@ -135,17 +138,18 @@ public class BuildCheckpoints implements Callable<Integer> {
|
|||
// Sorted map of block height to StoredBlock object.
|
||||
final TreeMap<Integer, StoredBlock> checkpoints = new TreeMap<>();
|
||||
|
||||
long now = new Date().getTime() / 1000;
|
||||
peerGroup.setFastCatchupTimeSecs(now);
|
||||
Instant now = TimeUtils.currentTime();
|
||||
peerGroup.setFastCatchupTime(now);
|
||||
|
||||
final long timeAgo = now - (86400 * days);
|
||||
System.out.println("Checkpointing up to " + TimeUtils.dateTimeFormat(timeAgo * 1000));
|
||||
Instant timeAgo = now.minus(days, ChronoUnit.DAYS);
|
||||
System.out.println("Checkpointing up to " + TimeUtils.dateTimeFormat(timeAgo.toEpochMilli()));
|
||||
|
||||
chain.addNewBestBlockListener(Threading.SAME_THREAD, block -> {
|
||||
int height = block.getHeight();
|
||||
if (height % params.getInterval() == 0 && block.getHeader().getTimeSeconds() <= timeAgo) {
|
||||
if (height % params.getInterval() == 0 && timeAgo.isAfter(block.getHeader().getTimeInstant())) {
|
||||
System.out.println(String.format("Checkpointing block %s at height %d, time %s",
|
||||
block.getHeader().getHash(), block.getHeight(), TimeUtils.dateTimeFormat(block.getHeader().getTime())));
|
||||
block.getHeader().getHash(), block.getHeight(),
|
||||
TimeUtils.dateTimeFormat(block.getHeader().getTimeInstant().toEpochMilli())));
|
||||
checkpoints.put(height, block);
|
||||
}
|
||||
});
|
||||
|
@ -222,17 +226,17 @@ public class BuildCheckpoints implements Callable<Integer> {
|
|||
checkState(manager.numCheckpoints() == expectedSize);
|
||||
|
||||
if (params.network() == BitcoinNetwork.MAINNET) {
|
||||
StoredBlock test = manager.getCheckpointBefore(1390500000); // Thu Jan 23 19:00:00 CET 2014
|
||||
StoredBlock test = manager.getCheckpointBefore(Instant.ofEpochSecond(1390500000)); // Thu Jan 23 19:00:00 CET 2014
|
||||
checkState(test.getHeight() == 280224);
|
||||
checkState(test.getHeader().getHashAsString()
|
||||
.equals("00000000000000000b5d59a15f831e1c45cb688a4db6b0a60054d49a9997fa34"));
|
||||
} else if (params.network() == BitcoinNetwork.TESTNET) {
|
||||
StoredBlock test = manager.getCheckpointBefore(1390500000); // Thu Jan 23 19:00:00 CET 2014
|
||||
StoredBlock test = manager.getCheckpointBefore(Instant.ofEpochSecond(1390500000)); // Thu Jan 23 19:00:00 CET 2014
|
||||
checkState(test.getHeight() == 167328);
|
||||
checkState(test.getHeader().getHashAsString()
|
||||
.equals("0000000000035ae7d5025c2538067fe7adb1cf5d5d9c31b024137d9090ed13a9"));
|
||||
} else if (params.network() == BitcoinNetwork.SIGNET) {
|
||||
StoredBlock test = manager.getCheckpointBefore(1642000000); // 2022-01-12
|
||||
StoredBlock test = manager.getCheckpointBefore(Instant.ofEpochSecond(1642000000)); // 2022-01-12
|
||||
checkState(test.getHeight() == 72576);
|
||||
checkState(test.getHeader().getHashAsString()
|
||||
.equals("0000008f763bdf23bd159a21ccf211098707671d2ca9aa72d0f586c24505c5e7"));
|
||||
|
|
Loading…
Add table
Reference in a new issue