-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.java
33 lines (25 loc) · 964 Bytes
/
Block.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.lang.*;
import java.util.*;
/**
* Block class
*/
public class Block {
private int previousHash; //previous block's hash
private String[] transactions; //array of transactions
private int blockHash; //current block's hash
public Block(int previousHash, String[] transactions) {
this.previousHash = previousHash;
this.transactions = transactions;
Object[] contents = {Arrays.hashCode(transactions), previousHash}; //calculate the hash of transactions and the previous block's hash
this.blockHash = Arrays.hashCode(contents); //this block's hash by calculating the hash of both transactions and previous block's hash
}
public int getPreviousHash() {
return previousHash;
}
public String[] getTransaction() {
return transactions;
}
public int getBlockHash() {
return blockHash;
}
}