Tenderly / tenderly-cli

CLI tool for Smart Contract error tracking, monitoring and alerting.
https://tenderly.co
GNU General Public License v3.0
522 stars 137 forks source link

Adding node-extensions support in CLI #147

Closed g4ndr4 closed 1 year ago

g4ndr4 commented 1 year ago

Context

The aim of this PR is to add support for node-extension related operations to CLI.

node-extensions init command

This commands helps users initialize extensions in the tenderly.yaml file. It accepts the following arguments:

The command checks whether the provided methodName is valid, and then prompts the user to select one action from a list of those eligible for extensions (presented in the following format: account/project:action). The list will contain only actions that are not already used by other extensions in tenderly.yaml file. If there are no actions, eligible for extensions, found in tenderly.yaml, the command will return an error. If there are eligible actions in tenderly.yaml, but all already used for other extensions in tenderly.yaml, the command will return an error.

Once the user has picked an action, the command will check whether the chosen extension method name is already taken by another extension in the same account/project and, if so, return an error.

Otherwise, the command will add the extension to the tenderly.yaml.

node-extensions deploy command

This command deploys extensions specified in tenderly.yaml file. It accepts the following arguments:

If no arguments are provided, the command will attempt to deploy all extensions defined in tenderly.yaml. In case any of those extension deployments fail, it will print out the failure reasons and continue with deployment.

The deployment of an extension has two steps. In case there are multiple extensions being deployed, these same steps are repeated for each extension being deployed.

1. Validation

This step performs the following checks:

If any of these checks fail, the deployment of the extension won't go through. Results of all four checks are aggregated and presented to the user in an error message.

2. Deployment

This step deploys the extension to the backend. It executes only if the Validation step succeeds.

g4zyn commented 1 year ago

My code structure would look something like this:

tenderly-cli/
 - main.go
 internal/
  command/
   - builder.go
   - command.go (types/interfaces)
   w3a/ (actions)
   gateway/ (extension commands should be inside this package since they belong to gateway domain) 
   hardhat/
   ...

Focus more on grouping logic by domain and exposing more interfaces. Avoid things like:

@l2cup 's PR on restructuring tenderly-server is a good example of how things should be structured.

I didn't have time to dive into the implementation itself, but with right code structuring you'll be able to write cleaner and more manageable code.