Coverage Summary for Class: ImportBlocks (co.rsk.cli.tools)
Class |
Class, %
|
Method, %
|
Line, %
|
ImportBlocks |
0%
(0/1)
|
0%
(0/3)
|
0%
(0/17)
|
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 package co.rsk.cli.tools;
19
20 import co.rsk.RskContext;
21 import co.rsk.core.BlockDifficulty;
22 import org.bouncycastle.util.encoders.Hex;
23 import org.ethereum.core.Block;
24 import org.ethereum.core.BlockFactory;
25 import org.ethereum.db.BlockStore;
26
27 import java.io.BufferedReader;
28 import java.io.FileReader;
29 import java.io.IOException;
30 import java.math.BigInteger;
31
32 /**
33 * The entry point for import blocks CLI tool
34 * This is an experimental/unsupported tool
35 */
36 public class ImportBlocks {
37 public static void main(String[] args) throws IOException {
38 RskContext ctx = new RskContext(args);
39 BlockFactory blockFactory = ctx.getBlockFactory();
40 BlockStore blockStore = ctx.getBlockStore();
41
42 String filename = args[0];
43
44 try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
45 execute(blockFactory, blockStore, reader);
46 }
47 }
48
49 public static void execute(BlockFactory blockFactory, BlockStore blockStore, BufferedReader reader) throws IOException {
50 for (String line = reader.readLine(); line != null; line = reader.readLine()) {
51 String[] parts = line.split(",");
52
53 if (parts.length < 4) {
54 continue;
55 }
56
57 byte[] encoded = Hex.decode(parts[3]);
58
59 Block block = blockFactory.decodeBlock(encoded);
60
61 BlockDifficulty totalDifficulty = new BlockDifficulty(new BigInteger(Hex.decode(parts[2])));
62
63 blockStore.saveBlock(block, totalDifficulty, true);
64 }
65
66 blockStore.flush();
67 }
68 }