Coverage Summary for Class: ImportState (co.rsk.cli.tools)

Class Class, % Method, % Line, %
ImportState 0% (0/1) 0% (0/3) 0% (0/15)


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.crypto.Keccak256; 22 import org.bouncycastle.util.encoders.Hex; 23 import org.ethereum.crypto.Keccak256Helper; 24 import org.ethereum.datasource.KeyValueDataSource; 25 import org.ethereum.datasource.LevelDbDataSource; 26  27 import java.io.BufferedReader; 28 import java.io.FileReader; 29 import java.io.IOException; 30 import java.nio.file.Paths; 31  32 /** 33  * The entry point for import state CLI tool 34  * This is an experimental/unsupported tool 35  */ 36 public class ImportState { 37  public static void main(String[] args) throws IOException { 38  RskContext ctx = new RskContext(args); 39  String databaseDir = ctx.getRskSystemProperties().databaseDir(); 40  KeyValueDataSource trieDB = LevelDbDataSource.makeDataSource(Paths.get(databaseDir, "unitrie")); 41  42  String filename = args[0]; 43  44  try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { 45  execute(reader, trieDB); 46  } 47  } 48  49  public static void execute(BufferedReader reader, KeyValueDataSource trieDB) throws IOException { 50  for (String line = reader.readLine(); line != null; line = reader.readLine()) { 51  line = line.trim(); 52  byte[] value = Hex.decode(line); 53  byte[] key = new Keccak256(Keccak256Helper.keccak256(value)).getBytes(); 54  55  trieDB.put(key, value); 56  } 57  58  trieDB.flush(); 59  trieDB.close(); 60  } 61 }