From 05ec0b01502e39d8141f27129d6005d0cb3fcd1b Mon Sep 17 00:00:00 2001 From: ajlopez Date: Tue, 28 Apr 2020 15:20:00 -0300 Subject: [PATCH] Removing old code --- .../main/java/co/rsk/BlocksFileExporter.java | 73 ---------------- .../main/java/co/rsk/BlocksFilePlayer.java | 85 ------------------- .../java/co/rsk/BlockstoreBlockPlayer.java | 81 ------------------ 3 files changed, 239 deletions(-) delete mode 100644 rskj-core/src/main/java/co/rsk/BlocksFileExporter.java delete mode 100644 rskj-core/src/main/java/co/rsk/BlocksFilePlayer.java delete mode 100644 rskj-core/src/main/java/co/rsk/BlockstoreBlockPlayer.java diff --git a/rskj-core/src/main/java/co/rsk/BlocksFileExporter.java b/rskj-core/src/main/java/co/rsk/BlocksFileExporter.java deleted file mode 100644 index c1777ac8655..00000000000 --- a/rskj-core/src/main/java/co/rsk/BlocksFileExporter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of RskJ - * Copyright (C) 2019 RSK Labs Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package co.rsk; - -import org.bouncycastle.util.encoders.Hex; -import org.ethereum.core.Block; -import org.ethereum.db.BlockStore; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Arrays; - -public class BlocksFileExporter { - private final BlockStore sourceBlockStore; - private final String filename; - - private long blockNumber; - - private BlocksFileExporter(String filename, RskContext objects) { - this.sourceBlockStore = objects.getBlockStore(); - this.filename = filename; - this.blockNumber = 1; // skip the genesis block - } - - private void exportBlocks() throws IOException { - try (FileWriter fileWriter = new FileWriter(filename); - BufferedWriter writer = new BufferedWriter(fileWriter)) { - for (Block block = nextBlock(); block != null; block = nextBlock()) { - writer.write(String.valueOf(block.getNumber())); - writer.write(","); - writer.write(Hex.toHexString(block.getEncoded())); - writer.newLine(); - } - - System.out.printf("Best block exported is %7d%n", blockNumber); - } - } - - private Block nextBlock() { - return sourceBlockStore.getChainBlockByNumber(blockNumber++); - } - - public static void main(String[] args) throws IOException { - if (args.length == 0) { - System.out.println("usage: FileBlockExporter [] "); - System.exit(0); - return; - } - - String[] nodeCliArgs = Arrays.copyOf(args, args.length - 1); - RskContext objects = new RskContext(nodeCliArgs); - BlocksFileExporter bplayer = new BlocksFileExporter(args[args.length - 1], objects); - bplayer.exportBlocks(); - System.exit(0); - } -} diff --git a/rskj-core/src/main/java/co/rsk/BlocksFilePlayer.java b/rskj-core/src/main/java/co/rsk/BlocksFilePlayer.java deleted file mode 100644 index 49039077947..00000000000 --- a/rskj-core/src/main/java/co/rsk/BlocksFilePlayer.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of RskJ - * Copyright (C) 2019 RSK Labs Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package co.rsk; - -import co.rsk.net.BlockProcessResult; -import org.bouncycastle.util.encoders.Hex; -import org.ethereum.core.Block; -import org.ethereum.core.BlockFactory; -import org.ethereum.core.Blockchain; -import org.ethereum.core.ImportResult; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.stream.Stream; - -public class BlocksFilePlayer { - private final Blockchain targetBlockchain; - private final BlockFactory blockFactory; - private final String filename; - - private BlocksFilePlayer(String filename, RskContext objects) { - this.targetBlockchain = objects.getBlockchain(); - this.blockFactory = objects.getBlockFactory(); - this.filename = filename; - } - - private void connectBlocks() throws IOException { - try (Stream lines = Files.lines(Paths.get(filename))) { - long blocksToSkip = targetBlockchain.getBestBlock().getNumber(); - lines.skip(blocksToSkip).map(this::readBlock).forEach(this::connectBlock); - - System.out.printf("Best block is now %7d%n", targetBlockchain.getBestBlock().getNumber()); - } - } - - private Block readBlock(String line) { - String[] parts = line.split(","); - return blockFactory.decodeBlock(Hex.decode(parts[parts.length - 1])); - } - - private void connectBlock(Block block) { - ImportResult tryToConnectResult = targetBlockchain.tryToConnect(block); - if (!BlockProcessResult.importOk(tryToConnectResult)) { - System.err.printf("Import failed at block %7d%n", block.getNumber()); - System.exit(1); - return; - } - - if (block.getNumber() % 100 == 0) { - System.out.printf("Imported block with number %7d%n", block.getNumber()); - } - } - - public static void main(String[] args) throws IOException { - if (args.length == 0) { - System.out.println("usage: FileBlockPlayer [] "); - System.exit(0); - return; - } - - String[] nodeCliArgs = Arrays.copyOf(args, args.length - 1); - RskContext objects = new RskContext(nodeCliArgs); - BlocksFilePlayer bplayer = new BlocksFilePlayer(args[args.length - 1], objects); - bplayer.connectBlocks(); - System.exit(0); - } -} diff --git a/rskj-core/src/main/java/co/rsk/BlockstoreBlockPlayer.java b/rskj-core/src/main/java/co/rsk/BlockstoreBlockPlayer.java deleted file mode 100644 index 12156966b81..00000000000 --- a/rskj-core/src/main/java/co/rsk/BlockstoreBlockPlayer.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of RskJ - * Copyright (C) 2019 RSK Labs Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package co.rsk; - -import co.rsk.net.BlockProcessResult; -import org.ethereum.core.Block; -import org.ethereum.core.Blockchain; -import org.ethereum.core.ImportResult; -import org.ethereum.db.BlockStore; - -import java.util.Arrays; - -public class BlockstoreBlockPlayer { - private final Blockchain targetBlockchain; - private final BlockStore blockStore; - - private long blockNumber; - - private BlockstoreBlockPlayer(BlockStore blockStore, Blockchain targetBlockchain) { - this.blockStore = blockStore; - this.targetBlockchain = targetBlockchain; - this.blockNumber = this.targetBlockchain.getBestBlock().getNumber() + 1; - } - - private void connectBlocks() { - for (Block block = nextBlock(blockStore); block != null; block = nextBlock(blockStore)) { - if (!connectBlock(block)) { - System.err.printf("Import failed at block %s\n", block.getNumber()); - System.exit(1); - return; - } - - if (block.getNumber() % 100 == 0) { - System.out.printf("Imported block with number %7d\n", block.getNumber()); - } - } - - System.out.printf("Best block is now %7d%n", targetBlockchain.getBestBlock().getNumber()); - } - - private boolean connectBlock(Block block) { - ImportResult tryToConnectResult = targetBlockchain.tryToConnect(block); - return BlockProcessResult.importOk(tryToConnectResult); - } - - private Block nextBlock(BlockStore sourceBlockStore) { - return sourceBlockStore.getChainBlockByNumber(blockNumber++); - } - - public static void main(String[] args) { - if (args.length == 0) { - System.out.println("usage: BlockstoreBlockPlayer [] "); - System.exit(0); - return; - } - - String[] nodeCliArgs = Arrays.copyOf(args, args.length - 1); - RskContext objects = new RskContext(nodeCliArgs); - BlockStore blockStore = objects.buildBlockStore(args[args.length - 1]); - Blockchain blockchain = objects.getBlockchain(); - BlockstoreBlockPlayer blockPlayer = new BlockstoreBlockPlayer(blockStore, blockchain); - blockPlayer.connectBlocks(); - System.exit(0); - } -}