Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Sep 18, 2023
1 parent 57b3d6f commit d32597b
Show file tree
Hide file tree
Showing 17 changed files with 394 additions and 378 deletions.
16 changes: 15 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,15 @@ var (
// staticClient is used for generating the OpenRPC spec.
staticClient Client
Modules = moduleMap(&staticClient)

RequestURL string
RPCClient *Client
)

const (
authEnvKey = "CELESTIA_NODE_AUTH_TOKEN" //nolint:gosec

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

type Client struct {
Expand Down Expand Up @@ -65,8 +75,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)
},
}
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)
},
}
33 changes: 0 additions & 33 deletions cmd/celestia/internal/init.go

This file was deleted.

64 changes: 0 additions & 64 deletions cmd/celestia/internal/util.go

This file was deleted.

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)
},
}
38 changes: 29 additions & 9 deletions cmd/celestia/rpc.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
package main

import (
"github.com/celestiaorg/celestia-node/cmd/celestia/internal/admin"
"github.com/celestiaorg/celestia-node/cmd/celestia/internal/rpc"
"github.com/celestiaorg/celestia-node/api/rpc/client"

blob "github.com/celestiaorg/celestia-node/nodebuilder/blob/cmds"
das "github.com/celestiaorg/celestia-node/nodebuilder/das/cmds"
header "github.com/celestiaorg/celestia-node/nodebuilder/header/cmds"
node "github.com/celestiaorg/celestia-node/nodebuilder/node/cmds"
p2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p/cmds"
share "github.com/celestiaorg/celestia-node/nodebuilder/share/cmds"
state "github.com/celestiaorg/celestia-node/nodebuilder/state/cmds"
)

const authEnvKey = "CELESTIA_NODE_AUTH_TOKEN" //nolint:gosec

func init() {
rootCmd.AddCommand(admin.NodeCmd)
blob.BlobCmd.PersistentFlags().StringVar(initUrlFlag())
das.DASCmd.PersistentFlags().StringVar(initUrlFlag())
header.HeaderCmd.PersistentFlags().StringVar(initUrlFlag())
p2p.P2PCmd.PersistentFlags().StringVar(initUrlFlag())
share.ShareCmd.PersistentFlags().StringVar(initUrlFlag())
state.StateCmd.PersistentFlags().StringVar(initUrlFlag())
node.NodeCmd.PersistentFlags().StringVar(initUrlFlag())

rootCmd.AddCommand(
rpc.BlobCmd,
rpc.DASCmd,
rpc.HeaderCmd,
rpc.P2PCmd,
rpc.ShareCmd,
rpc.StateCmd,
blob.BlobCmd,
das.DASCmd,
header.HeaderCmd,
p2p.P2PCmd,
share.ShareCmd,
state.StateCmd,
node.NodeCmd,
)
}

func initUrlFlag() (*string, string, string, string) {
return &client.RequestURL, "url", client.DefaultRPCAddress, "Request URL"
}
68 changes: 0 additions & 68 deletions cmd/celestia/util.go

This file was deleted.

Loading

0 comments on commit d32597b

Please sign in to comment.