Skip to content

Commit

Permalink
Implementing blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksilva1 committed Dec 4, 2022
1 parent e7da180 commit 91d802f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
41 changes: 36 additions & 5 deletions src/App.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
public static void main(String[] args) {

for (Integer i = 0; i < 100; i++) {
System.out.println(SHA256Helper.generateHash(i.toString()));
}
BlockChain blockChain = new BlockChain();

Miner miner = new Miner();

// Genesis Block
Block block0 = new Block(0, "", Constants.GENESIS_PREV_HASH);
miner.mine(block0, blockChain);

// First Block
Block block1 = new Block(1, "Transaction1", blockChain.getBlockChain().get(blockChain.getSize() - 1).getHash());

miner.mine(block1, blockChain);

// Second Block
Block block2 = new Block(2, "Transaction2", blockChain.getBlockChain().get(blockChain.getSize() - 1).getHash());

miner.mine(block2, blockChain);

// Third Block
Block block3 = new Block(3, "Transaction3", blockChain.getBlockChain().get(blockChain.getSize() - 1).getHash());

miner.mine(block3, blockChain);

// Fourth Block
Block block4 = new Block(4, "Transaction4", blockChain.getBlockChain().get(blockChain.getSize() - 1).getHash());

miner.mine(block4, blockChain);

// Fifth Block
Block block5 = new Block(5, "Transaction5", blockChain.getBlockChain().get(blockChain.getSize() - 1).getHash());

miner.mine(block5, blockChain);

System.out.println("\n" + "Blockchain: \n" + blockChain);
System.out.println("Miner's reward: " + miner.getReward());
}
}
2 changes: 1 addition & 1 deletion src/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ private Constants() {
}

// Difficulty of leading zeros
public static final int DIFFICULTY = 1;
public static final int DIFFICULTY = 6;

// This is the reward in the underlying Cryptocurrency
public static final int REWARD = 10;
Expand Down

0 comments on commit 91d802f

Please sign in to comment.