Coverage Summary for Class: StatusResolver (co.rsk.net)
Class |
Class, %
|
Method, %
|
Line, %
|
StatusResolver |
0%
(0/1)
|
0%
(0/2)
|
0%
(0/16)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2019 RSK Labs Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package co.rsk.net;
20
21 import co.rsk.core.BlockDifficulty;
22 import org.ethereum.core.Block;
23 import org.ethereum.core.Genesis;
24 import org.ethereum.db.BlockStore;
25
26 public class StatusResolver {
27
28 private final BlockStore blockStore;
29 private final Genesis genesis;
30
31 public StatusResolver(BlockStore blockStore, Genesis genesis) {
32
33 this.blockStore = blockStore;
34 this.genesis = genesis;
35 }
36
37
38 /**
39 * Resolves the current status to broadcast and send to peers.
40 */
41 public Status currentStatus() {
42 Status status;
43 if (blockStore.getMinNumber() != 0) {
44 status = new Status(
45 genesis.getNumber(),
46 genesis.getHash().getBytes(),
47 genesis.getParentHash().getBytes(),
48 genesis.getCumulativeDifficulty());
49 } else {
50 Block block = blockStore.getBestBlock();
51 BlockDifficulty totalDifficulty = blockStore.getTotalDifficultyForHash(block.getHash().getBytes());
52
53 status = new Status(block.getNumber(),
54 block.getHash().getBytes(),
55 block.getParentHash().getBytes(),
56 totalDifficulty);
57 }
58 return status;
59 }
60 }