Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nullptr exception #37

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static BlockTree readObject(ObjectReader r) {
List<Item> items = new ArrayList<>();
items.add(new Item(nleaves, root));

while(items.size() > 0) {
while(!items.isEmpty()) {
Item item = items.remove(0);
Hash id = item.id;
List<Hash> children = new ArrayList<>();
Expand All @@ -79,12 +79,12 @@ public static void writeObject(ObjectWriter w, BlockTree o) {
List<Hash> children = new ArrayList<>();
children.add(o.root);
w.beginList(o.nodes.size());
while (children.size() > 0) {
while (!children.isEmpty()) {
Hash node = children.remove(0);
List<Hash> tmp = o.nodes.get(node);
w.write(tmp.size());
w.write(node);
if (tmp.size() > 0) {
if (!tmp.isEmpty()) {
children.addAll(tmp);
}
}
Expand Down Expand Up @@ -155,9 +155,13 @@ public interface OnRemoveListener {
}

public void prune(Hash until, OnRemoveListener lst) {
if (until.equals(root)) {
return;
}

List<Hash> removals = new ArrayList<>();
removals.add(root);
while (removals.size() > 0) {
while (!removals.isEmpty()) {
List<Hash> buf = new ArrayList<>();
for (Hash removal : removals) {
List<Hash> leaves = nodes.get(removal);
Expand All @@ -178,7 +182,7 @@ public void prune(Hash until, OnRemoveListener lst) {

@Override
public String toString() {
return "BlockTrie{" +
return "BlockTree{" +
"root=" + root +
", nodes=" + nodes +
'}';
Expand Down
50 changes: 40 additions & 10 deletions bmv/bsc2/src/test/resources/testnet.json

Large diffs are not rendered by default.