diff --git a/discovery/node.go b/discovery/node.go new file mode 100644 index 0000000..80e1348 --- /dev/null +++ b/discovery/node.go @@ -0,0 +1,3 @@ +package discovery + +type node struct{} diff --git a/node/config.go b/node/config.go new file mode 100644 index 0000000..7aae359 --- /dev/null +++ b/node/config.go @@ -0,0 +1,3 @@ +package node + +const SyncModeDefault = "default" diff --git a/node/node.go b/node/node.go new file mode 100644 index 0000000..1d9bac0 --- /dev/null +++ b/node/node.go @@ -0,0 +1,67 @@ +package node + +import ( + "context" + "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/p2p" + "github.com/rovergulf/chain/pkg/logutils" + "github.com/rovergulf/chain/pkg/traceutils" + "github.com/rovergulf/chain/wallets" + "github.com/spf13/viper" + "go.opentelemetry.io/otel/trace" + "go.uber.org/zap" + "os" +) + +type Node struct { + logger *zap.SugaredLogger + tracer trace.Tracer + + walletsManager *wallets.Manager + + key *keystore.Key + + peer *p2p.Peer +} + +func New() (*Node, error) { + zapLogger, err := logutils.NewLogger() + if err != nil { + return nil, err + } + + var traceProvider trace.TracerProvider + jaegerTraceUrl := viper.GetString(traceutils.CollectorUrlConfigKey) + if len(jaegerTraceUrl) > 0 { + if traceProvider, err = traceutils.NewJaegerProvider(jaegerTraceUrl); err != nil { + return nil, err + } + } + + n := &Node{ + logger: zapLogger, + } + + if traceProvider != nil { + n.tracer = traceProvider.Tracer("node") + } + + wm, err := wallets.NewManager() + if err != nil { + zapLogger.Errorw("Unable to init wallets manager", "err", err) + return nil, err + } + n.walletsManager = wm + + //n.peer = p2p.NewPeer(enode.PubkeyToIDV4()) + + return n, nil +} + +func (n *Node) GracefulShutdown(ctx context.Context, sig string) { + defer ctx.Done() + + n.logger.Warnw("Graceful shutdown signal received", "sig", sig) + + os.Exit(0) +} diff --git a/node/rpcstack.go b/node/rpcstack.go new file mode 100644 index 0000000..2b4023a --- /dev/null +++ b/node/rpcstack.go @@ -0,0 +1 @@ +package node