diff --git a/Block Chain Implimentation/bin/ImplimentChain.class b/Block Chain Implimentation/bin/ImplimentChain.class new file mode 100644 index 00000000..82abc29b Binary files /dev/null and b/Block Chain Implimentation/bin/ImplimentChain.class differ diff --git a/Block Chain Implimentation/bin/MyInfo.class b/Block Chain Implimentation/bin/MyInfo.class new file mode 100644 index 00000000..91b56929 Binary files /dev/null and b/Block Chain Implimentation/bin/MyInfo.class differ diff --git a/Block Chain Implimentation/src/ImplimentChain.java b/Block Chain Implimentation/src/ImplimentChain.java new file mode 100644 index 00000000..ea7ac253 --- /dev/null +++ b/Block Chain Implimentation/src/ImplimentChain.java @@ -0,0 +1,28 @@ +import java.util.ArrayList; +import java.util.Arrays; + +public class ImplimentChain { + /** + Hash = digital signature + Each Block will have :- + List of transactions + Previous Hash + Hash + */ + + ArrayList blockchain = new ArrayList<>(); + + public static void main(String[] args) { + String[] genesisTransactions = {"Ishita sent nini 20 bitcoin","Rajat sent fin 50 bitcoin"}; + MyInfo genesisInfo = new MyInfo(0, genesisTransactions); + + String[] block2Transaction = {"A sent 10 bitcoin to B", "B sent 5 bitcoin to C"}; + MyInfo block2 = new MyInfo(genesisInfo.getBlockHash(), block2Transaction); + + System.out.println("Hash of genesis Block :"); + System.out.println(genesisInfo.getBlockHash()); + System.out.println("Hash of Block 2:"); + System.out.print(block2.getBlockHash()); + } + +} diff --git a/Block Chain Implimentation/src/MyInfo.java b/Block Chain Implimentation/src/MyInfo.java new file mode 100644 index 00000000..958a44f9 --- /dev/null +++ b/Block Chain Implimentation/src/MyInfo.java @@ -0,0 +1,30 @@ +import java.util.Arrays; + +public class MyInfo { + + private int previousHash; + private String[] transactions; + + private int BlockHash; + + public MyInfo(int previousHash, String[] transactions) { + this.previousHash = previousHash; + this.transactions = transactions; + + Object[] contents = {Arrays.hashCode(transactions), previousHash }; + this.BlockHash = Arrays.hashCode(contents); + } + + public int getPreviousHash() { + return previousHash; + } + + public String[] getTransactions() { + return transactions; + } + + public int getBlockHash() { + return BlockHash; + } + +}