mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-30 23:02:15 +00:00
Clear some FindBugs warnings.
This commit is contained in:
parent
5a3515bef0
commit
883bf03007
@ -240,10 +240,12 @@ public class Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m == null) return;
|
if (m == null) return;
|
||||||
|
|
||||||
if (currentFilteredBlock != null && !(m instanceof Transaction)) {
|
synchronized (Peer.this) {
|
||||||
processFilteredBlock(currentFilteredBlock);
|
if (currentFilteredBlock != null && !(m instanceof Transaction)) {
|
||||||
currentFilteredBlock = null;
|
processFilteredBlock(currentFilteredBlock);
|
||||||
|
currentFilteredBlock = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m instanceof NotFoundMessage) {
|
if (m instanceof NotFoundMessage) {
|
||||||
@ -259,7 +261,9 @@ public class Peer {
|
|||||||
// messages stream in. We'll call processFilteredBlock when a non-tx message arrives (eg, another
|
// messages stream in. We'll call processFilteredBlock when a non-tx message arrives (eg, another
|
||||||
// FilteredBlock) or when a tx that isn't needed by that block is found. A ping message is sent after
|
// FilteredBlock) or when a tx that isn't needed by that block is found. A ping message is sent after
|
||||||
// a getblocks, to force the non-tx message path.
|
// a getblocks, to force the non-tx message path.
|
||||||
currentFilteredBlock = (FilteredBlock)m;
|
synchronized (Peer.this) {
|
||||||
|
currentFilteredBlock = (FilteredBlock)m;
|
||||||
|
}
|
||||||
} else if (m instanceof Transaction) {
|
} else if (m instanceof Transaction) {
|
||||||
processTransaction((Transaction) m);
|
processTransaction((Transaction) m);
|
||||||
} else if (m instanceof GetDataMessage) {
|
} else if (m instanceof GetDataMessage) {
|
||||||
|
@ -596,9 +596,10 @@ public class PeerGroup extends AbstractIdleService {
|
|||||||
* Be careful regenerating the bloom filter too often, as it decreases anonymity because remote nodes can
|
* Be careful regenerating the bloom filter too often, as it decreases anonymity because remote nodes can
|
||||||
* compare transactions against both the new and old filters to significantly decrease the false positive rate.
|
* compare transactions against both the new and old filters to significantly decrease the false positive rate.
|
||||||
*
|
*
|
||||||
* See the docs for {@link BloomFilter#BloomFilter(int, double)} for a brief explanation of anonymity when using bloom filters.
|
* See the docs for {@link BloomFilter#BloomFilter(int, double, long)} for a brief explanation of anonymity when
|
||||||
|
* using bloom filters.
|
||||||
*/
|
*/
|
||||||
public void setBloomFilterFalsePositiveRate(double bloomFilterFPRate) {
|
public synchronized void setBloomFilterFalsePositiveRate(double bloomFilterFPRate) {
|
||||||
this.bloomFilterFPRate = bloomFilterFPRate;
|
this.bloomFilterFPRate = bloomFilterFPRate;
|
||||||
recalculateFastCatchupAndFilter();
|
recalculateFastCatchupAndFilter();
|
||||||
}
|
}
|
||||||
|
@ -16,20 +16,19 @@
|
|||||||
|
|
||||||
package com.google.bitcoin.core;
|
package com.google.bitcoin.core;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.*;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
public class ScriptTest {
|
public class ScriptTest {
|
||||||
// From tx 05e04c26c12fe408a3c1b71aa7996403f6acad1045252b1c62e055496f4d2cb1 on the testnet.
|
// From tx 05e04c26c12fe408a3c1b71aa7996403f6acad1045252b1c62e055496f4d2cb1 on the testnet.
|
||||||
@ -67,8 +66,9 @@ public class ScriptTest {
|
|||||||
assertTrue(s.isSentToRawPubKey());
|
assertTrue(s.isSentToRawPubKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
static HashMap<String, Integer> mapOpNames;
|
private static HashMap<String, Integer> mapOpNames;
|
||||||
private Script parseScriptString(NetworkParameters params, String string) throws Exception {
|
|
||||||
|
private synchronized static void initMapOpNames() {
|
||||||
if (mapOpNames == null) {
|
if (mapOpNames == null) {
|
||||||
mapOpNames = new HashMap<String, Integer>();
|
mapOpNames = new HashMap<String, Integer>();
|
||||||
for (int op = Script.OP_NOP; op <= Script.OP_NOP10; op++) {
|
for (int op = Script.OP_NOP; op <= Script.OP_NOP10; op++) {
|
||||||
@ -79,7 +79,10 @@ public class ScriptTest {
|
|||||||
mapOpNames.put(name, op);
|
mapOpNames.put(name, op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Script parseScriptString(NetworkParameters params, String string) throws Exception {
|
||||||
|
initMapOpNames();
|
||||||
String[] words = string.split("[ \\t\\n]");
|
String[] words = string.split("[ \\t\\n]");
|
||||||
|
|
||||||
UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream();
|
UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream();
|
||||||
@ -100,7 +103,7 @@ public class ScriptTest {
|
|||||||
} else if (w.length() >= 2 && w.startsWith("'") && w.endsWith("'")) {
|
} else if (w.length() >= 2 && w.startsWith("'") && w.endsWith("'")) {
|
||||||
// Single-quoted string, pushed as data. NOTE: this is poor-man's
|
// Single-quoted string, pushed as data. NOTE: this is poor-man's
|
||||||
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
|
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
|
||||||
Script.writeBytes(out, w.substring(1, w.length() - 1).getBytes());
|
Script.writeBytes(out, w.substring(1, w.length() - 1).getBytes(Charset.forName("UTF-8")));
|
||||||
} else if (mapOpNames.containsKey(w)) {
|
} else if (mapOpNames.containsKey(w)) {
|
||||||
// opcode, e.g. OP_ADD or OP_1:
|
// opcode, e.g. OP_ADD or OP_1:
|
||||||
out.write(mapOpNames.get(w));
|
out.write(mapOpNames.get(w));
|
||||||
@ -117,7 +120,8 @@ public class ScriptTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataDrivenValidScripts() throws Exception {
|
public void dataDrivenValidScripts() throws Exception {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("script_valid.json")));
|
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||||
|
getClass().getResourceAsStream("script_valid.json"), Charset.forName("UTF-8")));
|
||||||
|
|
||||||
NetworkParameters params = NetworkParameters.testNet();
|
NetworkParameters params = NetworkParameters.testNet();
|
||||||
|
|
||||||
@ -125,6 +129,7 @@ public class ScriptTest {
|
|||||||
String script = "";
|
String script = "";
|
||||||
while (in.ready()) {
|
while (in.ready()) {
|
||||||
String line = in.readLine();
|
String line = in.readLine();
|
||||||
|
if (line == null || line.equals("")) continue;
|
||||||
script += line;
|
script += line;
|
||||||
if (line.equals("]") && script.equals("]") && !in.ready())
|
if (line.equals("]") && script.equals("]") && !in.ready())
|
||||||
break; // ignore last ]
|
break; // ignore last ]
|
||||||
@ -143,7 +148,8 @@ public class ScriptTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataDrivenInvalidScripts() throws Exception {
|
public void dataDrivenInvalidScripts() throws Exception {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("script_invalid.json")));
|
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||||
|
getClass().getResourceAsStream("script_invalid.json"), Charset.forName("UTF-8")));
|
||||||
|
|
||||||
NetworkParameters params = NetworkParameters.testNet();
|
NetworkParameters params = NetworkParameters.testNet();
|
||||||
|
|
||||||
@ -151,6 +157,7 @@ public class ScriptTest {
|
|||||||
String script = "";
|
String script = "";
|
||||||
while (in.ready()) {
|
while (in.ready()) {
|
||||||
String line = in.readLine();
|
String line = in.readLine();
|
||||||
|
if (line == null || line.equals("")) continue;
|
||||||
script += line;
|
script += line;
|
||||||
if (line.equals("]") && script.equals("]") && !in.ready())
|
if (line.equals("]") && script.equals("]") && !in.ready())
|
||||||
break; // ignore last ]
|
break; // ignore last ]
|
||||||
@ -162,14 +169,16 @@ public class ScriptTest {
|
|||||||
|
|
||||||
scriptSig.correctlySpends(new Transaction(params), 0, scriptPubKey, true);
|
scriptSig.correctlySpends(new Transaction(params), 0, scriptPubKey, true);
|
||||||
fail();
|
fail();
|
||||||
} catch (VerificationException e) {}
|
} catch (VerificationException e) {
|
||||||
|
// Expected.
|
||||||
|
}
|
||||||
script = "";
|
script = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
class JSONObject {
|
private static class JSONObject {
|
||||||
String string;
|
String string;
|
||||||
List<JSONObject> list;
|
List<JSONObject> list;
|
||||||
boolean booleanValue;
|
boolean booleanValue;
|
||||||
@ -210,6 +219,8 @@ public class ScriptTest {
|
|||||||
if (!inString)
|
if (!inString)
|
||||||
inArray++;
|
inArray++;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inArray != 0 || closePos == 0)
|
if (inArray != 0 || closePos == 0)
|
||||||
@ -259,7 +270,8 @@ public class ScriptTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataDrivenValidTransactions() throws Exception {
|
public void dataDrivenValidTransactions() throws Exception {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("tx_valid.json")));
|
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||||
|
getClass().getResourceAsStream("tx_valid.json"), Charset.forName("UTF-8")));
|
||||||
|
|
||||||
NetworkParameters params = NetworkParameters.testNet();
|
NetworkParameters params = NetworkParameters.testNet();
|
||||||
|
|
||||||
@ -269,8 +281,7 @@ public class ScriptTest {
|
|||||||
StringBuffer buffer = new StringBuffer(1000);
|
StringBuffer buffer = new StringBuffer(1000);
|
||||||
while (in.ready()) {
|
while (in.ready()) {
|
||||||
String line = in.readLine();
|
String line = in.readLine();
|
||||||
if (line.equals(""))
|
if (line == null || line.equals("")) continue;
|
||||||
continue;
|
|
||||||
buffer.append(line);
|
buffer.append(line);
|
||||||
if (line.equals("]") && buffer.toString().equals("]") && !in.ready())
|
if (line.equals("]") && buffer.toString().equals("]") && !in.ready())
|
||||||
break;
|
break;
|
||||||
@ -283,10 +294,12 @@ public class ScriptTest {
|
|||||||
String hash = input.list.get(0).string;
|
String hash = input.list.get(0).string;
|
||||||
int index = input.list.get(1).integer;
|
int index = input.list.get(1).integer;
|
||||||
String script = input.list.get(2).string;
|
String script = input.list.get(2).string;
|
||||||
scriptPubKeys.put(new TransactionOutPoint(params, index, new Sha256Hash(Hex.decode(hash.getBytes()))), parseScriptString(params, script));
|
Sha256Hash sha256Hash = new Sha256Hash(Hex.decode(hash.getBytes(Charset.forName("UTF-8"))));
|
||||||
|
scriptPubKeys.put(new TransactionOutPoint(params, index, sha256Hash), parseScriptString(params, script));
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction transaction = new Transaction(params, Hex.decode(tx.get(0).list.get(1).string.getBytes()));
|
byte[] bytes = tx.get(0).list.get(1).string.getBytes(Charset.forName("UTF-8"));
|
||||||
|
Transaction transaction = new Transaction(params, Hex.decode(bytes));
|
||||||
boolean enforceP2SH = tx.get(0).list.get(2).booleanValue;
|
boolean enforceP2SH = tx.get(0).list.get(2).booleanValue;
|
||||||
assertTrue(tx.get(0).list.get(2).isBoolean());
|
assertTrue(tx.get(0).list.get(2).isBoolean());
|
||||||
|
|
||||||
@ -307,17 +320,18 @@ public class ScriptTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataDrivenInvalidTransactions() throws Exception {
|
public void dataDrivenInvalidTransactions() throws Exception {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("tx_invalid.json")));
|
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||||
|
getClass().getResourceAsStream("tx_invalid.json"), Charset.forName("UTF-8")));
|
||||||
|
|
||||||
NetworkParameters params = NetworkParameters.testNet();
|
NetworkParameters params = NetworkParameters.testNet();
|
||||||
|
|
||||||
// Poor man's (aka. really, really poor) JSON parser (because pulling in a lib for this is probably not overkill)
|
// Poor man's (aka. really, really poor) JSON parser (because pulling in a lib for this is probably overkill)
|
||||||
List<JSONObject> tx = new ArrayList<JSONObject>(1);
|
List<JSONObject> tx = new ArrayList<JSONObject>(1);
|
||||||
in.read(); // remove first [
|
in.read(); // remove first [
|
||||||
StringBuffer buffer = new StringBuffer(1000);
|
StringBuffer buffer = new StringBuffer(1000);
|
||||||
while (in.ready()) {
|
while (in.ready()) {
|
||||||
String line = in.readLine();
|
String line = in.readLine();
|
||||||
if (line.equals(""))
|
if (line == null || line.equals(""))
|
||||||
continue;
|
continue;
|
||||||
buffer.append(line);
|
buffer.append(line);
|
||||||
if (line.equals("]") && buffer.toString().equals("]") && !in.ready())
|
if (line.equals("]") && buffer.toString().equals("]") && !in.ready())
|
||||||
@ -331,10 +345,12 @@ public class ScriptTest {
|
|||||||
String hash = input.list.get(0).string;
|
String hash = input.list.get(0).string;
|
||||||
int index = input.list.get(1).integer;
|
int index = input.list.get(1).integer;
|
||||||
String script = input.list.get(2).string;
|
String script = input.list.get(2).string;
|
||||||
scriptPubKeys.put(new TransactionOutPoint(params, index, new Sha256Hash(Hex.decode(hash.getBytes()))), parseScriptString(params, script));
|
Sha256Hash sha256Hash = new Sha256Hash(Hex.decode(hash.getBytes(Charset.forName("UTF-8"))));
|
||||||
|
scriptPubKeys.put(new TransactionOutPoint(params, index, sha256Hash), parseScriptString(params, script));
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction transaction = new Transaction(params, Hex.decode(tx.get(0).list.get(1).string.getBytes()));
|
byte[] bytes = tx.get(0).list.get(1).string.getBytes(Charset.forName("UTF-8"));
|
||||||
|
Transaction transaction = new Transaction(params, Hex.decode(bytes));
|
||||||
boolean enforceP2SH = tx.get(0).list.get(2).booleanValue;
|
boolean enforceP2SH = tx.get(0).list.get(2).booleanValue;
|
||||||
assertTrue(tx.get(0).list.get(2).isBoolean());
|
assertTrue(tx.get(0).list.get(2).isBoolean());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user