Skip to content

Commit

Permalink
Adding node-extensions support in CLI (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
g4ndr4 authored May 9, 2023
1 parent b5733ab commit 806ef39
Show file tree
Hide file tree
Showing 25 changed files with 1,336 additions and 21 deletions.
2 changes: 2 additions & 0 deletions buidler/buidler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func NewDeploymentProvider() *DeploymentProvider {
call.NewNetworkCalls(),
call.NewActionCalls(),
call.NewDevNetCalls(),
call.NewGatewayCalls(),
call.NewExtensionCalls(),
)

networks, err := rest.Networks.GetPublicNetworks()
Expand Down
2 changes: 1 addition & 1 deletion commands/actions/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type actionsTenderlyYaml struct {
Actions map[string]actionsModel.ProjectActions `yaml:"actions"`
}

func mustGetActions() map[string]actionsModel.ProjectActions {
func MustGetActions() map[string]actionsModel.ProjectActions {
if !config.IsAnyActionsInit() {
logrus.Error(commands.Colorizer.Sprintf(
"Actions not initialized. Are you in the right directory? Run %s to initialize project.",
Expand Down
2 changes: 1 addition & 1 deletion commands/actions/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func buildFunc(cmd *cobra.Command, args []string) {
commands.CheckLogin()
r = commands.NewRest()

allActions := mustGetActions()
allActions := MustGetActions()
var slugs []string
for k := range allActions {
slugs = append(slugs, k)
Expand Down
28 changes: 28 additions & 0 deletions commands/extensions/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package extensions

import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/tenderly/tenderly-cli/commands"
)

func init() {
commands.RootCmd.AddCommand(extensionsCmd)
}

var extensionsCmd = &cobra.Command{
Use: "node-extensions",
Short: "Create, build and deploy Node Extensions.",
Long: "Node Extensions allow you to easily build and deploy custom RPC endpoints for your dapps.\n" +
"Backed by Web3 Actions, you can define your own, custom JSON-RPC endpoints to fit your needs.",
Run: func(cmd *cobra.Command, args []string) {
commands.CheckLogin()

logrus.Info(commands.Colorizer.Sprintf("\nWelcome to Node Extensions!\n"+
"Initialize Node Extensions with %s.\n"+
"Deploy Node Extensions with %s.\n",
commands.Colorizer.Bold(commands.Colorizer.Green("tenderly extensions init")),
commands.Colorizer.Bold(commands.Colorizer.Green("tenderly extensions deploy")),
))
},
}
60 changes: 60 additions & 0 deletions commands/extensions/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package extensions

import (
"github.com/tenderly/tenderly-cli/config"
extensionsModel "github.com/tenderly/tenderly-cli/model/extensions"
"github.com/tenderly/tenderly-cli/userError"
"gopkg.in/yaml.v3"
"os"
)

func ReadExtensionsFromConfig() map[string][]extensionsModel.ConfigExtension {
extensions := make(map[string][]extensionsModel.ConfigExtension)
allExtensions := MustGetExtensions()
for accountAndProjectSlug, projectExtensions := range allExtensions {
extensions[accountAndProjectSlug] = make([]extensionsModel.ConfigExtension, len(projectExtensions.Specs))
i := 0
for configExtensionName, configExtension := range projectExtensions.Specs {
extensions[accountAndProjectSlug][i] = extensionsModel.ConfigExtension{
Name: configExtensionName,
ActionName: configExtension.ActionName,
MethodName: configExtension.MethodName,
Description: configExtension.Description,
}
i++
}
}

return extensions
}

type extensionsTenderlyYaml struct {
Extensions map[string]extensionsModel.ConfigProjectExtensions `yaml:"node_extensions"`
}

func MustGetExtensions() map[string]extensionsModel.ConfigProjectExtensions {
content, err := config.ReadProjectConfig()
if err != nil {
userError.LogErrorf("failed reading project config: %s",
userError.NewUserError(
err,
"Failed reading project's tenderly.yaml config. This can happen if you are running an older version of the Tenderly CLI.",
),
)
os.Exit(1)
}

var tenderlyYaml extensionsTenderlyYaml
err = yaml.Unmarshal(content, &tenderlyYaml)
if err != nil {
userError.LogErrorf("failed unmarshalling `node_extensions` config: %s",
userError.NewUserError(
err,
"Failed parsing `node_extensions` configuration. This can happen if you are running an older version of the Tenderly CLI.",
),
)
os.Exit(1)
}

return tenderlyYaml.Extensions
}
Loading

0 comments on commit 806ef39

Please sign in to comment.