Skip to content

Commit a74f758

Browse files
committed
Modularizing further fron-end code, prettyfying sass & pug, added new user_1 image, exhcanged node_module Bootstrap4.5 to a CDN link
1 parent a4facd1 commit a74f758

21 files changed

+246
-11042
lines changed

package-lock.json

+1-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/blockmatrix/blockchain/Block.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
/**
1010
* Class Model for "Block(s)"
11-
* holds the modal structure for a block in the "blockmatrix"
12-
11+
* holds the modal structure for a block in
12+
* the "blockmatrix"
1313
*/
1414

1515
public class Block {
@@ -25,6 +25,7 @@ public class Block {
2525
private long timeStamp; // number of milliseconds since 1/1/1970
2626
private int nonce; // first number a blockchain miner needs to discover before solving for a block in the blockchain
2727
private boolean genesis; // whether or not this block is genesis block, by default it is 'FALSE'
28+
private static int difficulty = 5; // blockchain mining difficulty (more higher = more difficult)
2829

2930
// __________________
3031
// Class Constructors
@@ -49,8 +50,15 @@ public String calculate_Block_Hash() {
4950
}
5051

5152
public void mine_Block() {
52-
merkleRoot = StringUtil.getMerkleRoot(transactions);
53-
hash = calculate_Block_Hash();
53+
String target = new String(new char[difficulty]).replace('\0', '0'); // Create a string with difficulty * "0"
54+
55+
merkleRoot = StringUtil.getMerkleRoot(transactions); // Get the MerkleRoot (Block Hash)
56+
57+
while(!hash.substring(0, difficulty).equals(target)) { // Infinite while loop until the hash is found
58+
nonce++;
59+
hash = calculate_Block_Hash();
60+
}
61+
5462
System.out.println("Block Mined: " + hash);
5563
}
5664

src/main/java/blockmatrix/blockchain/BlockMatrix.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public void setUpSecurity() {
142142
}
143143

144144
public Boolean is_Matrix_Valid() {
145+
145146
// sees if our matrix has maintained its security, or if it has been tampered with
146147
Block currentBlock; // ..
147148
HashMap<String, Transaction_Output> tempUTXOs = new HashMap<>(); // a temporary working list of unspent transactions at a given block state.
@@ -160,7 +161,7 @@ public Boolean is_Matrix_Valid() {
160161
return false;
161162
}
162163

163-
// check if hash is solved
164+
// check if hash is solved (mined)
164165
// if(!currentBlock.getHash().substring(0, difficulty).equals(hashTarget)) {
165166
// System.out.println("Block " + i + " hasn't been mined (first instance of unmined block, there may be more)");
166167
// return false;
@@ -169,7 +170,7 @@ public Boolean is_Matrix_Valid() {
169170
// loop through blockchain transactions
170171
Transaction_Output tempOutput;
171172

172-
for(int t=0; t <currentBlock.getTransactions().size(); t++) {
173+
for(int t=0; t < currentBlock.getTransactions().size(); t++) {
173174
Transaction currentTransaction = currentBlock.getTransactions().get(t);
174175

175176
if(!currentTransaction.verify_Transaction_Signature()) {

src/main/java/blockmatrix/blockchain/MatrixChain_Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void main(String[] args) {
5555

5656
bm.add_Block(block2); // Add our block with transactions to the BlockMatrix
5757

58-
bm.clear_Info_In_Transaction(2, 1); // Clear Transaction Info. passed along in the BlockNumber: 2 & Transaction Number: 1
58+
// bm.clear_Info_In_Transaction(2, 1); // Clear Transaction Info. passed along in the BlockNumber: 2 & Transaction Number: 1
5959

6060
block2.print_Block_Transactions(); //..
6161

src/main/java/blockmatrix/blockchain/Wallet.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import java.util.HashMap;
77
import java.util.Map;
88

9+
/**
10+
* Class Model for "Wallet"
11+
* holds the modal structure for a wallet on
12+
* on the blockmatrix;
13+
*/
14+
915
public class Wallet {
1016

1117
// __________________
@@ -14,7 +20,7 @@ public class Wallet {
1420
private PrivateKey privateKey; // 'this' wallet private Key
1521
private PublicKey publicKey; // 'this' wallet public Key
1622
private HashMap<String, Transaction_Output> UTXOs = new HashMap<>(); // only UTXOs owned by this wallet.
17-
private ArrayList<Transaction> transaction_list = new ArrayList<>(); // only transactions made by this wallet.
23+
private ArrayList<Transaction> transaction_list = new ArrayList<>(); // only transactions made by this wallet.
1824

1925
// __________________
2026
// Class Constructors

src/main/java/blockmatrix/controllers/Node_Controller.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import blockmatrix.blockchain.BlockMatrix;
1818

1919
@Controller
20+
@RequestMapping("/node")
2021
public class Node_Controller {
2122

2223
// __________________
@@ -26,7 +27,7 @@ public class Node_Controller {
2627
private BlockMatrix new_blockMatrix;
2728

2829
/**
29-
* Registerin the nodes onto the network
30+
* Registering the nodes onto the network
3031
*/
3132

3233
@RequestMapping(value = "/register", method = RequestMethod.POST)

src/main/java/blockmatrix/controllers/Wallet_Controller.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import blockmatrix.blockchain.BlockMatrix;
44
import blockmatrix.blockchain.StringUtil;
55
import blockmatrix.blockchain.Wallet;
6+
67
import org.springframework.beans.factory.annotation.Autowired;
78
import org.springframework.beans.factory.annotation.Value;
89
import org.springframework.stereotype.Controller;
@@ -35,7 +36,7 @@ public class Wallet_Controller {
3536

3637
/**
3738
* _________________
38-
* Blockchain Data (Explorer)
39+
* Blockchain Data (Explorer) @GetMapping
3940
*
4041
* Returns ->
4142
*
@@ -64,7 +65,7 @@ public String block_explorer(Model model) {
6465

6566
/**
6667
* __________________
67-
* User Dashboard (UI/UX)
68+
* User Dashboard (UI/UX) @GetMapping
6869
*
6970
* Returns ->
7071
*
-2.14 MB
Loading

0 commit comments

Comments
 (0)