-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
125 lines (101 loc) · 2.56 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"fmt"
"log"
"os"
"os/signal"
"os/user"
"path"
"runtime"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
)
func DataPath() string {
usr, _ := user.Current()
return path.Join(usr.HomeDir, ".ethereum")
}
var (
Datadir = DataPath()
)
const (
ClientIdentifier = "JeffCoin NC"
Version = "0.1"
ConfigFile = "conf.ini"
Identifier = "Jeff"
LogLevel = 4
OutboundPort = "40404"
MaxPeers = 10
UseSeed = true
)
var logger = ethlog.NewLogger("CLI")
var keyMarager *ethcrypto.KeyManager
var interruptCallbacks = []func(os.Signal){}
func handleInterrupt() {
c := make(chan os.Signal, 1)
go func() {
signal.Notify(c, os.Interrupt)
for sig := range c {
logger.Errorf("Shutting down (%v) ... \n", sig)
for _, cb := range interruptCallbacks {
cb(sig)
}
}
}()
}
func registerInterrupt(cb func(os.Signal)) {
interruptCallbacks = append(interruptCallbacks, cb)
}
func initDataDir(Datadir string) {
_, err := os.Stat(Datadir)
if err != nil {
if os.IsNotExist(err) {
fmt.Printf("Data directory '%s' doesn't Exitst, creating it\n", Datadir)
os.Mkdir(Datadir, 0777)
}
}
}
func main() {
UiInit()
runtime.GOMAXPROCS(runtime.NumCPU())
handleInterrupt()
initDataDir(Datadir)
ethutil.ReadConfig(ConfigFile, Datadir, "ETH")
ethlog.AddLogSystem(ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.LogLevel(LogLevel)))
db, err := ethdb.NewLDBDatabase("database")
if err != nil {
logger.Fatalln(err)
}
keyManager := ethcrypto.NewDBKeyManager(db)
err = keyManager.Init("", 0, false)
if err != nil {
panic(err)
}
fmt.Printf("addr %x\n", keyManager.KeyPair().Address())
clientIdentity := ethwire.NewSimpleClientIdentity(ClientIdentifier, Version, Identifier)
ethereum, err := eth.New(db, clientIdentity, keyManager, eth.CapDefault, false)
if err != nil {
logger.Fatalln("eth start err:", err)
}
ethereum.Port = OutboundPort
ethereum.MaxPeers = MaxPeers
logger.Infof("Starting %s", ethereum.ClientIdentity())
ethereum.Start(UseSeed)
registerInterrupt(func(sig os.Signal) {
ethereum.Stop()
ethlog.Flush()
})
ethereum.ConnectToPeer("localhost:30303")
jeffcoin := New(ethereum, keyManager.KeyPair())
jeffcoin.Start()
container := NewContainer(ethereum, jeffcoin)
if container.Show() != nil {
exit("container err: %v\n", err)
}
// this blocks the thread
//ethereum.WaitForShutdown()
ethlog.Flush()
}