mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 23:32:16 +00:00
More minor issues found by IntelliJ static analysis.
This commit is contained in:
parent
3a899767b4
commit
1ed2459522
@ -100,7 +100,7 @@ public class GetBlocksMessage extends Message {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = (int) version ^ "getblocks".hashCode();
|
int hashCode = (int) version ^ "getblocks".hashCode();
|
||||||
for (int i = 0; i < locator.size(); i++) hashCode ^= locator.get(i).hashCode();
|
for (Sha256Hash aLocator : locator) hashCode ^= aLocator.hashCode();
|
||||||
hashCode ^= stopHash.hashCode();
|
hashCode ^= stopHash.hashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class GetHeadersMessage extends GetBlocksMessage {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = (int) version ^ "getheaders".hashCode();
|
int hashCode = (int) version ^ "getheaders".hashCode();
|
||||||
for (int i = 0; i < locator.size(); i++) hashCode ^= locator.get(i).hashCode();
|
for (Sha256Hash aLocator : locator) hashCode ^= aLocator.hashCode();
|
||||||
hashCode ^= stopHash.hashCode();
|
hashCode ^= stopHash.hashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class HeadersMessage extends Message {
|
|||||||
// Read 80 bytes of the header and one more byte for the transaction list, which is always a 00 because the
|
// Read 80 bytes of the header and one more byte for the transaction list, which is always a 00 because the
|
||||||
// transaction list is empty.
|
// transaction list is empty.
|
||||||
byte[] blockHeader = readBytes(81);
|
byte[] blockHeader = readBytes(81);
|
||||||
if (blockHeader[80] != 00)
|
if (blockHeader[80] != 0)
|
||||||
throw new ProtocolException("Block header does not end with a null byte");
|
throw new ProtocolException("Block header does not end with a null byte");
|
||||||
Block newBlockHeader = new Block(this.params, blockHeader, true, true, 81);
|
Block newBlockHeader = new Block(this.params, blockHeader, true, true, 81);
|
||||||
blockHeaders.add(newBlockHeader);
|
blockHeaders.add(newBlockHeader);
|
||||||
|
@ -109,69 +109,66 @@ public class DiskBlockStore implements BlockStore {
|
|||||||
|
|
||||||
private void load(File theFile) throws IOException, BlockStoreException {
|
private void load(File theFile) throws IOException, BlockStoreException {
|
||||||
log.info("Reading block store from {}", theFile);
|
log.info("Reading block store from {}", theFile);
|
||||||
try {
|
// Read a version byte.
|
||||||
// Read a version byte.
|
int version = file.read();
|
||||||
int version = file.read();
|
if (version == -1) {
|
||||||
if (version == -1) {
|
// No such file or the file was empty.
|
||||||
// No such file or the file was empty.
|
throw new FileNotFoundException(theFile.getName() + " is empty");
|
||||||
throw new FileNotFoundException(theFile.getName() + " is empty");
|
|
||||||
}
|
|
||||||
if (version != 1) {
|
|
||||||
throw new BlockStoreException("Bad version number: " + version);
|
|
||||||
}
|
|
||||||
// Chain head pointer is the first thing in the file.
|
|
||||||
byte[] chainHeadHash = new byte[32];
|
|
||||||
if (file.read(chainHeadHash) < chainHeadHash.length)
|
|
||||||
throw new BlockStoreException("Truncated block store: cannot read chain head hash");
|
|
||||||
this.chainHead = new Sha256Hash(chainHeadHash);
|
|
||||||
log.info("Read chain head from disk: {}", this.chainHead);
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
// Rest of file is raw block headers.
|
|
||||||
byte[] headerBytes = new byte[Block.HEADER_SIZE];
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
// Read a block from disk.
|
|
||||||
int read = file.read(headerBytes);
|
|
||||||
if (read == -1) {
|
|
||||||
// End of file.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (read < headerBytes.length) {
|
|
||||||
throw new BlockStoreException("Truncated block store: partial block read");
|
|
||||||
}
|
|
||||||
// Parse it.
|
|
||||||
Block b = new Block(params, headerBytes);
|
|
||||||
// Look up the previous block it connects to.
|
|
||||||
StoredBlock prev = get(b.getPrevBlockHash());
|
|
||||||
StoredBlock s;
|
|
||||||
if (prev == null) {
|
|
||||||
// First block in the stored chain has to be treated specially.
|
|
||||||
if (b.equals(params.genesisBlock)) {
|
|
||||||
s = new StoredBlock(params.genesisBlock.cloneAsHeader(), params.genesisBlock.getWork(), 0);
|
|
||||||
} else {
|
|
||||||
throw new BlockStoreException("Could not connect " + b.getHash().toString() + " to "
|
|
||||||
+ b.getPrevBlockHash().toString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Don't try to verify the genesis block to avoid upsetting the unit tests.
|
|
||||||
b.verifyHeader();
|
|
||||||
// Calculate its height and total chain work.
|
|
||||||
s = prev.build(b);
|
|
||||||
}
|
|
||||||
// Save in memory.
|
|
||||||
blockMap.put(b.getHash(), s);
|
|
||||||
}
|
|
||||||
} catch (ProtocolException e) {
|
|
||||||
// Corrupted file.
|
|
||||||
throw new BlockStoreException(e);
|
|
||||||
} catch (VerificationException e) {
|
|
||||||
// Should not be able to happen unless the file contains bad blocks.
|
|
||||||
throw new BlockStoreException(e);
|
|
||||||
}
|
|
||||||
long elapsed = System.currentTimeMillis() - now;
|
|
||||||
log.info("Block chain read complete in {}ms", elapsed);
|
|
||||||
} finally {
|
|
||||||
}
|
}
|
||||||
|
if (version != 1) {
|
||||||
|
throw new BlockStoreException("Bad version number: " + version);
|
||||||
|
}
|
||||||
|
// Chain head pointer is the first thing in the file.
|
||||||
|
byte[] chainHeadHash = new byte[32];
|
||||||
|
if (file.read(chainHeadHash) < chainHeadHash.length)
|
||||||
|
throw new BlockStoreException("Truncated block store: cannot read chain head hash");
|
||||||
|
this.chainHead = new Sha256Hash(chainHeadHash);
|
||||||
|
log.info("Read chain head from disk: {}", this.chainHead);
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
// Rest of file is raw block headers.
|
||||||
|
byte[] headerBytes = new byte[Block.HEADER_SIZE];
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
// Read a block from disk.
|
||||||
|
int read = file.read(headerBytes);
|
||||||
|
if (read == -1) {
|
||||||
|
// End of file.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (read < headerBytes.length) {
|
||||||
|
throw new BlockStoreException("Truncated block store: partial block read");
|
||||||
|
}
|
||||||
|
// Parse it.
|
||||||
|
Block b = new Block(params, headerBytes);
|
||||||
|
// Look up the previous block it connects to.
|
||||||
|
StoredBlock prev = get(b.getPrevBlockHash());
|
||||||
|
StoredBlock s;
|
||||||
|
if (prev == null) {
|
||||||
|
// First block in the stored chain has to be treated specially.
|
||||||
|
if (b.equals(params.genesisBlock)) {
|
||||||
|
s = new StoredBlock(params.genesisBlock.cloneAsHeader(), params.genesisBlock.getWork(), 0);
|
||||||
|
} else {
|
||||||
|
throw new BlockStoreException("Could not connect " + b.getHash().toString() + " to "
|
||||||
|
+ b.getPrevBlockHash().toString());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Don't try to verify the genesis block to avoid upsetting the unit tests.
|
||||||
|
b.verifyHeader();
|
||||||
|
// Calculate its height and total chain work.
|
||||||
|
s = prev.build(b);
|
||||||
|
}
|
||||||
|
// Save in memory.
|
||||||
|
blockMap.put(b.getHash(), s);
|
||||||
|
}
|
||||||
|
} catch (ProtocolException e) {
|
||||||
|
// Corrupted file.
|
||||||
|
throw new BlockStoreException(e);
|
||||||
|
} catch (VerificationException e) {
|
||||||
|
// Should not be able to happen unless the file contains bad blocks.
|
||||||
|
throw new BlockStoreException(e);
|
||||||
|
}
|
||||||
|
long elapsed = System.currentTimeMillis() - now;
|
||||||
|
log.info("Block chain read complete in {}ms", elapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureOpen() throws BlockStoreException {
|
private void ensureOpen() throws BlockStoreException {
|
||||||
|
@ -43,6 +43,6 @@ public class WalletExtensionSerializer {
|
|||||||
* Get collection of extensions to add, should be overridden by any class adding wallet extensions.
|
* Get collection of extensions to add, should be overridden by any class adding wallet extensions.
|
||||||
*/
|
*/
|
||||||
public Collection<Protos.Extension> getExtensionsToWrite(Wallet wallet) {
|
public Collection<Protos.Extension> getExtensionsToWrite(Wallet wallet) {
|
||||||
return Collections.<Protos.Extension>emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,11 +185,11 @@ public class BitcoinURI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to decode the rest of the tokens into a parameter map.
|
// Attempt to decode the rest of the tokens into a parameter map.
|
||||||
for (int i = 0; i < nameValuePairTokens.length; i++) {
|
for (String nameValuePairToken : nameValuePairTokens) {
|
||||||
String[] tokens = nameValuePairTokens[i].split("=");
|
String[] tokens = nameValuePairToken.split("=");
|
||||||
if (tokens.length != 2 || "".equals(tokens[0])) {
|
if (tokens.length != 2 || "".equals(tokens[0])) {
|
||||||
throw new BitcoinURIParseException("Malformed Bitcoin URI - cannot parse name value pair '" +
|
throw new BitcoinURIParseException("Malformed Bitcoin URI - cannot parse name value pair '" +
|
||||||
nameValuePairTokens[i] + "'");
|
nameValuePairToken + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
String nameToken = tokens[0].toLowerCase();
|
String nameToken = tokens[0].toLowerCase();
|
||||||
|
Loading…
Reference in New Issue
Block a user