-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
68 lines (59 loc) · 2.05 KB
/
Block.java
File metadata and controls
68 lines (59 loc) · 2.05 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package blockchain;
import java.io.Serializable;
import java.util.Date;
class Block implements Serializable {
private static final long serialVersionUID = 3L;
private final String PREVIOUS_HASH;
private final String CURRENT_HASH;
private final long ID;
private final long TIME_STAMP;
private final long TIME_TO_CREATE_HASH;
private final long MAGIC_NUMBER;
private final long MINER_ID;
private final String MESSAGE;
private final String BlockData;
public Block(String PREVIOUS_HASH, String hash, String message, int ID,
long minerId, long magicNumber, long timeToCreate, String mess) {
this.BlockData = mess;
this.TIME_TO_CREATE_HASH = timeToCreate;
this.MAGIC_NUMBER = magicNumber;
this.CURRENT_HASH = hash;
this.MESSAGE = message;
this.MINER_ID = minerId;
this.PREVIOUS_HASH = PREVIOUS_HASH;
this.ID = ID;
this.TIME_STAMP = new Date().getTime();
}
public long getTIME_TO_CREATE_HASH() {
return this.TIME_TO_CREATE_HASH;
}
public String toString() {
return String.format("Block:%n" +
"Created by minter # %d%n" +
"Id: %d%n" +
"Timestamp: %d%n" +
"Magic number: %d%n" +
"Hash of the previous block:%n" +
"%s%n" +
"Hash of the block:%n" +
"%s%n" +
"%s" +
"Block was generating for %d seconds%n" +
"%s",
this.MINER_ID,
this.ID,
this.TIME_STAMP,
this.MAGIC_NUMBER,
this.PREVIOUS_HASH,
this.CURRENT_HASH,
this.BlockData,
this.TIME_TO_CREATE_HASH,
this.MESSAGE);
}
public String getCurrentHash() {
return this.CURRENT_HASH;
}
public String getPreviousHash() {
return this.PREVIOUS_HASH;
}
}