Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): match upcoming node version with API #3318

Merged
merged 6 commits into from
May 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pb-gen:
## openrpc-gen: Generate OpenRPC spec for Celestia-Node's RPC api
openrpc-gen:
@echo "--> Generating OpenRPC spec"
@go run ./cmd/docgen fraud header state share das p2p node blob da
@go run ${LDFLAGS} ./cmd/celestia docgen
.PHONY: openrpc-gen

## lint-imports: Lint only Go imports.
Expand Down
37 changes: 16 additions & 21 deletions cmd/docgen/openrpc.go → cmd/celestia/docgen.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
package main

import (
"context"
"encoding/json"
"os"

"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-node/api/docgen"
"github.com/celestiaorg/celestia-node/api/rpc/client"
"github.com/celestiaorg/celestia-node/nodebuilder"
)

var rootCmd = &cobra.Command{
Use: "docgen [packages]",
Short: "docgen generates the openrpc documentation for Celestia Node packages",
RunE: func(_ *cobra.Command, moduleNames []string) error {
// 1. Open the respective nodebuilder/X/service.go files for AST parsing
var docgenCmd = &cobra.Command{
Use: "docgen",
Short: "docgen generates the openrpc documentation for all Celestia Node packages",
RunE: func(_ *cobra.Command, _ []string) error {
// 1. Collect all node's modules
moduleNames := make([]string, 0, len(client.Modules))
for module := range client.Modules {
moduleNames = append(moduleNames, module)
}

// 2. Open the respective nodebuilder/X/service.go files for AST parsing
nodeComments, permComments := docgen.ParseCommentsFromNodebuilderModules(moduleNames...)

// 2. Create an OpenRPC document from the map of comments + hardcoded metadata
// 3. Create an OpenRPC document from the map of comments + hardcoded metadata
doc := docgen.NewOpenRPCDocument(nodeComments, permComments)

// 3. Register the client wrapper interface on the document
// 4. Register the client wrapper interface on the document
for moduleName, module := range nodebuilder.PackageToAPI {
doc.RegisterReceiverName(moduleName, module)
}

// 4. Call doc.Discover()
// 5. Call doc.Discover()
d, err := doc.Discover()
if err != nil {
return err
}

// 5. Print to Stdout
// 6. Print to Stdout
jsonOut, err := json.MarshalIndent(d, "", " ")
if err != nil {
return err
Expand All @@ -42,14 +48,3 @@ var rootCmd = &cobra.Command{
return err
},
}

func main() {
err := run()
if err != nil {
os.Exit(1)
}
}

func run() error {
return rootCmd.ExecuteContext(context.Background())
}
1 change: 1 addition & 0 deletions cmd/celestia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func init() {
bridgeCmd,
lightCmd,
fullCmd,
docgenCmd,
versionCmd,
)
rootCmd.SetHelpCommand(&cobra.Command{})
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/node/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/celestiaorg/celestia-node/libs/authtoken"
)

const APIVersion = "v0.11.0"
var APIVersion = GetBuildInfo().SemanticVersion

type module struct {
tp Type
Expand Down
Loading