Wednesday, July 25, 2018

Simple block chain code with Java

A blockchain is the structure of data that represents a financial ledger entry, or a record of a transaction. Block chain contains list of blocks, each block will contain transaction and a hashcode of previous block. similarly next block will contain its transaction and hashcode of current block thus if any of the transaction value gets change in blockchain subsequent blocks hashcode will change.



If you dont know about hashcode, The hashcode of a Java Object is simply a number, it is 32-bit signed int, that allows an object to be managed by a hash-based data structure.

Transaction.java - It contains transaction information


Block.java - This is a block of our block chain. It will contain transaction and hashcode of previous block. Please note, it also contains current hashcode will be generated based on transaction in this block and hashcode of previous block


BlockChain.java - It contains list of blocks. If value in any of the block gets changed then hashcode all the subsequent block will get changed. Consider this block chain as a ledger which is published to all users hence no one can modify the block on his own. If he does so then all the transactions will be invalidated

No comments:

Post a Comment