-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompliantMiner.java
More file actions
51 lines (39 loc) · 1.21 KB
/
CompliantMiner.java
File metadata and controls
51 lines (39 loc) · 1.21 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
package edu.nyu.crypto.csci3033.miners;
import edu.nyu.crypto.csci3033.blockchain.Block;
import edu.nyu.crypto.csci3033.blockchain.NetworkStatistics;
public class CompliantMiner extends BaseMiner implements Miner {
private Block currentHead;
public CompliantMiner(String id, int hashRate, int connectivity) {
super(id, hashRate, connectivity);
}
@Override
public Block currentlyMiningAt() {
return currentHead;
}
@Override
public Block currentHead() {
return currentHead;
}
@Override
public void blockMined(Block block, boolean isMinerMe) {
if(isMinerMe) {
if (block.getHeight() > currentHead.getHeight()) {
this.currentHead = block;
}
}
else{
if (currentHead == null) {
currentHead = block;
} else if (block != null && block.getHeight() > currentHead.getHeight()) {
this.currentHead = block;
}
}
}
@Override
public void initialize(Block genesis, NetworkStatistics networkStatistics) {
this.currentHead = genesis;
}
@Override
public void networkUpdate(NetworkStatistics statistics) {
}
}