forked from nolash/ethereum-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
C1_Stack.go
44 lines (36 loc) · 896 Bytes
/
C1_Stack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// set up boilerplate service node and start it
package main
import (
"fmt"
"os"
"github.com/ethereum/go-ethereum/node"
demo "github.com/nolash/go-ethereum-p2p-demo/common"
)
const (
p2pDefaultPort = 30100
ipcpath = ".demo.ipc"
datadirPrefix = ".data_"
)
func main() {
// set up the service node
cfg := &node.DefaultConfig
cfg.P2P.ListenAddr = fmt.Sprintf(":%d", p2pDefaultPort)
cfg.IPCPath = ipcpath
cfg.DataDir = fmt.Sprintf("%s%d", datadirPrefix, p2pDefaultPort)
// create the node instance with the config
stack, err := node.New(cfg)
if err != nil {
demo.Log.Crit("ServiceNode create fail", "err", err)
}
// start the node
err = stack.Start()
if err != nil {
demo.Log.Crit("ServiceNode start fail", "err", err)
}
defer os.RemoveAll(stack.DataDir())
// shut down
err = stack.Stop()
if err != nil {
demo.Log.Crit("Node stop fail", "err", err)
}
}