-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from KenshiTech/fix-cobra-98
Fix cobra 98
- Loading branch information
Showing
54 changed files
with
696 additions
and
1,059 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,5 @@ docker/pgadmin | |
node_trace.* | ||
internal/bin | ||
bin | ||
conf.*.private | ||
**/conf.*.private | ||
.idea |
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,38 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/KenshiTech/unchained/internal/app" | ||
"github.com/KenshiTech/unchained/internal/config" | ||
"github.com/KenshiTech/unchained/internal/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// broker represents the broker command. | ||
var broker = &cobra.Command{ | ||
Use: "broker", | ||
Short: "Run the Unchained client in broker mode", | ||
Long: `Run the Unchained client in broker mode`, | ||
Run: func(_ *cobra.Command, _ []string) { | ||
err := config.Load(config.App.System.ConfigPath, config.App.System.SecretsPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
log.Start(config.App.System.Log) | ||
app.Broker() | ||
}, | ||
} | ||
|
||
// WithBrokerCmd appends the broker command to the root command. | ||
func WithBrokerCmd(cmd *cobra.Command) { | ||
cmd.AddCommand(broker) | ||
} | ||
|
||
func init() { | ||
broker.Flags().StringP( | ||
"broker", | ||
"b", | ||
"wss://shinobi.brokers.kenshi.io", | ||
"Unchained broker to connect to", | ||
) | ||
} |
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,51 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/KenshiTech/unchained/internal/app" | ||
"github.com/KenshiTech/unchained/internal/config" | ||
"github.com/KenshiTech/unchained/internal/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// consumer represents the consumer command. | ||
var consumer = &cobra.Command{ | ||
Use: "consumer", | ||
Short: "Run the Unchained client in consumer mode", | ||
Long: `Run the Unchained client in consumer mode`, | ||
|
||
PreRun: func(cmd *cobra.Command, _ []string) { | ||
config.App.Network.BrokerURI = cmd.Flags().Lookup("broker").Value.String() | ||
config.App.Network.Bind = cmd.Flags().Lookup("graphql").Value.String() | ||
}, | ||
|
||
Run: func(_ *cobra.Command, _ []string) { | ||
err := config.Load(config.App.System.ConfigPath, config.App.System.SecretsPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
log.Start(config.App.System.Log) | ||
app.Consumer() | ||
}, | ||
} | ||
|
||
// WithConsumerCmd append command of consumer to the root command. | ||
func WithConsumerCmd(cmd *cobra.Command) { | ||
cmd.AddCommand(consumer) | ||
} | ||
|
||
func init() { | ||
consumer.Flags().StringP( | ||
"broker", | ||
"b", | ||
"wss://shinobi.brokers.kenshi.io", | ||
"Unchained broker to connect to", | ||
) | ||
|
||
consumer.Flags().StringP( | ||
"graphql", | ||
"g", | ||
"127.0.0.1:8080", | ||
"The graphql server path to bind", | ||
) | ||
} |
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,43 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/KenshiTech/unchained/internal/app" | ||
"github.com/KenshiTech/unchained/internal/config" | ||
"github.com/KenshiTech/unchained/internal/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// worker represents the worker command. | ||
var worker = &cobra.Command{ | ||
Use: "worker", | ||
Short: "Run the Unchained client in worker mode", | ||
Long: `Run the Unchained client in worker mode`, | ||
|
||
PreRun: func(cmd *cobra.Command, _ []string) { | ||
config.App.Network.BrokerURI = cmd.Flags().Lookup("broker").Value.String() | ||
}, | ||
|
||
Run: func(_ *cobra.Command, _ []string) { | ||
err := config.Load(config.App.System.ConfigPath, config.App.System.SecretsPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
log.Start(config.App.System.Log) | ||
app.Worker() | ||
}, | ||
} | ||
|
||
// WithWorkerCmd appends the worker command to the root command. | ||
func WithWorkerCmd(cmd *cobra.Command) { | ||
cmd.AddCommand(worker) | ||
} | ||
|
||
func init() { | ||
worker.Flags().StringP( | ||
"broker", | ||
"b", | ||
"wss://shinobi.brokers.kenshi.io", | ||
"Unchained broker to connect to", | ||
) | ||
} |
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,53 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/KenshiTech/unchained/cmd/handler" | ||
"github.com/KenshiTech/unchained/internal/config" | ||
"github.com/KenshiTech/unchained/internal/constants" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// root represents the root command of application. | ||
var root = &cobra.Command{ | ||
Use: "unchained", | ||
Short: "Unchained is the universal data validation and processing protocol", | ||
Long: `Unchained is the universal data validation and processing protocol`, | ||
Run: func(_ *cobra.Command, _ []string) { | ||
if config.App.System.PrintVersion { | ||
fmt.Println(constants.Version) | ||
} else { | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
func main() { | ||
handler.WithBrokerCmd(root) | ||
handler.WithConsumerCmd(root) | ||
handler.WithWorkerCmd(root) | ||
|
||
err := root.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
root.Flags().BoolVarP(&config.App.System.PrintVersion, "version", "v", false, "Print the Unchained version number and die") | ||
root.PersistentFlags().StringVarP(&config.App.System.ConfigPath, "config", "c", "./conf.yaml", "Config file") | ||
root.PersistentFlags().StringVarP(&config.App.System.SecretsPath, "secrets", "s", "./secrets.yaml", "Secrets file") | ||
root.PersistentFlags().StringVarP(&config.App.System.ContextPath, "context", "x", "./context", "Context DB") | ||
|
||
err := root.MarkPersistentFlagRequired("config") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = root.MarkPersistentFlagFilename("config", "yaml") | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,32 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/KenshiTech/unchained/internal/constants" | ||
"github.com/KenshiTech/unchained/internal/crypto" | ||
"github.com/KenshiTech/unchained/internal/crypto/ethereum" | ||
"github.com/KenshiTech/unchained/internal/log" | ||
"github.com/KenshiTech/unchained/internal/pos" | ||
"github.com/KenshiTech/unchained/internal/transport/server" | ||
"github.com/KenshiTech/unchained/internal/transport/server/websocket" | ||
) | ||
|
||
// Broker starts the Unchained broker and contains its DI. | ||
func Broker() { | ||
log.Logger. | ||
With("Mode", "Broker"). | ||
With("Version", constants.Version). | ||
With("Protocol", constants.ProtocolVersion). | ||
Info("Running Unchained") | ||
|
||
crypto.InitMachineIdentity( | ||
crypto.WithBlsIdentity(), | ||
crypto.WithEvmSigner(), | ||
) | ||
|
||
ethRPC := ethereum.New() | ||
pos.New(ethRPC) | ||
|
||
server.New( | ||
websocket.WithWebsocket(), | ||
) | ||
} |
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,49 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/KenshiTech/unchained/internal/constants" | ||
"github.com/KenshiTech/unchained/internal/crypto" | ||
"github.com/KenshiTech/unchained/internal/crypto/ethereum" | ||
"github.com/KenshiTech/unchained/internal/db" | ||
"github.com/KenshiTech/unchained/internal/log" | ||
"github.com/KenshiTech/unchained/internal/pos" | ||
correctnessService "github.com/KenshiTech/unchained/internal/service/correctness" | ||
evmlogService "github.com/KenshiTech/unchained/internal/service/evmlog" | ||
uniswapService "github.com/KenshiTech/unchained/internal/service/uniswap" | ||
"github.com/KenshiTech/unchained/internal/transport/client" | ||
"github.com/KenshiTech/unchained/internal/transport/client/conn" | ||
"github.com/KenshiTech/unchained/internal/transport/client/handler" | ||
"github.com/KenshiTech/unchained/internal/transport/server" | ||
"github.com/KenshiTech/unchained/internal/transport/server/gql" | ||
) | ||
|
||
// Consumer starts the Unchained consumer and contains its DI. | ||
func Consumer() { | ||
log.Logger. | ||
With("Mode", "Consumer"). | ||
With("Version", constants.Version). | ||
With("Protocol", constants.ProtocolVersion). | ||
Info("Running Unchained") | ||
|
||
crypto.InitMachineIdentity( | ||
crypto.WithEvmSigner(), | ||
crypto.WithBlsIdentity(), | ||
) | ||
|
||
ethRPC := ethereum.New() | ||
pos := pos.New(ethRPC) | ||
db.Start() | ||
|
||
correctnessService := correctnessService.New(ethRPC) | ||
evmLogService := evmlogService.New(ethRPC, pos) | ||
uniswapService := uniswapService.New(ethRPC, pos) | ||
|
||
conn.Start() | ||
|
||
handler := handler.NewConsumerHandler(correctnessService, uniswapService, evmLogService) | ||
client.NewRPC(handler) | ||
|
||
server.New( | ||
gql.WithGraphQL(), | ||
) | ||
} |
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,50 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/KenshiTech/unchained/internal/config" | ||
"github.com/KenshiTech/unchained/internal/constants" | ||
"github.com/KenshiTech/unchained/internal/crypto" | ||
"github.com/KenshiTech/unchained/internal/crypto/ethereum" | ||
"github.com/KenshiTech/unchained/internal/log" | ||
"github.com/KenshiTech/unchained/internal/persistence" | ||
"github.com/KenshiTech/unchained/internal/pos" | ||
"github.com/KenshiTech/unchained/internal/scheduler" | ||
evmlogService "github.com/KenshiTech/unchained/internal/service/evmlog" | ||
uniswapService "github.com/KenshiTech/unchained/internal/service/uniswap" | ||
"github.com/KenshiTech/unchained/internal/transport/client" | ||
"github.com/KenshiTech/unchained/internal/transport/client/conn" | ||
"github.com/KenshiTech/unchained/internal/transport/client/handler" | ||
) | ||
|
||
// Worker starts the Unchained worker and contains its DI. | ||
func Worker() { | ||
log.Logger. | ||
With("Mode", "Worker"). | ||
With("Version", constants.Version). | ||
With("Protocol", constants.ProtocolVersion). | ||
Info("Running Unchained") | ||
|
||
crypto.InitMachineIdentity( | ||
crypto.WithEvmSigner(), | ||
crypto.WithBlsIdentity(), | ||
) | ||
|
||
ethRPC := ethereum.New() | ||
pos := pos.New(ethRPC) | ||
badger := persistence.New(config.App.System.ContextPath) | ||
|
||
evmLogService := evmlogService.New(ethRPC, pos) | ||
uniswapService := uniswapService.New(ethRPC, pos) | ||
|
||
scheduler := scheduler.New( | ||
scheduler.WithEthLogs(evmLogService, ethRPC, badger), | ||
scheduler.WithUniswapEvents(uniswapService, ethRPC), | ||
) | ||
|
||
conn.Start() | ||
|
||
handler := handler.NewWorkerHandler() | ||
client.NewRPC(handler) | ||
|
||
scheduler.Start() | ||
} |
Oops, something went wrong.