Search in sources :

Example 1 with Hex.toHexString

use of org.aion.util.conversions.Hex.toHexString in project aion by aionnetwork.

the class AionRepositoryImpl method dumpTestData.

public void dumpTestData(long blockNumber, String[] otherParameters, String basePath, Logger log) {
    try {
        String file = blockStore.dumpPastBlocksForConsensusTest(blockNumber, basePath);
        if (file == null) {
            log.error("Illegal arguments. Cannot print block information.");
        } else {
            log.info("Block information stored in " + file);
        }
    } catch (IOException e) {
        log.error("Exception encountered while writing data to file.", e);
    }
    int paramIndex = 1;
    // print state for parent block
    Block parent = blockStore.getChainBlockByNumber(blockNumber - 1);
    if (parent == null) {
        log.error("Illegal arguments. Parent block is null.");
    } else {
        if (otherParameters.length > paramIndex && otherParameters[paramIndex].equals("skip-state")) {
            log.info("Parent state information is not retrieved.");
            paramIndex++;
        } else {
            try {
                syncToRoot(parent.getStateRoot());
                File file = new File(basePath, System.currentTimeMillis() + "-state-for-parent-block-" + parent.getNumber() + ".out");
                BufferedWriter writer = new BufferedWriter(new FileWriter(file));
                writer.append(Hex.toHexString(dumpImportableState(parent.getStateRoot(), Integer.MAX_VALUE, DatabaseType.STATE)));
                writer.newLine();
                writer.close();
                log.info("Parent state information stored in " + file.getName());
            } catch (IOException e) {
                log.error("Exception encountered while writing data to file.", e);
            }
        }
        // print details and storage for the given contracts
        if (otherParameters.length > paramIndex) {
            try {
                syncToRoot(parent.getStateRoot());
                File file = new File(basePath, System.currentTimeMillis() + "-state-contracts.out");
                BufferedWriter writer = new BufferedWriter(new FileWriter(file));
                // iterate through contracts
                for (int i = paramIndex; i < otherParameters.length; i++) {
                    writer.append("Contract: " + AddressUtils.wrapAddress(otherParameters[i]));
                    writer.newLine();
                    StoredContractDetails details = getContractDetails(AddressUtils.wrapAddress(otherParameters[i]));
                    if (details != null) {
                        writer.append("Details: " + Hex.toHexString(details.getEncoded()));
                        writer.newLine();
                        writer.append("Storage: " + Hex.toHexString(dumpImportableStorage(details.getStorageHash(), Integer.MAX_VALUE, AddressUtils.wrapAddress(otherParameters[i]))));
                        writer.newLine();
                    }
                    writer.newLine();
                }
                writer.close();
                log.info("Contract details and storage information stored in " + file.getName());
            } catch (IOException e) {
                log.error("Exception encountered while writing data to file.", e);
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) Block(org.aion.zero.impl.types.Block) Hex.toHexString(org.aion.util.conversions.Hex.toHexString) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Hex.toHexString (org.aion.util.conversions.Hex.toHexString)1 Block (org.aion.zero.impl.types.Block)1