mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-19 05:33:44 +01:00
Add/fix hashCodes/equals() implementations in some cases. Clears more FindBugs warnings.
This commit is contained in:
parent
440619f1c5
commit
1a5f74a148
@ -16,6 +16,7 @@
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -243,4 +244,9 @@ public class BloomFilter extends Message {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(hashFuncs, nTweak, Arrays.hashCode(data));
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,10 @@
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.spongycastle.util.Arrays;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Parses and generates private keys in the form used by the Bitcoin "dumpprivkey" command. This is the private key
|
||||
@ -76,4 +77,25 @@ public class DumpedPrivateKey extends VersionedChecksummedBytes {
|
||||
public ECKey getKey() {
|
||||
return new ECKey(new BigInteger(1, bytes), null, compressed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
// This odd construction is to avoid anti-symmetry of equality: where a.equals(b) != b.equals(a).
|
||||
boolean result = false;
|
||||
if (other instanceof VersionedChecksummedBytes) {
|
||||
result = Arrays.equals(bytes, ((VersionedChecksummedBytes)other).bytes);
|
||||
}
|
||||
if (other instanceof DumpedPrivateKey) {
|
||||
DumpedPrivateKey o = (DumpedPrivateKey) other;
|
||||
result = Arrays.equals(bytes, o.bytes) &&
|
||||
version == o.version &&
|
||||
compressed == o.compressed;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(bytes, version, compressed);
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
|
||||
LinkedList<StoredTransactionOutput> txOutsSpent = new LinkedList<StoredTransactionOutput>();
|
||||
LinkedList<StoredTransactionOutput> txOutsCreated = new LinkedList<StoredTransactionOutput>();
|
||||
long sigOps = 0;
|
||||
final boolean enforceBIP16 = block.getTimeSeconds() >= params.BIP16_ENFORCE_TIME;
|
||||
final boolean enforceBIP16 = block.getTimeSeconds() >= NetworkParameters.BIP16_ENFORCE_TIME;
|
||||
|
||||
if (scriptVerificationExecutor.isShutdown())
|
||||
scriptVerificationExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
@ -261,7 +261,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
|
||||
LinkedList<StoredTransactionOutput> txOutsSpent = new LinkedList<StoredTransactionOutput>();
|
||||
LinkedList<StoredTransactionOutput> txOutsCreated = new LinkedList<StoredTransactionOutput>();
|
||||
long sigOps = 0;
|
||||
final boolean enforcePayToScriptHash = newBlock.getHeader().getTimeSeconds() >= params.BIP16_ENFORCE_TIME;
|
||||
final boolean enforcePayToScriptHash = newBlock.getHeader().getTimeSeconds() >= NetworkParameters.BIP16_ENFORCE_TIME;
|
||||
if (!params.isCheckpoint(newBlock.getHeight())) {
|
||||
for(Transaction tx : transactions) {
|
||||
Sha256Hash hash = tx.getHash();
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -166,7 +167,7 @@ public class NetworkParameters implements Serializable {
|
||||
* network rules in a soft-forking manner, that is, blocks that don't follow the rules are accepted but not
|
||||
* mined upon and thus will be quickly re-orged out as long as the majority are enforcing the rule.
|
||||
*/
|
||||
public final int BIP16_ENFORCE_TIME = 1333238400;
|
||||
public static final int BIP16_ENFORCE_TIME = 1333238400;
|
||||
|
||||
/**
|
||||
* The maximum money to be generated
|
||||
@ -306,12 +307,18 @@ public class NetworkParameters implements Serializable {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof NetworkParameters)) return false;
|
||||
NetworkParameters o = (NetworkParameters) other;
|
||||
return o.getId().equals(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
/** Returns the network parameters for the given string ID or NULL if not recognized. */
|
||||
public static NetworkParameters fromID(String id) {
|
||||
if (id.equals(ID_PRODNET)) {
|
||||
|
Loading…
Reference in New Issue
Block a user