Commit c217628b authored by Michel Schudel's avatar Michel Schudel

opdracht verder in het Engels geschreven

parent 343768c6
This diff is collapsed.
...@@ -9,6 +9,7 @@ import org.apache.commons.codec.digest.DigestUtils; ...@@ -9,6 +9,7 @@ import org.apache.commons.codec.digest.DigestUtils;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* Implementation of the blockchain. * Implementation of the blockchain.
...@@ -45,11 +46,12 @@ public class Blockchain { ...@@ -45,11 +46,12 @@ public class Blockchain {
* @param transactionsToBeIncluded the transactions the be included in the block. * @param transactionsToBeIncluded the transactions the be included in the block.
* @return the new block. * @return the new block.
*/ */
Block mineNewBlock(Set<Transaction> transactionsToBeIncluded) { Block mineNewBlock(Set<Transaction> transactionsToBeIncluded, Transaction reward) {
Set<Transaction> transactionsToBeMined = Stream.concat(transactionsToBeIncluded.stream(),Stream.of(reward)).collect(Collectors.toSet());
String previousHash = createHashOf(this.getLastBlock()); String previousHash = createHashOf(this.getLastBlock());
Block block = new Block(getIndexOfLastBlock() + 1, Instant Block block = new Block(getIndexOfLastBlock() + 1, Instant
.now() .now()
.toEpochMilli(), transactionsToBeIncluded, this.proofOfWork(), previousHash); .toEpochMilli(), transactionsToBeMined, this.proofOfWork(), previousHash);
chain.add(block); chain.add(block);
return block; return block;
} }
......
...@@ -109,9 +109,9 @@ public class BlockchainService { ...@@ -109,9 +109,9 @@ public class BlockchainService {
} }
//reward the miner //reward the miner
String signature = signatureService.sign("0" + miningWalletId + CRAFTSCOIN_MINING_REWARD); String signature = signatureService.sign("0" + miningWalletId + CRAFTSCOIN_MINING_REWARD);
Transaction transaction = new Transaction("0", miningWalletId, CRAFTSCOIN_MINING_REWARD, signature, signatureService.getPublicKey()); Transaction reward = new Transaction("0", miningWalletId, CRAFTSCOIN_MINING_REWARD, signature, signatureService.getPublicKey());
transactionPool.addTransaction(transaction); transactionPool.addTransaction(reward);
Block newBlock = this.blockchain.mineNewBlock(transactionPool.getAllTransactions()); Block newBlock = this.blockchain.mineNewBlock(transactionPool.getAllTransactions(), reward);
genericRepository.save(this.blockchain); genericRepository.save(this.blockchain);
transactionPool.clearTransactions(); transactionPool.clearTransactions();
network.notifyPeersOfNewBlock(newBlock, null); network.notifyPeersOfNewBlock(newBlock, null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment