aboutsummaryrefslogtreecommitdiffstats
path: root/node/node.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-08-16 00:38:32 +0800
committerFelix Lange <fjl@twurst.com>2016-08-17 23:39:03 +0800
commit312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e (patch)
treee10f9cc260af1ce13cb67b02bbce9c17c3b09de2 /node/node.go
parentd6625ac34dad741f5659ca1dad3b0179603d37f0 (diff)
downloaddexon-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.gz
dexon-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.zst
dexon-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.zip
cmd/utils, node: create account manager in package node
The account manager was previously created by packge cmd/utils as part of flag processing and then passed down into eth.Ethereum through its config struct. Since we are starting to create nodes which do not have eth.Ethereum as a registered service, the code was rearranged to register the account manager as its own service. Making it a service is ugly though and it doesn't really fix the root cause: creating nodes without eth.Ethereum requires duplicating lots of code. This commit splits utils.MakeSystemNode into three functions, making creation of other node/service configurations easier. It also moves the account manager into Node so it can be used by those configurations without requiring package eth.
Diffstat (limited to 'node/node.go')
-rw-r--r--node/node.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/node/node.go b/node/node.go
index ac8a7e8f0..f3be2f763 100644
--- a/node/node.go
+++ b/node/node.go
@@ -26,6 +26,7 @@ import (
"sync"
"syscall"
+ "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/logger"
@@ -49,6 +50,9 @@ type Node struct {
datadir string // Path to the currently used data directory
eventmux *event.TypeMux // Event multiplexer used between the services of a stack
+ accman *accounts.Manager
+ ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop
+
serverConfig p2p.Config
server *p2p.Server // Currently running P2P networking layer
@@ -90,13 +94,20 @@ func New(conf *Config) (*Node, error) {
return nil, err
}
}
+ am, ephemeralKeystore, err := makeAccountManager(conf)
+ if err != nil {
+ return nil, err
+ }
+
// Assemble the networking layer and the node itself
nodeDbPath := ""
if conf.DataDir != "" {
nodeDbPath = filepath.Join(conf.DataDir, datadirNodeDatabase)
}
return &Node{
- datadir: conf.DataDir,
+ datadir: conf.DataDir,
+ accman: am,
+ ephemeralKeystore: ephemeralKeystore,
serverConfig: p2p.Config{
PrivateKey: conf.NodeKey(),
Name: conf.Name,
@@ -156,9 +167,10 @@ func (n *Node) Start() error {
for _, constructor := range n.serviceFuncs {
// Create a new context for the particular service
ctx := &ServiceContext{
- datadir: n.datadir,
- services: make(map[reflect.Type]Service),
- EventMux: n.eventmux,
+ datadir: n.datadir,
+ services: make(map[reflect.Type]Service),
+ EventMux: n.eventmux,
+ AccountManager: n.accman,
}
for kind, s := range services { // copy needed for threaded access
ctx.services[kind] = s
@@ -473,9 +485,18 @@ func (n *Node) Stop() error {
n.server = nil
close(n.stop)
+ // Remove the keystore if it was created ephemerally.
+ var keystoreErr error
+ if n.ephemeralKeystore != "" {
+ keystoreErr = os.RemoveAll(n.ephemeralKeystore)
+ }
+
if len(failure.Services) > 0 {
return failure
}
+ if keystoreErr != nil {
+ return keystoreErr
+ }
return nil
}
@@ -548,6 +569,11 @@ func (n *Node) DataDir() string {
return n.datadir
}
+// AccountManager retrieves the account manager used by the protocol stack.
+func (n *Node) AccountManager() *accounts.Manager {
+ return n.accman
+}
+
// IPCEndpoint retrieves the current IPC endpoint used by the protocol stack.
func (n *Node) IPCEndpoint() string {
return n.ipcEndpoint