forked from ethereum/ecp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
117 lines (104 loc) · 2.26 KB
/
main.go
File metadata and controls
117 lines (104 loc) · 2.26 KB
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
package main
import (
"fmt"
"github.com/codegangsta/cli"
"os"
"runtime"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger"
)
const (
Version = "0.0.2"
)
var (
clilogger = logger.NewLogger("Parser")
app = utils.NewApp(Version, "Ethereum chain parser")
)
func init() {
app.Action = run
app.Name = "BlockParser"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "mongo-url",
Value: "mongodb://localhost",
Usage: "MongoDB connection url",
},
cli.StringFlag{
Name: "mongo-database",
Value: "chain_explorer",
Usage: "MongoDB database",
},
utils.UnlockedAccountFlag,
utils.PasswordFileFlag,
utils.BootnodesFlag,
utils.DataDirFlag,
utils.JSpathFlag,
utils.ListenPortFlag,
utils.LogFileFlag,
utils.LogJSONFlag,
utils.VerbosityFlag,
utils.MaxPeersFlag,
utils.EtherbaseFlag,
utils.BlockchainVersionFlag,
utils.MinerThreadsFlag,
utils.MiningEnabledFlag,
utils.NATFlag,
utils.NodeKeyFileFlag,
utils.NodeKeyHexFlag,
utils.RPCEnabledFlag,
utils.RPCListenAddrFlag,
utils.RPCPortFlag,
utils.VMDebugFlag,
utils.ProtocolVersionFlag,
utils.NetworkIdFlag,
utils.RPCCORSDomainFlag,
utils.BacktraceAtFlag,
utils.LogToStdErrFlag,
}
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
defer logger.Flush()
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run(ctx *cli.Context) {
importer := NewImporter(ctx)
utils.HandleInterrupt()
cfg := utils.MakeEthConfig("EthChainParser", Version, ctx)
ethereum, err := eth.New(cfg)
if err != nil {
utils.Fatalf("%v", err)
}
utils.StartEthereum(ethereum)
if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
utils.StartRPC(ethereum, ctx)
}
events := ethereum.EventMux().Subscribe(
core.ChainEvent{},
core.TxPreEvent{},
)
defer events.Unsubscribe()
for {
select {
case ev, isopen := <-events.Chan():
if !isopen {
return
}
switch ev := ev.(type) {
case core.ChainEvent:
importer.importBlock(ev.Block)
case core.TxPreEvent:
// Not dealing with incoming txes for now
//importer.importTx(ev.Tx)
}
}
}
ethereum.WaitForShutdown()
logger.Flush()
fmt.Printf("Shutting down\n")
}