Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SUMMARY This project will involve the creation of a Blockchain miner that does all the following: Receives transactions from user or remote node. Sends transactions

SUMMARY

This project will involve the creation of a Blockchain miner that does all the following:

Receives transactions from user or remote node.

Sends transactions to a remote node.

Manages incoming remote node messages using a Queue.

Generates a Merkle Tree and an eventual Merkle Root as part of Transaction processing.

Creates Blockchain Blocks using Proof of Work algorithm.

For this project, you will create the main functionality inside of an existing code base called BlockchainBasics. The BlockchainBasics code that you will begin with is provided along with this document.

BlockchainBasics, once completed, will allow you to run two instances of this app on two different ports that pass transactions to each other and mine blocks.

This app doesnt save the blocks into a blockchain, but the central functionality you code into this app will be able to be plugged in directly into a larger Blockchain application (the code for this will be provided in the coming weeks) that fully manages a Blockchain, connects to multiple networked nodes, and allows you to trade items on the network.

However, you will only be turning in the BlockchainBasics code as specified at the end of this doc.

This project will involve the following:

- Socket programming

- Queue

- Multithreading

- Hashing: SHA-256

- Merkle Trees

- Blockchain Proof of Work

DETAILS

Download BlockchainBasics.zip

This includes the following classes:

BlockchainBasics.java

Miner.java

Block.java

MerkleNode.java

BlockchainUtil.java

P2PServer.java

P2PMessageQueue.java

P2PMessage.java

P2PUtil.java

You only add code where you see this:

### ADD CODE HERE ###

CLASSES where you add code:

Miner

doProofOfWork method: The logic behind this will be reviewed in class.This method should first create a string that has as many zeros in it as oBlock.getDifficulty() equals.

Hint: use a while loop here that keeps looping while the length of this string youre creating is less than the target difficulty length.

Then, this method should keep looping until a valid nonce is found.

The nonce starts at 0 and increments each loop.

A valid nonce, after its added to the blocks properties and the block is hashed, should result in a hash that has as many leading zeros as the string you created above (use Strings startsWith method for this check).

Block

computeMerkleRoot:

Choose which approach you want to take:

The 90% approach is much easier and is based on what weve done in class but your max score for the project can only reach 90%.

The 100% approach is much trickier, and you must figure out on your own.

90% Project Score Logic: This logic needs to account for possibly 2 or 4 items in lstItems that are passed in.

This means your code should have 2 or 4 Merkle Tree leaves depending on how many items are passed in.

100% Project Score Logic: You can only get 90% on this project if everything else is done perfectly. To get 100%, you must make this method flexible to accept any multiple of 2 items. So lstItems could be 2,4,8,16,32, etc. and your code would be able to compute the Merkle Root.

IMPORTANT: If you choose this route, youll have to show me your logic in class one week before the project is due.

NOTE: There is a main method at the bottom of this class that you can use to test 2 and 4 items simply by right clicking on the tab for this class and selecting Run Block.main()

populateMerkleNode:

This method will work just as we did in class set the left and right nodes and then call generateHash in the BlockchainUtil class and set the nodes hash.

BlockchainUtil

generateHash:

This method generates a SHA-256 hash of the string passed in.

Code for this was reviewed in class and doesnt need to be changed.

P2PMessageQueue

enqueue:

This adds a node to the queue.

Code will be reviewed in class.

dequeue:

This removes and returns a node from the queue.

Code will be reviewed in class.

hasNodes:

This returns true or false depending on if any nodes exist in queue.

Code will be reviewed in class.

P2PUtil

connectForOneMessage:

This method will connect to a given server via Socket for a one-time sending of a message to that server and it will return the reply from the server and disconnect.

Code for the Socket communication will be reviewed in class.

Testing Your CodeYou need to run two instances of this app so that they can communicate with each other.

One app can be run from your IDE like you normally do.

The other app must be ran from a PowerShell window or other command line tool as explained below.

Running a separate instance of your app:Jar file generation

You first need to build your code into a JAR file.

Instructions are included with the project online and will be reviewed in class.

Running your JAR fileNavigate to your JAR file in file explorer.Shortcut if using IntelliJ:Find it in your left side file explorer in your IntelliJ IDE:

out > artifacts > BlockchainBasics_jar > BlockchainBasics.jar

Right click on it and pic Show in Explorer.

Make sure that no file is highlighted by LEFT clicking in right space.

SHIFT + RIGHT click in white space as shown in class to get extra menu item of Open PowerShell Window here

In PowerShell or other command line tool, type the following to run:

java -jar BlockchainBasics.jar

Then make sure a different port is chosen for your IDE instance and your command line instance:

For instance, choose 8800 for one and 8888 or the other.

NOT PART OF PROJECT GRADING: Incorporating your code into larger in-class Griffin Blockchain app.

All of the code you added to this BlockchainBasics project can also now be added to the Griffin Blockchain app to make it functional and partake in full Blockchain networking with others in class.

Details will be provided in class, and this apps code will be made available later.

TURNING IN PROJECT:

IMPORTANT: DO NOT ZIP your files please. Turn in just the 5 .java files that you added code to. ALSO, include a runnable .jar file if your code is functional.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago