forked from Qortal/qortal
Updated electrumx with non null objects
This commit is contained in:
parent
a6cbdaafd8
commit
ea1d4dd962
@ -142,7 +142,7 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
|
||||
private int nextId = 1;
|
||||
|
||||
private static final int TX_CACHE_SIZE = 1000;
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
private final Map<String, BitcoinyTransaction> transactionCache = Collections.synchronizedMap(new LinkedHashMap<>(TX_CACHE_SIZE + 1, 0.75F, true) {
|
||||
// This method is called just after a new entry has been added
|
||||
@Override
|
||||
@ -222,10 +222,10 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
|
||||
if (!(countObj instanceof Long) || !(hexObj instanceof String))
|
||||
throw new ForeignBlockchainException.NetworkException("Missing/invalid 'count' or 'hex' entries in JSON from ElectrumX blockchain.block.headers RPC");
|
||||
|
||||
Long returnedCount = (Long) countObj;
|
||||
long returnedCount = (Long) countObj;
|
||||
String hex = (String) hexObj;
|
||||
|
||||
List<byte[]> rawBlockHeaders = new ArrayList<>(returnedCount.intValue());
|
||||
List<byte[]> rawBlockHeaders = new ArrayList<>((int) returnedCount);
|
||||
|
||||
byte[] raw = HashCode.fromString(hex).asBytes();
|
||||
|
||||
@ -592,7 +592,7 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
|
||||
|
||||
Object peers = this.connectedRpc("server.peers.subscribe");
|
||||
|
||||
for (Object rawPeer : (JSONArray) peers) {
|
||||
for (Object rawPeer : (JSONArray) Objects.requireNonNull(peers)) {
|
||||
JSONArray peer = (JSONArray) rawPeer;
|
||||
if (peer.size() < 3)
|
||||
// We're expecting at least 3 fields for each peer entry: IP, hostname, features
|
||||
@ -721,7 +721,7 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
|
||||
// Check connection is suitable by asking for server features, including genesis block hash
|
||||
JSONObject featuresJson = (JSONObject) this.connectedRpc("server.features");
|
||||
|
||||
if (featuresJson == null || Double.valueOf((String) featuresJson.get("protocol_min")) < MIN_PROTOCOL_VERSION)
|
||||
if (featuresJson == null || Double.parseDouble((String) featuresJson.get("protocol_min")) < MIN_PROTOCOL_VERSION)
|
||||
return Optional.of( recorder.recordConnection(server, requestedBy, true, false, MINIMUM_VERSION_ERROR) );
|
||||
|
||||
if (this.expectedGenesisHash != null && !((String) featuresJson.get("genesis_hash")).equals(this.expectedGenesisHash))
|
||||
@ -729,9 +729,11 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
|
||||
|
||||
// Ask for more servers
|
||||
Set<Server> moreServers = serverPeersSubscribe();
|
||||
|
||||
// Discard duplicate servers we already know
|
||||
moreServers.removeAll(this.servers);
|
||||
// Add to both lists
|
||||
|
||||
// Add all servers to both lists
|
||||
this.remainingServers.addAll(moreServers);
|
||||
this.servers.addAll(moreServers);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user