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