From 7d000121c32ae51a0b2e544b9da0c2c16abe41f3 Mon Sep 17 00:00:00 2001 From: Peter White Date: Mon, 18 Sep 2023 16:54:17 -0600 Subject: [PATCH] feat: add export genesis script --- scripts/export-genesis-state.sh | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/export-genesis-state.sh diff --git a/scripts/export-genesis-state.sh b/scripts/export-genesis-state.sh new file mode 100755 index 00000000..d8ca359b --- /dev/null +++ b/scripts/export-genesis-state.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Check if the correct number of arguments is provided +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi + +binary_location="$1" +chain_spec_location="$2" +output_file_name="$3" + +# Check if the binary location exists +if [ ! -f "$binary_location" ]; then + echo "Error: Binary location '$binary_location' does not exist." + exit 1 +fi + +# Check if the chain spec location exists +if [ ! -f "$chain_spec_location" ]; then + echo "Error: Chain spec location '$chain_spec_location' does not exist." + exit 1 +fi + +# Export the genesis state +export_output="$("$binary_location" export-genesis-state --chain="$chain_spec_location" "$output_file_name" 2>&1 | tee /dev/tty)" + +echo "" + +# Check if the export command produced an error +if [[ "$export_output" == *"No specific runtime was recognized for ChainSpec's Id"* || "$export_output" == *"Error"* ]]; then + echo "Error exporting genesis state. Please check your chain spec file." + echo "Deleting '$output_file_name'..." + rm "$output_file_name" + exit 1 +else + echo "Genesis state exported successfully to '$output_file_name'" +fi + + +