|
|
@ -12,19 +12,11 @@ public class Block { |
|
|
|
String ownHash; |
|
|
|
String previousHash; |
|
|
|
|
|
|
|
public Block(int data, Block vorher, String previousHash, int konto) { |
|
|
|
this.data = data; |
|
|
|
ownHash = createNewHash(); |
|
|
|
|
|
|
|
kontostand = konto + this.data; |
|
|
|
|
|
|
|
this.vorher = vorher; |
|
|
|
this.previousHash = previousHash; |
|
|
|
} |
|
|
|
|
|
|
|
//erste Block |
|
|
|
public Block(int data) { |
|
|
|
this.data = data; |
|
|
|
ownHash = createNewHash(); |
|
|
|
ownHash = createNewHash(Integer.toString(data)); |
|
|
|
|
|
|
|
kontostand = this.data; |
|
|
|
|
|
|
@ -32,8 +24,33 @@ public class Block { |
|
|
|
this.previousHash = null; |
|
|
|
} |
|
|
|
|
|
|
|
private String createNewHash() { |
|
|
|
return null; |
|
|
|
//Alle anderen Blöcke |
|
|
|
public Block(int data, Block vorher, String previousHash, int konto) { |
|
|
|
this.data = data; |
|
|
|
ownHash = createNewHash(Integer.toString(data)+previousHash); |
|
|
|
|
|
|
|
kontostand = konto + this.data; |
|
|
|
|
|
|
|
this.vorher = vorher; |
|
|
|
this.previousHash = previousHash; |
|
|
|
} |
|
|
|
|
|
|
|
private String createNewHash(String input) { |
|
|
|
try { |
|
|
|
MessageDigest digest = MessageDigest.getInstance("SHA-256"); |
|
|
|
//Applies sha256 to our input, |
|
|
|
byte[] hash = digest.digest(input.getBytes("UTF-8")); |
|
|
|
StringBuffer hexString = new StringBuffer(); // This will contain hash as hexidecimal |
|
|
|
for (int i = 0; i < hash.length; i++) { |
|
|
|
String hex = Integer.toHexString(0xff & hash[i]); |
|
|
|
if(hex.length() == 1) hexString.append('0'); |
|
|
|
hexString.append(hex); |
|
|
|
} |
|
|
|
return hexString.toString(); |
|
|
|
} |
|
|
|
catch(Exception e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public int getKontostand() { |
|
|
|