Open
Conversation
# Conflicts: # src/blockchain/Block.java # src/blockchain/Blockchain.java # src/blockchain/Main.java # src/blockchain/miners/Miner.java
swsms
reviewed
Jan 9, 2019
swsms
left a comment
There was a problem hiding this comment.
A good implementation with a large number of Java features. You can also try using var from newer versions of the language.
| private List<T> data = List.of(); | ||
|
|
||
|
|
||
| public Block(Integer id, Long minerId, String hashPreviousBlock, String hash, |
There was a problem hiding this comment.
Personally, I don’t really like constructors with a lot of arguments (3-4+) of the same (String, String) or almost the same types (Integer, Long). But you use builder below which can be added inside this class to hide the constructor.
| import java.io.Serializable; | ||
| import java.util.List; | ||
|
|
||
| public class Block<T extends SignedData & Serializable> implements Serializable { |
| readLock.lock(); | ||
| return Stream.iterate("0", x -> "0") | ||
| .limit(prefixLength) | ||
| .reduce("", (x, y) -> x + y); |
There was a problem hiding this comment.
There is a reduce-like function joining for strings. You may try to use it.
| Block<T> prev = blocks.get(i - 1); | ||
| Block<T> cur = blocks.get(i); | ||
| Stream<T> concatData = Stream.concat( | ||
| Objects.requireNonNullElse(prev.getData(), new ArrayList<T>()).stream(), |
Nexgen90
reviewed
Feb 4, 2021
| do { | ||
| prefix = blockchain.getPrefix(); | ||
| magicNumber = random.nextInt(); | ||
| hash = StringUtil.applySha256(previousHash + magicNumber); |
There was a problem hiding this comment.
I don't understand why "Message" is not a part of hash?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.