Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@
"@ethersproject/bytes": "^5.8.0",
"@ethersproject/rlp": "^5.8.0",
"@grpc/grpc-js": "^1.12.6",
"@hashgraph/cryptography": "1.9.0",
"@hashgraph/proto": "2.22.0",
"@hashgraph/cryptography": "file:.yalc/@hashgraph/cryptography",
"@hashgraph/proto": "file:.yalc/@hashgraph/proto",
"bignumber.js": "^9.1.1",
"bn.js": "^5.1.1",
"crypto-js": "^4.2.0",
"import-sync": "^2.2.3",
"js-base64": "^3.7.4",
"long": "^5.3.1",
"pino": "^9.6.0",
Expand Down Expand Up @@ -135,5 +136,6 @@
},
"resolutions": {
"bn.js": "5.2.1"
}
},
"packageManager": "[email protected]+sha512.845196026aab1cc3f098a0474b64dfbab2afe7a1b4e91dd86895d8e4aa32a7a6d03049e2d0ad770bbe4de023a7122fb68c1a1d6e0d033c7076085f9d5d4800d4"
}
127 changes: 126 additions & 1 deletion packages/proto/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ tasks:
- install
cmds:
- task "build:standalone"
- task "build:minimal:transactions"

build:standalone:
cmds:
Expand All @@ -73,6 +74,130 @@ tasks:
- npx copyfiles -u 1 src/index.d.ts src/proto.d.ts lib/ > /dev/null
# This is necessary to correctly run browser tests with an unpublished proto package
- npx yalc publish > /dev/null
build:minimal:transactions:
desc: "Generate individual JS files for each transaction proto file"
cmds:
- mkdir -p src/minimal
- |
success_count=0
fail_count=0

# Generate individual transaction files with specific dependencies
for proto_file in minimal_src/*_transaction.proto; do
if [ -f "$proto_file" ]; then
base_name=$(basename "$proto_file" .proto)
echo "Generating $base_name.js..."

# Get the imports from the transaction file
imports=$(grep -h '^import' "$proto_file" | sed 's/import "\(.*\)";/minimal_src\/\1/' | tr '\n' ' ')

# Get list of directly imported files (without minimal_src/ prefix)
direct_imports=$(grep -h '^import' "$proto_file" | sed 's/import "\(.*\)";/\1/' | tr '\n' ' ')

# Build common deps, excluding any that are directly imported
common_deps=""
for dep in duration.proto basic_types.proto custom_fees.proto timestamp.proto google_protobuf_wrappers.proto; do
if ! echo "$direct_imports" | grep -q "$dep"; then
common_deps="$common_deps minimal_src/$dep"
fi
done

# Generate each transaction with its own unique namespace to avoid conflicts
unique_namespace="hashgraph_${base_name}"
if npx pbjs -r "$unique_namespace" -t static-module -w es6 -p=minimal_src --dependency protobufjs/minimal --force-long --no-beautify --no-convert --no-delimited --no-verify -o "src/minimal/${base_name}.js" "$proto_file" $imports $common_deps 2>/dev/null; then
npx pbjs -r "transaction_contents" -t static-module -w es6 -p=minimal_src --dependency protobufjs/minimal --force-long --no-beautify --no-convert --no-delimited --no-verify -o "src/minimal/transaction_contents.js" transaction_contents.proto timestamp.proto google_protobuf_wrappers.proto
npx pbjs -r "transaction_response" -t static-module -w es6 -p=minimal_src --dependency protobufjs/minimal --force-long --no-beautify --no-convert --no-delimited --no-verify -o "src/minimal/transaction_response.js" transaction_response.proto timestamp.proto google_protobuf_wrappers.proto
npx pbts -n "$unique_namespace" -o src/minimal/${base_name}.d.ts src/minimal/${base_name}.js
npx pbts -n "transaction_contents" -o src/minimal/transaction_contents.d.ts src/minimal/transaction_contents.js
npx pbts -n "transaction_response" -o src/minimal/transaction_response.d.ts src/minimal/transaction_response.js
echo "✓ Successfully generated $base_name.js"
success_count=$((success_count + 1))
fi
fi
done

echo ""
echo "Summary: $success_count files generated successfully, $fail_count failed"
if [ $success_count -gt 0 ]; then
echo "✓ Each generated JS file contains the specific transaction and its dependencies"
fi
if [ $fail_count -gt 0 ]; then
echo "Note: Failed files likely have missing dependencies that need to be added to minimal_src/"
fi
- npx copyfiles -u 1 "src/minimal/*.d.ts" lib/ > /dev/null
- npx babel src/minimal -d lib/minimal
- task: generate:minimal:index

generate:minimal:index:
desc: "Generate index.js file for tree-shaking support in lib/minimal"
cmds:
- |
echo "Generating lib/minimal/index.js for tree-shaking..."

# Create the index.js content
cat > lib/minimal/index.js << 'EOF'
// Auto-generated index file for minimal transaction proto modules
// This enables tree-shaking by providing named exports for each transaction type

EOF

# Add named exports for each .js file
for js_file in lib/minimal/*.js; do
if [ -f "$js_file" ]; then
base_name=$(basename "$js_file" .js)
# Skip index.js to avoid circular reference
if [ "$base_name" != "index" ]; then
# Convert snake_case to PascalCase
class_name=$(echo "$base_name" | awk -F_ '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1' OFS="")
echo "export { default as $class_name } from \"./$base_name.js\";" >> lib/minimal/index.js
fi
fi
done

echo "" >> lib/minimal/index.js
echo "// For backwards compatibility, also export all as a single object" >> lib/minimal/index.js
echo "export default {" >> lib/minimal/index.js

# Add dynamic imports for default export
for js_file in lib/minimal/*.js; do
if [ -f "$js_file" ]; then
base_name=$(basename "$js_file" .js)
# Skip index.js to avoid circular reference
if [ "$base_name" != "index" ]; then
# Convert snake_case to PascalCase
class_name=$(echo "$base_name" | awk -F_ '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1' OFS="")
echo " $class_name: () => import(\"./$base_name.js\")," >> lib/minimal/index.js
fi
fi
done

echo "};" >> lib/minimal/index.js

# Count the exports
export_count=$(grep -c "export { default as" lib/minimal/index.js)
echo "✓ Generated index.js with $export_count transaction exports"
- task: generate:minimal:index:types

generate:minimal:index:types:
desc: "Generate TypeScript definitions for lib/minimal/index.js"
cmds:
- |
# Generate index.d.ts for the minimal package
echo "// Auto-generated index types for minimal transaction proto modules" > lib/minimal/index.d.ts
echo "// This enables tree-shaking by providing named exports for each transaction type" >> lib/minimal/index.d.ts
echo "" >> lib/minimal/index.d.ts

# Convert export statements to TypeScript
grep "^export { default as" lib/minimal/index.js | sed 's/\.js";$/";/' >> lib/minimal/index.d.ts

# Add default export type
echo "" >> lib/minimal/index.d.ts
echo "// For backwards compatibility, also export all as a single object" >> lib/minimal/index.d.ts
echo "declare const _default: {" >> lib/minimal/index.d.ts
grep "() => import" lib/minimal/index.js | sed 's/: () => import(\"\(.*\)\.js\"),/: () => Promise<typeof import("\1")>;/' >> lib/minimal/index.d.ts
echo "};" >> lib/minimal/index.d.ts
echo "" >> lib/minimal/index.d.ts
echo "export default _default;" >> lib/minimal/index.d.ts

clean:
cmds:
Expand All @@ -98,7 +223,7 @@ tasks:

"lint:js":
cmds:
- npx eslint --fix "src/*.js"
- npx eslint --fix "src/proto.js"

"test:release":
deps:
Expand Down
88 changes: 88 additions & 0 deletions packages/proto/minimal_src/atomic_batch_transaction.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* # Atomic Batch Transaction
* Transaction for handling a set of transactions atomically.
*/
syntax = "proto3";

package proto;

// SPDX-License-Identifier: Apache-2.0
option java_package = "com.hederahashgraph.api.proto.java";
option java_multiple_files = true;

import "basic_types.proto";
import "duration.proto";
import "custom_fees.proto";

/**
* A wrapper around signed transaction bytes for atomic batch.
*/
message Transaction {
/**
* A valid, serialized, `SignedTransaction` message.
*/
bytes signedTransactionBytes = 5;
}

/**
* A transaction body for handling a set of transactions atomically.
*/
message AtomicBatchTransactionBody {
/**
* A list of signed bytes that represent the batch transactions.
*/
repeated bytes transactions = 1;
}

/**
* A transaction body for atomic batch.
*/
message TransactionBody {
reserved 30, 61, 62, 63, 64;

/**
* A transaction identifier.
*/
TransactionID transactionID = 1;

/**
* A node account identifier.
*/
AccountID nodeAccountID = 2;

/**
* A maximum transaction fee, in tinybar.
*/
uint64 transactionFee = 3;

/**
* A maximum duration in which to execute this transaction.
*/
Duration transactionValidDuration = 4;

/**
* A short description for this transaction.
*/
string memo = 6;

/**
* The public key of the trusted batch assembler.
*/
Key batch_key = 73;

oneof data {
/**
* A transaction body for handling a set of transactions atomically.
*/
AtomicBatchTransactionBody atomic_batch = 74;
}

/**
* A list of maximum custom fees that the users are willing to pay.
*/
repeated CustomFeeLimit max_custom_fees = 1001;
}

message TransactionList {
repeated Transaction transaction_list = 1;
}
Loading
Loading