From 3bbabbcc65e4e472294646ecc4aa69bcf99b28ae Mon Sep 17 00:00:00 2001 From: Ishita <95162790+ishita-kundi04@users.noreply.github.com> Date: Fri, 14 Oct 2022 22:45:15 +0530 Subject: [PATCH] adding some basics of block chain for beginner understanding, explained with code how block chain can be implemented in java using arrayList --- .../bin/ImplimentChain.class | Bin 0 -> 1219 bytes Block Chain Implimentation/bin/MyInfo.class | Bin 0 -> 914 bytes .../src/ImplimentChain.java | 28 ++++++++++++++++ Block Chain Implimentation/src/MyInfo.java | 30 ++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 Block Chain Implimentation/bin/ImplimentChain.class create mode 100644 Block Chain Implimentation/bin/MyInfo.class create mode 100644 Block Chain Implimentation/src/ImplimentChain.java create mode 100644 Block Chain Implimentation/src/MyInfo.java diff --git a/Block Chain Implimentation/bin/ImplimentChain.class b/Block Chain Implimentation/bin/ImplimentChain.class new file mode 100644 index 0000000000000000000000000000000000000000..82abc29bff4a32cc936024babe994c54dd2d96c6 GIT binary patch literal 1219 zcmZuwYflqF6g@*1wk-=St$={a;saY=g$k$?Q9zMuL1Iah2ER<}(hjz}WOr)9&(cIl zB>DsV;7>B%*)3?3e%RTWbI;s+?qh!a`Ti3?4sUhzFbw9Krw!4xY`Iv8s|GT4^}dPgO->7%upPmK2T5rt9*vg79RHAyO1Io6DAKF-&&jtQYpq z^7gTl+aPw|y0C@ZU#>$u4oC7{ovX3<(3h=wpZ#gl+A& znib1E@e;yjJ@Y4Tn6@IVVf)0W*sI~AgD$Zlenvr zzQ-_{%6C-}#sh|t&A`>twHs49=2jRFsV7^3ZRJXUGHol@X#+EuWiV=%+)`cK9+6<>&2)~+Ex|GVNOJUHw#IHgIp|XCg7X~&J zt=D%+bne!u-N`Q1B(yE|(B-zrt5P^Nar@h-nox%D)vPiM`NN<6k4?P`FnSq9r{z|y z9ib*K**RPbYJM?A!y2L|$LOPprN2(Q9)#(mM}sJ>{e)~0OL5{e7cgcnF<8Dp{2PY8 z`0OODgT5aP8U_%f^#)-^a0kN}p;H8-xY_pin;5->edzsxv2rLeQ7mhT+r`2qCd;AO z3ry{`4fmB{y11_lbLU9SlWk4=in&Dg9Lw}q;5pV5@+?5cG#`5YPun!bCheqa2xCYh zMe0^b(*`NpB~1r}9%0>j-N3&I%|)&Kwi literal 0 HcmV?d00001 diff --git a/Block Chain Implimentation/bin/MyInfo.class b/Block Chain Implimentation/bin/MyInfo.class new file mode 100644 index 0000000000000000000000000000000000000000..91b56929602376c0d75f00b840c20e93690732ac GIT binary patch literal 914 zcmZuve{0iF6g{s=n>Kx}wRNkm{@C2qB(}>3s0b>Efw~DDh2dYXF>5npB57LKNASD& zhl0f+=m+paiT5SdWu*ji-@Cc@oO933?>|3&0qDWjP+%y%K6k>?NQ25yKNE9d2O=EX zN24>(O&Ivc*qi&&Z2C$}Ck)J?R1%ADD%`}6!YM=ZZU3@uki>pC?lDxJ2a)?eYbrhQ zLqB=S&@!Ag#paMfeG$F$bST*1&{1Ph40Bik!*z}#O7hg?&`{Q~iI#?~e`05eAK1_0 zSe#EeZsHb0c|uAh9K)88r^`m_nU0P&?r6A8=$Fc!F!9D-%yAd@7__+vX5P`M#Bj{q zfXlL;RJ6-cL5ZQ(_e1Y+_F?43$6^!^aibr(A{dI;m-l5-O(s71RqkhwlSySaBGxcj zb#bYbkjGx~=E?%d7g~YLA79zRreWr1{l5oJmAO^ugJ>4J-b-JqtY$(EqzTxiffV{L z6cnW6bSg-{(@0ZNRH;HomEN3gpXjbq>{{P(&1x@Dw>k?nia(*8D4h%3xWM+{L~YA( zXmu&Ez|Pkc?moS@Q%Id4s$?R^20ih?X}I_ Hl;Yqo@xiAt literal 0 HcmV?d00001 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; + } + +}