Coverage Summary for Class: BlockHeaderValidatorImpl (co.rsk.core.bc)
Class |
Class, %
|
Method, %
|
Line, %
|
BlockHeaderValidatorImpl |
0%
(0/1)
|
0%
(0/2)
|
0%
(0/6)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 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.core.bc;
20
21 import co.rsk.validators.BlockHeaderValidationRule;
22 import co.rsk.validators.BlockValidator;
23 import org.ethereum.core.Block;
24 import org.ethereum.core.BlockHeader;
25
26 import javax.annotation.Nonnull;
27
28 /**
29 * Validates a block header if it is good enough to be propagated.
30 *
31 * The validation includes:
32 * - validation of the header data of the block
33 */
34 public class BlockHeaderValidatorImpl implements BlockValidator {
35
36 private final BlockHeaderValidationRule blockHeaderValidator;
37
38 public BlockHeaderValidatorImpl(@Nonnull BlockHeaderValidationRule blockHeaderValidator) {
39 this.blockHeaderValidator = blockHeaderValidator;
40 }
41
42 /**
43 * Checks if a block header is valid.
44 *
45 * @param block Block to validate
46 * @return true if the block is valid, otherwise - false.
47 */
48 @Override
49 public boolean isValid(@Nonnull Block block) {
50 if (block.isGenesis()) {
51 return false;
52 }
53
54 BlockHeader header = block.getHeader();
55 return blockHeaderValidator.isValid(header);
56 }
57 }