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;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Implementation of the blockchain.
......@@ -45,11 +46,12 @@ public class Blockchain {
* @param transactionsToBeIncluded the transactions the be included in the 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());
Block block = new Block(getIndexOfLastBlock() + 1, Instant
.now()
.toEpochMilli(), transactionsToBeIncluded, this.proofOfWork(), previousHash);
.toEpochMilli(), transactionsToBeMined, this.proofOfWork(), previousHash);
chain.add(block);
return block;
}
......
......@@ -109,9 +109,9 @@ public class BlockchainService {
}
//reward the miner
String signature = signatureService.sign("0" + miningWalletId + CRAFTSCOIN_MINING_REWARD);
Transaction transaction = new Transaction("0", miningWalletId, CRAFTSCOIN_MINING_REWARD, signature, signatureService.getPublicKey());
transactionPool.addTransaction(transaction);
Block newBlock = this.blockchain.mineNewBlock(transactionPool.getAllTransactions());
Transaction reward = new Transaction("0", miningWalletId, CRAFTSCOIN_MINING_REWARD, signature, signatureService.getPublicKey());
transactionPool.addTransaction(reward);
Block newBlock = this.blockchain.mineNewBlock(transactionPool.getAllTransactions(), reward);
genericRepository.save(this.blockchain);
transactionPool.clearTransactions();
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