Skip to content

Commit

Permalink
feat: 231 add block stream tools (#300)
Browse files Browse the repository at this point in the history
Signed-off-by: jasperpotts <[email protected]>
Co-authored-by: jasperpotts <[email protected]>
  • Loading branch information
jasperpotts and jasperpotts authored Oct 30, 2024
1 parent efc0bba commit 5fe56b2
Show file tree
Hide file tree
Showing 9 changed files with 798 additions and 0 deletions.
21 changes: 21 additions & 0 deletions buildSrc/src/main/kotlin/com.hedera.block.tools.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("application")
id("com.hedera.block.conventions")
id("me.champeau.jmh")
}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include(":suites")
include(":stream")
include(":server")
include(":simulator")
include(":tools")

includeBuild(".") // https://github.com/gradle/gradle/issues/21490#issuecomment-1458887481

Expand Down Expand Up @@ -62,6 +63,7 @@ dependencyResolutionManagement {
version("com.google.auto.service.processor", "1.1.1")
version("com.google.auto.service", "1.1.1")
version("org.hyperledger.besu.nativelib.secp256k1", "0.8.2")
version("info.picocli", "4.7.6")

// gRPC dependencies
version("io.grpc", "1.65.1")
Expand Down
59 changes: 59 additions & 0 deletions stream/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,65 @@
exports com.hedera.hapi.block.stream;
exports com.hedera.hapi.block.stream.input;
exports com.hedera.hapi.block.stream.output;
exports com.hedera.hapi.node.base;
exports com.hedera.hapi.node.base.codec;
exports com.hedera.hapi.node.base.schema;
exports com.hedera.hapi.node.consensus;
exports com.hedera.hapi.node.consensus.codec;
exports com.hedera.hapi.node.consensus.schema;
exports com.hedera.hapi.node.contract;
exports com.hedera.hapi.node.contract.codec;
exports com.hedera.hapi.node.contract.schema;
exports com.hedera.hapi.node.file;
exports com.hedera.hapi.node.file.codec;
exports com.hedera.hapi.node.file.schema;
exports com.hedera.hapi.node.freeze;
exports com.hedera.hapi.node.freeze.codec;
exports com.hedera.hapi.node.freeze.schema;
exports com.hedera.hapi.node.network;
exports com.hedera.hapi.node.network.codec;
exports com.hedera.hapi.node.network.schema;
exports com.hedera.hapi.node.scheduled;
exports com.hedera.hapi.node.scheduled.codec;
exports com.hedera.hapi.node.scheduled.schema;
exports com.hedera.hapi.node.token;
exports com.hedera.hapi.node.token.codec;
exports com.hedera.hapi.node.token.schema;
exports com.hedera.hapi.node.transaction;
exports com.hedera.hapi.node.transaction.codec;
exports com.hedera.hapi.node.transaction.schema;
exports com.hedera.hapi.node.util;
exports com.hedera.hapi.node.util.codec;
exports com.hedera.hapi.node.util.schema;
exports com.hedera.hapi.streams;
exports com.hedera.hapi.streams.codec;
exports com.hedera.hapi.streams.schema;
exports com.hedera.hapi.node.addressbook;
exports com.hedera.hapi.node.state.addressbook.codec;
exports com.hedera.hapi.node.state.addressbook;
exports com.hedera.hapi.node.state.consensus.codec;
exports com.hedera.hapi.node.state.consensus;
exports com.hedera.hapi.node.state.token;
exports com.hedera.hapi.node.state.common;
exports com.hedera.hapi.node.state.contract;
exports com.hedera.hapi.node.state.file;
exports com.hedera.hapi.node.state.recordcache;
exports com.hedera.hapi.node.state.recordcache.codec;
exports com.hedera.hapi.node.state.blockrecords;
exports com.hedera.hapi.node.state.blockrecords.codec;
exports com.hedera.hapi.node.state.blockrecords.schema;
exports com.hedera.hapi.node.state.blockstream;
exports com.hedera.hapi.node.state.schedule;
exports com.hedera.hapi.node.state.primitives;
exports com.hedera.hapi.node.state.throttles;
exports com.hedera.hapi.node.state.congestion;
exports com.hedera.hapi.platform.event;
exports com.hedera.services.stream.proto;
exports com.hederahashgraph.api.proto.java;
exports com.hederahashgraph.service.proto.java;
exports com.hedera.hapi.platform.state;
exports com.hedera.hapi.node.state.roster;
exports com.hedera.hapi.block.stream.schema;

requires transitive com.google.common;
requires transitive com.google.protobuf;
Expand Down
45 changes: 45 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Command Line Tools for Block Nodes & Streams

This subproject provides command line tools for working with block stream files and maybe other things in the future. It
uses [picocli](https://picocli.info) to provide a command line interface which makes it easy to extend and add new
subcommands or options.

## Running from command line
You can run through gradle with the `tools:run` task. For example, to see the help for the `info` subcommand, you can
run:

`./gradlew -q tools:run --args="info --help"`

## Subcommands
The following subcommands are available:
- **json** Converts a binary block stream to JSON
- **info** Prints info for block files

# JSON Subcommand
Converts a binary block stream to JSON

`Usage: subcommands json [-t] [-ms=<minSizeMb>] [<files>...]`

**Options:**
- `-ms <minSizeMb>` or `--min-size=<minSizeMb>`
- Filter to only files bigger than this minimum file size in megabytes
- `-t` or `--transactions`
- expand transactions, this is no longer pure json conversion but is very useful making the
transactions human-readable.
- `<files>...`
- The block files or directories of block files to convert to JSON

# Info Subcommand
Prints info for block files

`Usage: subcommands info [-c] [-ms=<minSizeMb>] [-o=<outputFile>] [<files>...]`

**Options:**
- `-c` or `--csv`
- Enable CSV output mode (default: false)
- `-ms <minSizeMb>` or `--min-size=<minSizeMb>`
- Filter to only files bigger than this minimum file size in megabytes
- `-o <outputFile>` or `--output-file=<outputFile>`
- Output to file rather than stdout
- `<files>...`
- The block files or directories of block files to print info for
35 changes: 35 additions & 0 deletions tools/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("application")
id("com.hedera.block.tools")
}

description = "Hedera Block Stream Tools"

application {
mainModule = "com.hedera.block.tools"
mainClass = "com.hedera.block.tools.BlockStreamTool"
}

mainModuleInfo {
runtimeOnly("com.swirlds.config.impl")
runtimeOnly("org.apache.logging.log4j.slf4j2.impl")
runtimeOnly("io.grpc.netty.shaded")
}

testModuleInfo { requiresStatic("com.github.spotbugs.annotations") }
48 changes: 48 additions & 0 deletions tools/src/main/java/com/hedera/block/tools/BlockStreamTool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.block.tools;

import com.hedera.block.tools.commands.BlockInfo;
import com.hedera.block.tools.commands.ConvertToJson;
import picocli.CommandLine;
import picocli.CommandLine.Command;

/**
* Command line tool for working with Hedera block stream files
*/
@SuppressWarnings("InstantiationOfUtilityClass")
@Command(
name = "subcommands",
mixinStandardHelpOptions = true,
version = "BlockStreamTool 0.1",
subcommands = {ConvertToJson.class, BlockInfo.class})
public final class BlockStreamTool {

/**
* Empty Default constructor to remove JavaDoc warning
*/
public BlockStreamTool() {}

/**
* Main entry point for the app
* @param args command line arguments
*/
public static void main(String... args) {
int exitCode = new CommandLine(new BlockStreamTool()).execute(args);
System.exit(exitCode);
}
}
Loading

0 comments on commit 5fe56b2

Please sign in to comment.