Skip to content

Commit

Permalink
style: clean up and simply code for several classes (#253)
Browse files Browse the repository at this point in the history
* FinalCommitment, GetQuorumRotationInfo, InstantSend8, LLMQ*, MasternodeConfig, Report
  • Loading branch information
HashEngineering authored Jul 6, 2024
1 parent 0615416 commit 9840285
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
* Created by Hash Engineering on 7/8/2018.
*/
public class MasternodeConfig {


public static class MasternodeEntry {

private String alias;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void setIp(String ip) {
protected File masternodeConfigFile;

public MasternodeConfig(File configFile) {
entries = new ArrayList<MasternodeEntry>();
entries = new ArrayList<>();
masternodeConfigFile = configFile;
}

Expand All @@ -94,15 +94,15 @@ public void add(String alias, String ip, String privKey, String txHash, String o
entries.add(cme);
}

public ArrayList<MasternodeEntry> getEntries() {
public List<MasternodeEntry> getEntries() {
return entries;
}

public int getCount() {
return entries.size();
}

private ArrayList<MasternodeEntry> entries;
private final ArrayList<MasternodeEntry> entries;

public boolean importFromFile(String fileToImport, StringBuilder strError) {
try {
Expand Down Expand Up @@ -190,8 +190,7 @@ public boolean read(StringBuilder strError) {
} catch (FileNotFoundException x) {
strError.append(x.getMessage());

try {
FileOutputStream configFile = new FileOutputStream(masternodeConfigFile, true);
try (FileOutputStream configFile = new FileOutputStream(masternodeConfigFile, true)) {
String strHeader = "# Masternode config file\n" + "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n" + "# Example: mn1 127.0.0.2:19999 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n";
configFile.write(strHeader.getBytes());
return true; // Nothing to read, so just return
Expand Down
27 changes: 12 additions & 15 deletions core/src/main/java/org/bitcoinj/quorums/FinalCommitment.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class FinalCommitment extends SpecialTxPayload {
@Deprecated
Expand Down Expand Up @@ -128,6 +129,7 @@ protected void parse() throws ProtocolException {
length = cursor - offset;
}

@Override
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException{
bitcoinSerializeToStream(stream, isLegacy());
}
Expand Down Expand Up @@ -189,6 +191,7 @@ public String getName() {
* }
*/

@Override
public JSONObject toJson() {
JSONObject result = new JSONObject();
result.put("version", getVersion());
Expand Down Expand Up @@ -245,7 +248,7 @@ public boolean verify(StoredBlock block, ArrayList<Masternode> members, boolean
return false;

if(!params.getLlmqs().containsKey(LLMQParameters.LLMQType.fromValue(llmqType))) {
log.error("invalid llmqType " + llmqType);
log.error("invalid llmqType: {}", llmqType);
return false;
}

Expand Down Expand Up @@ -325,13 +328,10 @@ public boolean isNull() {
countValidMembers() > 0) {
return false;
}
if (quorumPublicKey.isValid() ||
!quorumVvecHash.isZero() ||
membersSignature.isValid() ||
quorumSignature.isValid()) {
return false;
}
return true;
return !quorumPublicKey.isValid() &&
quorumVvecHash.isZero() &&
!membersSignature.isValid() &&
!quorumSignature.isValid();
}

public boolean verifyNull()
Expand All @@ -342,11 +342,7 @@ public boolean verifyNull()
}
LLMQParameters llmqParameters = params.getLlmqs().get(LLMQParameters.LLMQType.fromValue(llmqType));

if (!isNull() || !verifySizes(llmqParameters)) {
return false;
}

return true;
return isNull() && verifySizes(llmqParameters);
}

public boolean verifySizes(LLMQParameters llmqParameters) {
Expand All @@ -361,6 +357,7 @@ public boolean verifySizes(LLMQParameters llmqParameters) {
return true;
}

@Override
public Sha256Hash getHash() {
try {
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(getMessageSize());
Expand Down Expand Up @@ -407,11 +404,11 @@ public BLSSignature getQuorumSignature() {
return quorumSignature.getSignature();
}

public ArrayList<Boolean> getSigners() {
public List<Boolean> getSigners() {
return signers;
}

public ArrayList<Boolean> getValidMembers() {
public List<Boolean> getValidMembers() {
return validMembers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public GetQuorumRotationInfo(NetworkParameters params, byte [] payload) {
}

public GetQuorumRotationInfo(NetworkParameters params,
ArrayList<Sha256Hash> baseBlockHashes, Sha256Hash blockRequestHash, boolean extraShare) {
List<Sha256Hash> baseBlockHashes, Sha256Hash blockRequestHash, boolean extraShare) {
super(params);
this.baseBlockHashes = new ArrayList<>(baseBlockHashes.size());
this.baseBlockHashes.addAll(baseBlockHashes);
Expand Down Expand Up @@ -73,7 +73,7 @@ public Sha256Hash getBlockRequestHash() {
return blockRequestHash;
}

public ArrayList<Sha256Hash> getBaseBlockHashes() {
public List<Sha256Hash> getBaseBlockHashes() {
return baseBlockHashes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public Sha256Hash getRequestId() {
}
}

@Override
public Sha256Hash getHash() {
try {
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(getMessageSize());
Expand Down
Loading

0 comments on commit 9840285

Please sign in to comment.