mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 07:12:17 +00:00
Rename Block.getTime() to Block.getTimeSeconds() and note the metric used in the javadoc.
Don't rethrow BlockStoreException as RuntimeException in BlockChain constructor. Updates issue 66.
This commit is contained in:
parent
4e097c1e80
commit
2191a9979f
@ -436,8 +436,11 @@ public class Block extends Message {
|
|||||||
this.hash = null;
|
this.hash = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the time in seconds at which the block was solved and broadcast, according to the clock of the solving node. */
|
/**
|
||||||
public long getTime() {
|
* Returns the time at which the block was solved and broadcast, according to the clock of the solving node.
|
||||||
|
* This is measured in seconds since the UNIX epoch (midnight Jan 1st 1970).
|
||||||
|
*/
|
||||||
|
public long getTimeSeconds() {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class BlockChain {
|
|||||||
* For the store you can use a {@link com.google.bitcoin.store.MemoryBlockStore} if you don't care about saving the downloaded data, or a
|
* For the store you can use a {@link com.google.bitcoin.store.MemoryBlockStore} if you don't care about saving the downloaded data, or a
|
||||||
* {@link com.google.bitcoin.store.BoundedOverheadBlockStore} if you'd like to ensure fast startup the next time you run the program.
|
* {@link com.google.bitcoin.store.BoundedOverheadBlockStore} if you'd like to ensure fast startup the next time you run the program.
|
||||||
*/
|
*/
|
||||||
public BlockChain(NetworkParameters params, Wallet wallet, BlockStore blockStore) {
|
public BlockChain(NetworkParameters params, Wallet wallet, BlockStore blockStore) throws BlockStoreException {
|
||||||
this(params, new ArrayList<Wallet>(), blockStore);
|
this(params, new ArrayList<Wallet>(), blockStore);
|
||||||
if (wallet != null)
|
if (wallet != null)
|
||||||
addWallet(wallet);
|
addWallet(wallet);
|
||||||
@ -89,21 +89,18 @@ public class BlockChain {
|
|||||||
* Constructs a BlockChain that has no wallet at all. This is helpful when you don't actually care about sending
|
* Constructs a BlockChain that has no wallet at all. This is helpful when you don't actually care about sending
|
||||||
* and receiving coins but rather, just want to explore the network data structures.
|
* and receiving coins but rather, just want to explore the network data structures.
|
||||||
*/
|
*/
|
||||||
public BlockChain(NetworkParameters params, BlockStore blockStore) {
|
public BlockChain(NetworkParameters params, BlockStore blockStore) throws BlockStoreException {
|
||||||
this(params, new ArrayList<Wallet>(), blockStore);
|
this(params, new ArrayList<Wallet>(), blockStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a BlockChain connected to the given list of wallets and a store.
|
* Constructs a BlockChain connected to the given list of wallets and a store.
|
||||||
*/
|
*/
|
||||||
public BlockChain(NetworkParameters params, List<Wallet> wallets, BlockStore blockStore){
|
public BlockChain(NetworkParameters params, List<Wallet> wallets,
|
||||||
try {
|
BlockStore blockStore) throws BlockStoreException {
|
||||||
this.blockStore = blockStore;
|
this.blockStore = blockStore;
|
||||||
chainHead = blockStore.getChainHead();
|
chainHead = blockStore.getChainHead();
|
||||||
log.info("chain head is:\n{}", chainHead.getHeader());
|
log.info("chain head is:\n{}", chainHead.getHeader());
|
||||||
} catch (BlockStoreException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.wallets = new ArrayList<Wallet>(wallets);
|
this.wallets = new ArrayList<Wallet>(wallets);
|
||||||
}
|
}
|
||||||
@ -397,7 +394,7 @@ public class BlockChain {
|
|||||||
log.info("Difficulty transition traversal took {}msec", System.currentTimeMillis() - now);
|
log.info("Difficulty transition traversal took {}msec", System.currentTimeMillis() - now);
|
||||||
|
|
||||||
Block blockIntervalAgo = cursor.getHeader();
|
Block blockIntervalAgo = cursor.getHeader();
|
||||||
int timespan = (int) (prev.getTime() - blockIntervalAgo.getTime());
|
int timespan = (int) (prev.getTimeSeconds() - blockIntervalAgo.getTimeSeconds());
|
||||||
// Limit the adjustment step.
|
// Limit the adjustment step.
|
||||||
if (timespan < params.targetTimespan / 4)
|
if (timespan < params.targetTimespan / 4)
|
||||||
timespan = params.targetTimespan / 4;
|
timespan = params.targetTimespan / 4;
|
||||||
|
@ -59,7 +59,7 @@ public class DownloadListener extends AbstractPeerEventListener {
|
|||||||
|
|
||||||
double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft));
|
double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft));
|
||||||
if ((int)pct != lastPercent) {
|
if ((int)pct != lastPercent) {
|
||||||
progress(pct, new Date(block.getTime() * 1000));
|
progress(pct, new Date(block.getTimeSeconds() * 1000));
|
||||||
lastPercent = (int)pct;
|
lastPercent = (int)pct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,8 @@ public class BlockChainTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet));
|
testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet));
|
||||||
|
|
||||||
unitTestParams = NetworkParameters.unitTests();
|
unitTestParams = NetworkParameters.unitTests();
|
||||||
wallet = new Wallet(unitTestParams);
|
wallet = new Wallet(unitTestParams);
|
||||||
wallet.addKey(new ECKey());
|
wallet.addKey(new ECKey());
|
||||||
|
@ -34,7 +34,7 @@ public class ChainSplitTests {
|
|||||||
private Address someOtherGuy;
|
private Address someOtherGuy;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
unitTestParams = NetworkParameters.unitTests();
|
unitTestParams = NetworkParameters.unitTests();
|
||||||
wallet = new Wallet(unitTestParams);
|
wallet = new Wallet(unitTestParams);
|
||||||
wallet.addKey(new ECKey());
|
wallet.addKey(new ECKey());
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright 2011 Google Inc.
|
* Copyright 2011 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
Loading…
Reference in New Issue
Block a user