Added multithreading

This commit is contained in:
2021-07-12 16:06:02 +02:00
parent 80592cae2b
commit 3856ff7e48
4 changed files with 37 additions and 7 deletions

View File

@@ -13,10 +13,10 @@ public class BlockChain {
this.hashZeroes = hashZeroes;
}
public void addBlock() {
public synchronized void addBlock(final int minerId) {
final int nextId = blockList.size();
final String previousBlockHash = (nextId > 0) ? blockList.get(nextId - 1).getBlockHash() : "0";
blockList.add(new Block(previousBlockHash, nextId, hashZeroes));
blockList.add(new Block(previousBlockHash, minerId, nextId, hashZeroes));
}
public boolean validateBlockchain() {
@@ -51,4 +51,4 @@ public class BlockChain {
public void save() {
FileManagement.saveBlockchain(blockList);
}
}
}