Skip to content

Commit

Permalink
refactor: add and modify getters for SimplifiedMasternodeList
Browse files Browse the repository at this point in the history
Signed-off-by: HashEngineering <[email protected]>
  • Loading branch information
HashEngineering committed Jul 6, 2024
1 parent 088afce commit 0d5c8ae
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class SimplifiedMasternodeListDiff extends AbstractDiffMessage {
public static final short BASIC_BLS_VERSION = 2;
public static final short CURRENT_VERSION = 1;
private short version;
public Sha256Hash prevBlockHash;
public Sha256Hash blockHash;
private Sha256Hash prevBlockHash;
private Sha256Hash blockHash;
PartialMerkleTree cbTxMerkleTree;
Transaction coinBaseTx;
protected HashSet<Sha256Hash> deletedMNs;
Expand Down Expand Up @@ -188,6 +188,14 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException
}
}

public Sha256Hash getPrevBlockHash() {
return prevBlockHash;
}

public Sha256Hash getBlockHash() {
return blockHash;
}

public boolean hasChanges() {
return !mnList.isEmpty() || !deletedMNs.isEmpty() || hasQuorumChanges();
}
Expand All @@ -197,10 +205,14 @@ boolean verify() {
return true;
}

private String getAddRemovedString() {
return String.format("adding %d and removing %d masternodes%s", mnList.size(), deletedMNs.size(),
(coinBaseTx.getExtraPayloadObject().getVersion() >= 2 ? (String.format(" while adding %d and removing %d quorums", newQuorums.size(), deletedQuorums.size())) : ""));
}

@Override
public String toString() {
return "Simplified MNList Diff: adding " + mnList.size() + " and removing " + deletedMNs.size() + " masternodes" +
(coinBaseTx.getExtraPayloadObject().getVersion() >= 2 ? (" while adding " + newQuorums.size() + " and removing " + deletedQuorums.size() + " quorums") : "");
return String.format("Simplified MNList Diff{ %s }", getAddRemovedString());
}

public String toString(DualBlockChain blockChain) {
Expand All @@ -212,28 +224,22 @@ public String toString(DualBlockChain blockChain) {
} catch (Exception x) {
// swallow
}
StringBuilder builder = new StringBuilder();
builder.append("Simplified MNList Diff: ").append(prevHeight).append(" -> ").append(height).append("/").append(getHeight())
.append(" [adding ").append(mnList.size()).append(" and removing ").append(deletedMNs.size()).append(" masternodes")
.append(coinBaseTx.getExtraPayloadObject().getVersion() >= 2 ? (" while adding " + newQuorums.size() + " and removing " + deletedQuorums.size() + " quorums") : "")
.append("]");

return builder.toString();
return String.format("Simplified MNList Diff{ %d -> %d/%d; %s }", prevHeight, height, getHeight(), getAddRemovedString());
}

public Transaction getCoinBaseTx() {
return coinBaseTx;
}

public ArrayList<SimplifiedMasternodeListEntry> getMnList() {
public List<SimplifiedMasternodeListEntry> getMnList() {
return mnList;
}

public ArrayList<Pair<Integer, Sha256Hash>> getDeletedQuorums() {
public List<Pair<Integer, Sha256Hash>> getDeletedQuorums() {
return deletedQuorums;
}

public ArrayList<FinalCommitment> getNewQuorums() {
public List<FinalCommitment> getNewQuorums() {
return newQuorums;
}

Expand Down

0 comments on commit 0d5c8ae

Please sign in to comment.