Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 27 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
# Repository versions and URLs
COSMOS_SDK_VERSION := v0.50.13-evm-comet1-inj.6
COSMOS_SDK_VERSION := v0.50.14-inj
COSMOS_SDK_REPO := https://github.com/InjectiveLabs/cosmos-sdk.git

INJECTIVE_CORE_VERSION := v1.16.4
INJECTIVE_CORE_VERSION := v1.17.0
INJECTIVE_CORE_REPO := https://github.com/InjectiveLabs/injective-core.git

INDEXER_VERSION := v1.16.91
INDEXER_VERSION := v1.17.16
INDEXER_REPO := https://github.com/InjectiveLabs/injective-indexer.git

PYTHON_SDK_VERSION := v1.11.2
IBC_GO_VERSION := v8.7.0-inj.3
IBC_GO_REPO := https://github.com/InjectiveLabs/ibc-go.git

COMETBFT_VERSION := v1.0.1-inj.4
COMETBFT_REPO := https://github.com/InjectiveLabs/cometbft.git

WASMD_VERSION := v0.53.3-inj.2
WASMD_REPO := https://github.com/InjectiveLabs/wasmd.git

PYTHON_SDK_VERSION := v1.12.0
PYTHON_SDK_REPO := https://github.com/InjectiveLabs/sdk-python.git

GO_SDK_VERSION := v1.58.3
GO_SDK_VERSION := v1.59.0
GO_SDK_REPO := https://github.com/InjectiveLabs/sdk-go.git

# Temporary directories
TEMP_DIR := /tmp/injective-docs-repos
COSMOS_SDK_DIR := $(TEMP_DIR)/cosmos-sdk
INJECTIVE_CORE_DIR := $(TEMP_DIR)/injective-core
INDEXER_DIR := $(TEMP_DIR)/injective-indexer
IBC_GO_DIR := $(TEMP_DIR)/ibc-go
COMETBFT_DIR := $(TEMP_DIR)/cometbft
WASMD_DIR := $(TEMP_DIR)/wasmd
PYTHON_SDK_DIR := tmp-python-sdk
GO_SDK_DIR := tmp-go-sdk

Expand All @@ -42,14 +54,18 @@ refresh-examples:

# Internal targets without repository management
_update-errors:
@echo "Updating error documentation from repositories..."
@./scripts/extract_errors.sh $(COSMOS_SDK_DIR) $(INJECTIVE_CORE_DIR)
@echo "Cleaning existing errors directory..."
@rm -rf source/json_tables/errors
@mkdir -p source/json_tables/errors
@echo "Generating errors JSON files..."
@cd $(INJECTIVE_CORE_DIR) && go run scripts/docs/document_error_codes_script.go -dest $(CURDIR)/source/json_tables/errors
@echo "Generating markdown documentation..."
@./scripts/generate_errors_md.sh
@echo "Error documentation update complete!"

_update-proto:
@echo "Generating proto JSON files..."
@./scripts/generate_proto_json_files.sh $(COSMOS_SDK_DIR) $(INJECTIVE_CORE_DIR) $(INDEXER_DIR)
@./scripts/generate_proto_json_files.sh $(COSMOS_SDK_DIR) $(INJECTIVE_CORE_DIR) $(INDEXER_DIR) $(IBC_GO_DIR) $(COMETBFT_DIR) $(WASMD_DIR)

# Public targets with repository management
update-errors-documentation:
Expand All @@ -70,6 +86,9 @@ clone-repos:
@git clone -q --depth 1 --branch $(COSMOS_SDK_VERSION) $(COSMOS_SDK_REPO) $(COSMOS_SDK_DIR)
@git clone -q --depth 1 --branch $(INJECTIVE_CORE_VERSION) $(INJECTIVE_CORE_REPO) $(INJECTIVE_CORE_DIR)
@git clone -q --depth 1 --branch $(INDEXER_VERSION) $(INDEXER_REPO) $(INDEXER_DIR)
@git clone -q --depth 1 --branch $(IBC_GO_VERSION) $(IBC_GO_REPO) $(IBC_GO_DIR)
@git clone -q --depth 1 --branch $(COMETBFT_VERSION) $(COMETBFT_REPO) $(COMETBFT_DIR)
@git clone -q --depth 1 --branch $(WASMD_VERSION) $(WASMD_REPO) $(WASMD_DIR)

clean-repos:
@echo "Cleaning up repositories..."
Expand Down
12 changes: 6 additions & 6 deletions scripts/extract_errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ process_modules() {

# Clean up any existing files and create directory structure
echo "Setting up directories..."
rm -rf "$BASE_OUTPUT_DIR/errors" "$BASE_OUTPUT_DIR/chain/errors"
mkdir -p "$BASE_OUTPUT_DIR/errors" "$BASE_OUTPUT_DIR/chain/errors"
rm -rf "$BASE_OUTPUT_DIR/cosmos/errors" "$BASE_OUTPUT_DIR/injective/errors"
mkdir -p "$BASE_OUTPUT_DIR/cosmos/errors" "$BASE_OUTPUT_DIR/injective/errors"

# Process Cosmos SDK repository
echo "Processing Cosmos SDK repository..."
process_modules "$COSMOS_SDK_DIR" "$BASE_OUTPUT_DIR/errors" "x"
process_modules "$COSMOS_SDK_DIR" "$BASE_OUTPUT_DIR/cosmos/errors" "x"

# Process Injective Core repository
echo "Processing Injective Core repository..."
process_modules "$INJECTIVE_CORE_DIR" "$BASE_OUTPUT_DIR/chain/errors" "injective-chain/modules"
process_modules "$INJECTIVE_CORE_DIR" "$BASE_OUTPUT_DIR/injective/errors" "injective-chain/modules"

echo "Error extraction complete. JSON files have been created in:"
echo "- $BASE_OUTPUT_DIR/errors (Cosmos SDK modules)"
echo "- $BASE_OUTPUT_DIR/chain/errors (Injective Core modules)"
echo "- $BASE_OUTPUT_DIR/cosmos/errors (Cosmos SDK modules)"
echo "- $BASE_OUTPUT_DIR/injective/errors (Injective Core modules)"
34 changes: 14 additions & 20 deletions scripts/generate_errors_md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
set -e

OUTPUT_FILE="source/includes/_errors.md"
COSMOS_ERRORS_DIR="source/json_tables/errors"
INJECTIVE_ERRORS_DIR="source/json_tables/chain/errors"
ERRORS_DIR="source/json_tables/errors"

# Function to add a module's errors to the markdown file
add_module_errors() {
local file=$1
local prefix=$2
local module_name=$(basename "$file" .json)

# Just capitalize the first letter
local capitalized_name=$(echo "$module_name" | perl -pe 's/^(.)/\u$1/')
# Remove "_errors" suffix and capitalize the first letter
local clean_name=$(echo "$module_name" | sed 's/_errors$//')
local capitalized_name=$(echo "$clean_name" | perl -pe 's/^(.)/\u$1/')

echo "## ${capitalized_name} module" >> "$OUTPUT_FILE"
echo >> "$OUTPUT_FILE"
Expand All @@ -26,23 +25,18 @@ add_module_errors() {
# Remove existing file if it exists
rm -f "$OUTPUT_FILE"

# Add Cosmos SDK section
if [ -d "$COSMOS_ERRORS_DIR" ]; then
echo "# Cosmos SDK errors" >> "$OUTPUT_FILE"
echo >> "$OUTPUT_FILE"
for file in "$COSMOS_ERRORS_DIR"/*.json; do
[ -f "$file" ] || continue
add_module_errors "$file" "Cosmos SDK"
done
fi
# Add header
echo "# Error Codes" >> "$OUTPUT_FILE"
echo >> "$OUTPUT_FILE"
echo "This section lists all error codes from various modules in the Injective ecosystem." >> "$OUTPUT_FILE"
echo >> "$OUTPUT_FILE"

# Add Injective section
if [ -d "$INJECTIVE_ERRORS_DIR" ]; then
echo "# Injective errors" >> "$OUTPUT_FILE"
echo >> "$OUTPUT_FILE"
for file in "$INJECTIVE_ERRORS_DIR"/*.json; do
# Process all error files in the errors directory
if [ -d "$ERRORS_DIR" ]; then
# Sort files alphabetically for consistent output
for file in $(ls "$ERRORS_DIR"/*.json 2>/dev/null | sort); do
[ -f "$file" ] || continue
add_module_errors "$file" "Injective"
add_module_errors "$file"
done
fi

Expand Down
134 changes: 123 additions & 11 deletions scripts/generate_proto_json_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ set -euo pipefail

# Script usage
usage() {
echo "Usage: $0 <cosmos-sdk-path> <injective-core-path> <indexer-path>"
echo "Usage: $0 <cosmos-sdk-path> <injective-core-path> <indexer-path> <ibc-go-path> <cometbft-path> <wasmd-path>"
echo
echo "Generate proto JSON files from repositories"
echo
echo "Arguments:"
echo " cosmos-sdk-path Path to the Cosmos SDK repository"
echo " injective-core-path Path to the Injective Core repository"
echo " indexer-path Path to the Indexer repository"
echo " ibc-go-path Path to the IBC Go repository"
echo " cometbft-path Path to the CometBFT repository"
echo " wasmd-path Path to the Wasmd repository"
echo
echo "Example:"
echo " $0 /tmp/cosmos-sdk /tmp/injective-core /tmp/injective-indexer"
echo " $0 /tmp/cosmos-sdk /tmp/injective-core /tmp/injective-indexer /tmp/ibc-go /tmp/cometbft /tmp/wasmd"
exit 1
}

# Check arguments
if [ $# -ne 3 ]; then
if [ $# -ne 6 ]; then
usage
fi

Expand All @@ -39,17 +42,36 @@ init_config() {

# Cosmos SDK configuration
COSMOS_MODULES_PATH="$1/x"
COSMOS_CLIENT_GRPC_PATH="$1/client/grpc"
COSMOS_PROTO_PATH="$1/proto/cosmos"
COSMOS_OUTPUT_DIR="$OUTPUT_BASE_DIR/cosmos"

# Indexer configuration
INDEXER_API_PATH="$3/api/gen/grpc"
INDEXER_OUTPUT_DIR="$OUTPUT_BASE_DIR/indexer_new"
INDEXER_OUTPUT_DIR="$OUTPUT_BASE_DIR/indexer"

# IBC Go configuration
IBC_MODULES_PATH="$4/modules"
IBC_PROTO_PATH="$4/proto/ibc"
IBC_OUTPUT_DIR="$OUTPUT_BASE_DIR/ibc"

# CometBFT configuration
COMETBFT_MODULES_PATH="$5/api/cometbft"
COMETBFT_PROTO_PATH="$5/proto"
COMETBFT_OUTPUT_DIR="$OUTPUT_BASE_DIR/cometbft"

# Wasmd configuration
WASMD_MODULES_PATH="$6/x"
WASMD_PROTO_PATH="$6/proto"
WASMD_OUTPUT_DIR="$OUTPUT_BASE_DIR/wasmd"

# Export all variables
export OUTPUT_BASE_DIR INJECTIVE_CHAIN_PATH INJECTIVE_MODULES_PATH INJECTIVE_TYPES_PATH \
INJECTIVE_STREAM_PATH INJECTIVE_PROTO_PATH INJECTIVE_OUTPUT_DIR COSMOS_MODULES_PATH \
COSMOS_PROTO_PATH COSMOS_OUTPUT_DIR INDEXER_API_PATH INDEXER_OUTPUT_DIR
COSMOS_CLIENT_GRPC_PATH COSMOS_PROTO_PATH COSMOS_OUTPUT_DIR INDEXER_API_PATH INDEXER_OUTPUT_DIR \
IBC_MODULES_PATH IBC_PROTO_PATH IBC_OUTPUT_DIR \
COMETBFT_MODULES_PATH COMETBFT_PROTO_PATH COMETBFT_OUTPUT_DIR \
WASMD_MODULES_PATH WASMD_PROTO_PATH WASMD_OUTPUT_DIR
}

# Check required commands
Expand Down Expand Up @@ -202,10 +224,10 @@ process_pb_file() {
declare -a comment_lines

while IFS= read -r line || [ -n "$line" ]; do
if [[ $line =~ ^type[[:space:]]+([[:alnum:]]+)[[:space:]]+struct[[:space:]]+\{ ]]; then
if [[ $line =~ ^type[[:space:]]+([[:alnum:]_]+)[[:space:]]+struct[[:space:]]+\{ ]]; then
local new_type="${BASH_REMATCH[1]}"

if [ -n "$current_type" ] && [ ${#fields[@]} -gt 0 ] && [[ ! "$current_type" =~ ^Event ]]; then
if [ -n "$current_type" ] && [ ${#fields[@]} -gt 0 ] && [[ ! "$current_type" =~ ^Event.+ ]]; then
(IFS=$'\n'; echo "${fields[*]}") | jq -s '.' > "$output_dir/${current_type}.json"
echo "Generated $output_dir/${current_type}.json"
fi
Expand All @@ -224,7 +246,7 @@ process_pb_file() {

# Check if this line is a protobuf field definition
if [[ $line =~ ^[[:space:]]*[A-Z][[:alnum:]]*[[:space:]] ]] && [[ $line =~ protobuf: ]]; then
if [ -n "$current_type" ] && [[ ! "$current_type" =~ ^Event ]]; then
if [ -n "$current_type" ] && [[ ! "$current_type" =~ ^Event.+ ]]; then
local proto_name
proto_name=$(get_proto_name "$line")
if [ -n "$proto_name" ]; then
Expand Down Expand Up @@ -262,7 +284,7 @@ process_pb_file() {
done < "$pb_file"

# Write the last type if it exists and has fields
if [ -n "$current_type" ] && [ ${#fields[@]} -gt 0 ] && [[ ! "$current_type" =~ ^Event ]]; then
if [ -n "$current_type" ] && [ ${#fields[@]} -gt 0 ] && [[ ! "$current_type" =~ ^Event.+ ]]; then
(IFS=$'\n'; echo "${fields[*]}") | jq -s '.' > "$output_dir/${current_type}.json"
echo "Generated $output_dir/${current_type}.json"
fi
Expand Down Expand Up @@ -422,6 +444,13 @@ process_repository_modules() {

if [ -d "$module_dir/types" ]; then
process_types_directory "$module_dir/types" "$output_dir" "$module_name"
else
# Check if module has .pb.go files in the main directory
if compgen -G "$module_dir/*.pb.go" > /dev/null 2>&1; then
echo "Processing module with direct .pb.go files: $module_name"
mkdir -p "$output_dir/$module_name"
process_directory "$module_dir" "$output_dir/$module_name"
fi
fi
done
}
Expand Down Expand Up @@ -511,14 +540,76 @@ process_indexer_modules() {
done
}

# Process IBC modules - recursively find and process all 'types' folders
process_ibc_modules() {
local modules_path="$1"
local output_dir="$2"

echo "Processing IBC modules..."

# Process each module
for module_dir in "$modules_path"/*/; do
if [ -d "$module_dir" ]; then
module_name=$(basename "$module_dir")
echo "Processing IBC module: $module_name"

# Find all 'types' directories within this module recursively
while IFS= read -r -d '' types_dir; do
# Get the relative path from the modules_path to preserve structure
local rel_path="${types_dir#$modules_path/}"

# Create the corresponding output directory structure
local types_output_dir="$output_dir/$rel_path"
mkdir -p "$types_output_dir"

echo "Processing types directory: $rel_path"

# Process .pb.go files in this types directory
process_directory "$types_dir" "$types_output_dir"

done < <(find "$module_dir" -type d -name "types" -print0)
fi
done
}

# Process CometBFT modules - recursively find and process all .pb.go files
process_cometbft_modules() {
local modules_path="$1"
local output_dir="$2"

echo "Processing CometBFT modules..."

# Process each module
for module_dir in "$modules_path"/*/; do
if [ -d "$module_dir" ]; then
module_name=$(basename "$module_dir")
echo "Processing CometBFT module: $module_name"

# Get the relative path from the modules_path to preserve structure
local rel_path="${module_dir#$modules_path/}"
# Remove trailing slash
rel_path="${rel_path%/}"

# Create the corresponding output directory structure
local module_output_dir="$output_dir/$rel_path"
mkdir -p "$module_output_dir"

echo "Processing CometBFT module directory: $rel_path"

# Process all .pb.go files recursively in this module directory
process_directory_recursive "$module_dir" "$module_output_dir"
fi
done
}

# Initialize configuration with provided paths
init_config "$1" "$2" "$3"
init_config "$1" "$2" "$3" "$4" "$5" "$6"

# Check requirements first
check_requirements

# Create base output directories
mkdir -p "$INJECTIVE_OUTPUT_DIR" "$COSMOS_OUTPUT_DIR" "$INDEXER_OUTPUT_DIR"
mkdir -p "$INJECTIVE_OUTPUT_DIR" "$COSMOS_OUTPUT_DIR" "$INDEXER_OUTPUT_DIR" "$IBC_OUTPUT_DIR" "$COMETBFT_OUTPUT_DIR" "$WASMD_OUTPUT_DIR"

# Process Injective modules
echo "Processing Injective modules..."
Expand All @@ -537,9 +628,30 @@ if [ -d "$1/types" ]; then
process_cosmos_types_directory "$1/types" "$COSMOS_OUTPUT_DIR"
fi

# Process Cosmos SDK client/grpc directory and its subdirectories
if [ -d "$COSMOS_CLIENT_GRPC_PATH" ]; then
echo "Processing Cosmos SDK client/grpc directory..."
process_directory_recursive "$COSMOS_CLIENT_GRPC_PATH" "$COSMOS_OUTPUT_DIR"
fi

[ -d "$COSMOS_PROTO_PATH" ] && process_proto_directory "$COSMOS_PROTO_PATH" "$COSMOS_OUTPUT_DIR"

# Process Indexer modules
[ -d "$INDEXER_API_PATH" ] && process_indexer_modules "$INDEXER_API_PATH" "$INDEXER_OUTPUT_DIR"

# Process IBC modules
echo "Processing IBC modules..."
[ -d "$IBC_MODULES_PATH" ] && process_ibc_modules "$IBC_MODULES_PATH" "$IBC_OUTPUT_DIR"
[ -d "$IBC_PROTO_PATH" ] && process_proto_directory "$IBC_PROTO_PATH" "$IBC_OUTPUT_DIR"

# Process CometBFT modules
echo "Processing CometBFT modules..."
[ -d "$COMETBFT_MODULES_PATH" ] && process_cometbft_modules "$COMETBFT_MODULES_PATH" "$COMETBFT_OUTPUT_DIR"
[ -d "$COMETBFT_PROTO_PATH" ] && process_proto_directory "$COMETBFT_PROTO_PATH" "$COMETBFT_OUTPUT_DIR"

# Process Wasmd modules
echo "Processing Wasmd modules..."
[ -d "$WASMD_MODULES_PATH" ] && process_repository_modules "$WASMD_MODULES_PATH" "$WASMD_OUTPUT_DIR"
[ -d "$WASMD_PROTO_PATH" ] && process_proto_directory "$WASMD_PROTO_PATH" "$WASMD_OUTPUT_DIR"

echo "Processing complete!"
Loading