-
Notifications
You must be signed in to change notification settings - Fork 6
Part five #9
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
base: master
Are you sure you want to change the base?
Part five #9
Conversation
# Conflicts: # src/blockchain/Block.java # src/blockchain/Blockchain.java # src/blockchain/Main.java # src/blockchain/miners/Miner.java
swsms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good abstraction
| readLock.lock(); | ||
| return Stream.iterate("0", x -> "0") | ||
| .limit(prefixLength) | ||
| .reduce("", (x, y) -> x + y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| do { | ||
| prefix = blockchain.getPrefix(); | ||
| magicNumber = random.nextInt(); | ||
| hash = StringUtil.applySha256(previousHash + magicNumber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why "Message" is not a part of hash?
No description provided.