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

refactor(cmd): extract rpc cmds #2706

Merged
merged 10 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
15 changes: 14 additions & 1 deletion api/rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"os"

"github.com/filecoin-project/go-jsonrpc"

Expand All @@ -22,6 +23,14 @@ var (
// staticClient is used for generating the OpenRPC spec.
staticClient Client
Modules = moduleMap(&staticClient)

RequestURL string
)

const (
authEnvKey = "CELESTIA_NODE_AUTH_TOKEN"

DefaultRPCAddress = "http://localhost:26658"
)

type Client struct {
Expand Down Expand Up @@ -65,8 +74,12 @@ func NewPublicClient(ctx context.Context, addr string) (*Client, error) {
}

// NewClient creates a new Client with one connection per namespace with the
// given token as the authorization token.
// given token as the authorization token. In case if token will be empty, then
// `CELESTIA_NODE_AUTH_TOKEN` will be used in order to get the token.
func NewClient(ctx context.Context, addr string, token string) (*Client, error) {
if token == "" {
token = os.Getenv(authEnvKey)
}
authHeader := http.Header{perms.AuthKey: []string{fmt.Sprintf("Bearer %s", token)}}
return newClient(ctx, addr, authHeader)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/celestia/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/spf13/pflag"

cmdnode "github.com/celestiaorg/celestia-node/cmd"
"github.com/celestiaorg/celestia-node/cmd/celestia/util"
"github.com/celestiaorg/celestia-node/nodebuilder/core"
"github.com/celestiaorg/celestia-node/nodebuilder/gateway"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
Expand Down Expand Up @@ -42,6 +43,6 @@ var bridgeCmd = &cobra.Command{
Args: cobra.NoArgs,
Short: "Manage your Bridge node",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return persistentPreRunEnv(cmd, node.Bridge, args)
return util.PersistentPreRunEnv(cmd, node.Bridge, args)
},
}
20 changes: 20 additions & 0 deletions cmd/celestia/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,23 @@ func TestBridge(t *testing.T) {
})
*/
}

func parseSignatureForHelpstring(methodSig reflect.StructField) string {
simplifiedSignature := "("
in, out := methodSig.Type.NumIn(), methodSig.Type.NumOut()
for i := 1; i < in; i++ {
simplifiedSignature += methodSig.Type.In(i).String()
if i != in-1 {
simplifiedSignature += ", "
}
}
simplifiedSignature += ") -> ("
for i := 0; i < out-1; i++ {
simplifiedSignature += methodSig.Type.Out(i).String()
if i != out-2 {
simplifiedSignature += ", "
}
}
simplifiedSignature += ")"
return simplifiedSignature
}
27 changes: 0 additions & 27 deletions cmd/celestia/das.go

This file was deleted.

3 changes: 2 additions & 1 deletion cmd/celestia/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/spf13/pflag"

cmdnode "github.com/celestiaorg/celestia-node/cmd"
"github.com/celestiaorg/celestia-node/cmd/celestia/util"
"github.com/celestiaorg/celestia-node/nodebuilder/core"
"github.com/celestiaorg/celestia-node/nodebuilder/gateway"
"github.com/celestiaorg/celestia-node/nodebuilder/header"
Expand Down Expand Up @@ -46,6 +47,6 @@ var fullCmd = &cobra.Command{
Args: cobra.NoArgs,
Short: "Manage your Full node",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return persistentPreRunEnv(cmd, node.Full, args)
return util.PersistentPreRunEnv(cmd, node.Full, args)
},
}
3 changes: 2 additions & 1 deletion cmd/celestia/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/spf13/pflag"

cmdnode "github.com/celestiaorg/celestia-node/cmd"
"github.com/celestiaorg/celestia-node/cmd/celestia/util"
"github.com/celestiaorg/celestia-node/nodebuilder/core"
"github.com/celestiaorg/celestia-node/nodebuilder/gateway"
"github.com/celestiaorg/celestia-node/nodebuilder/header"
Expand Down Expand Up @@ -46,6 +47,6 @@ var lightCmd = &cobra.Command{
Args: cobra.NoArgs,
Short: "Manage your Light node",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return persistentPreRunEnv(cmd, node.Light, args)
return util.PersistentPreRunEnv(cmd, node.Light, args)
},
}
Loading