-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding node-extensions support in CLI (#147)
- Loading branch information
Showing
25 changed files
with
1,336 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")), | ||
)) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.