Coverage Summary for Class: ExportBlocks (co.rsk.cli.tools)
Class |
Class, %
|
Method, %
|
Line, %
|
ExportBlocks |
0%
(0/1)
|
0%
(0/3)
|
0%
(0/14)
|
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.ethereum.core.Block;
23 import org.ethereum.db.BlockStore;
24 import org.ethereum.util.ByteUtil;
25
26 import java.io.PrintStream;
27
28 /**
29 * The entry point for export blocks CLI tool
30 * This is an experimental/unsupported tool
31 */
32 public class ExportBlocks {
33 public static void main(String[] args) {
34 RskContext ctx = new RskContext(args);
35 BlockStore blockStore = ctx.getBlockStore();
36
37 execute(args, blockStore, System.out);
38 }
39
40 public static void execute(String[] args, BlockStore blockStore, PrintStream writer) {
41 long fromBlockNumber = Long.parseLong(args[0]);
42 long toBlockNumber = Long.parseLong(args[1]);
43
44 for (long n = fromBlockNumber; n <= toBlockNumber; n++) {
45 Block block = blockStore.getChainBlockByNumber(n);
46 BlockDifficulty totalDifficulty = blockStore.getTotalDifficultyForHash(block.getHash().getBytes());
47
48 writer.println(
49 block.getNumber() + "," +
50 ByteUtil.toHexString(block.getHash().getBytes()) + "," +
51 ByteUtil.toHexString(totalDifficulty.getBytes()) + "," +
52 ByteUtil.toHexString(block.getEncoded())
53 );
54 }
55 }
56 }