Skip to content

Commit

Permalink
Prepare node packages
Browse files Browse the repository at this point in the history
  • Loading branch information
scDisorder committed Dec 13, 2022
1 parent 6732d70 commit bcab966
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions discovery/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package discovery

type node struct{}
3 changes: 3 additions & 0 deletions node/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package node

const SyncModeDefault = "default"
67 changes: 67 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions node/rpcstack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package node

0 comments on commit bcab966

Please sign in to comment.