Skip to content

Instantly share code, notes, and snippets.

@cyberpirate92
Created May 14, 2019 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberpirate92/46d3c208b7fef79b8cb229b4f5cba5a9 to your computer and use it in GitHub Desktop.
Save cyberpirate92/46d3c208b7fef79b8cb229b4f5cba5a9 to your computer and use it in GitHub Desktop.
public static void main(String[] args) {
try {
var blockChain = new BlockChain();
Block block1 = new Block("Hello");
Block block2 = new Block("World");
Block block3 = new Block("Whatever");
blockChain.addBlock(block1);
blockChain.addBlock(block2);
blockChain.addBlock(block3);
for (Block block: blockChain.chain) {
System.out.println(block);
}
System.out.println("Is valid chain : " + blockChain.isValid());
// modify second block's data..
blockChain.chain.get(1).transactionData = "World1";
System.out.println("Is valid chain : " + blockChain.isValid()); // will be false
}
catch(Exception e) {
System.err.println(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment