hashgraph / hedera-sdk-js

Hederaโ„ข Hashgraph SDK for JavaScript/TypeScript
https://docs.hedera.com/guides/docs/sdks
Apache License 2.0
276 stars 144 forks source link

Automatically generate/update `Status.js` and `RequestType.js` #1145

Open janaakhterov opened 2 years ago

janaakhterov commented 2 years ago

๐Ÿ†•๐Ÿฅ First Timers Only

This issue is reserved for people who have never contributed to Hedera or any open source project in general. We know that creating a pull request (PR) is a major barrier for new contributors. The goal of this issue and all other issues labeled by 'good first issue' is to help you make your first contribution to Hedera.

๐Ÿ‘พ Description of the issue

Problem

Currently, both Status.js and RequestType.js must be manually updated whenever new statuses or request types are introduced. While tools and scripts can streamline this process, it still requires manual execution and oversight. In particular, files like Status.js are prone to human error when manually updating the various status codes and response codes associated with Hedera transactions. Automating this process would eliminate the need for human intervention, ensure accuracy, and save time when new statuses or request types are added to the Hedera system.

For example, Status.js currently contains manually hardcoded status codes:

case Status.Ok:
  return "OK";
case Status.InvalidTransaction:
  return "INVALID_TRANSACTION";
case Status.PayerAccountNotFound:
  return "PAYER_ACCOUNT_NOT_FOUND"

Here are examples for manually adding the statuses: Example 1 Example 2 Example 3

If a new status code is introduced in the Hedera protobuf definitions, this file would need to be manually updated to reflect that change.

Solution

Automate the generation or updating of Status.js and RequestType.js by connecting the process directly to the Hedera protobuf definitions. This way, whenever new status codes or request types are introduced in the protobuf schema, the corresponding JavaScript files will be automatically updated or regenerated. This could be done by writing a script that parses the protobuf definitions and generates the JavaScript constants, ensuring that all relevant status codes and request types are always up-to-date.

Steps to Implement

  1. Create or modify a script to parse the Hedera protobuf definitions (such as ResponseCodeEnum).
  2. The script should automatically generate or update the content of Status.js and RequestType.js, appending new statuses and request types as needed.
  3. Integrate this script into the build or CI/CD pipeline so that the files are always updated whenever new protobuf definitions are added.

Additional Context

Given that Hedera is tightly integrated with protobuf, having the ability to pull in new status codes from the protobuf schema directly into the JavaScript files would ensure consistency across the ecosystem, especially during frequent updates.

Affected Environment

Hedera SDK Version: Any Operating System: Platform-independent (process needs to work across all environments)

๐Ÿ“‹ Step by step guide to do a contribution

If you have never contributed to an open source project at GitHub, the following step-by-step guide will introduce you to the workflow. More information and concrete samples for shell commands for each step can be found in our CONTRIBUTING.md file. A more detailed general documentation of the GitHub PR workflow can be found here.

๐ŸŽ‰ Contribute to Hacktoberfest

Solve this issue as part of the Hacktoberfest event and get a chance to receive cool goodies like a T-Shirt. ๐ŸŽฝ

๐Ÿค” Additional Information

If you have any questions, just ask us directly in this issue by adding a comment. You can join our community chat at Discord. A general manual about open-source contributions can be found here.

janaakhterov commented 2 years ago

Something to note here, with Java auto-generating these files already the hick-up we faced was when the protobufs renamed HederaFunctionality.Prng -> HederaFunctionality.UtilPrng. This would cause (and did cause) a breaking change in Java. So, the question is, should the SDKs keep up to date with the names in the protobufs for certain enums such as ResponseCodeEnum and HederaFunctionality, or should the SDKs hard-code a name?

hendrikebbers commented 1 month ago

We discussed about the issue in the hackathon today and have some questions about status and requestType. Before somebody work on the issues we should check if we can find a better solution. See https://github.com/hashgraph/hedera-sdk-java/issues/2040