-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 231 add block stream tools (#300)
Signed-off-by: jasperpotts <[email protected]> Co-authored-by: jasperpotts <[email protected]>
- Loading branch information
1 parent
efc0bba
commit 5fe56b2
Showing
9 changed files
with
798 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
buildSrc/src/main/kotlin/com.hedera.block.tools.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
tools/src/main/java/com/hedera/block/tools/BlockStreamTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.