forked from ledgerwatch/erigon
/
daemon.go
158 lines (149 loc) · 4.16 KB
/
daemon.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package jsonrpc
import (
"github.com/nebojsa94/erigon/erigon-lib/gointerfaces/txpool"
"github.com/nebojsa94/erigon/erigon-lib/kv"
"github.com/nebojsa94/erigon/erigon-lib/kv/kvcache"
libstate "github.com/nebojsa94/erigon/erigon-lib/state"
"github.com/nebojsa94/erigon/cmd/rpcdaemon/cli/httpcfg"
"github.com/nebojsa94/erigon/consensus"
"github.com/nebojsa94/erigon/consensus/bor"
"github.com/nebojsa94/erigon/consensus/clique"
"github.com/nebojsa94/erigon/rpc"
"github.com/nebojsa94/erigon/turbo/rpchelper"
"github.com/nebojsa94/erigon/turbo/services"
"github.com/ledgerwatch/log/v3"
)
// APIList describes the list of available RPC apis
func APIList(db kv.RoDB, eth rpchelper.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient,
filters *rpchelper.Filters, stateCache kvcache.Cache,
blockReader services.FullBlockReader, agg *libstate.AggregatorV3, cfg *httpcfg.HttpCfg, engine consensus.EngineReader,
logger log.Logger,
) (list []rpc.API) {
base := NewBaseApi(filters, stateCache, blockReader, agg, cfg.WithDatadir, cfg.EvmCallTimeout, engine, cfg.Dirs)
ethImpl := NewEthAPI(base, db, eth, txPool, mining, cfg.Gascap, cfg.ReturnDataLimit, cfg.AllowUnprotectedTxs, cfg.MaxGetProofRewindBlockCount, logger)
erigonImpl := NewErigonAPI(base, db, eth)
txpoolImpl := NewTxPoolAPI(base, db, txPool)
netImpl := NewNetAPIImpl(eth)
debugImpl := NewPrivateDebugAPI(base, db, cfg.Gascap)
traceImpl := NewTraceAPI(base, db, cfg)
web3Impl := NewWeb3APIImpl(eth)
dbImpl := NewDBAPIImpl() /* deprecated */
adminImpl := NewAdminAPI(eth)
parityImpl := NewParityAPIImpl(base, db)
var borImpl *BorImpl
type lazy interface {
HasEngine() bool
Engine() consensus.EngineReader
}
switch engine := engine.(type) {
case *bor.Bor:
borImpl = NewBorAPI(base, db)
case lazy:
if _, ok := engine.Engine().(*bor.Bor); !engine.HasEngine() || ok {
borImpl = NewBorAPI(base, db)
}
}
otsImpl := NewOtterscanAPI(base, db, cfg.OtsMaxPageSize)
gqlImpl := NewGraphQLAPI(base, db)
if cfg.GraphQLEnabled {
list = append(list, rpc.API{
Namespace: "graphql",
Public: true,
Service: GraphQLAPI(gqlImpl),
Version: "1.0",
})
}
for _, enabledAPI := range cfg.API {
switch enabledAPI {
case "eth":
list = append(list, rpc.API{
Namespace: "eth",
Public: true,
Service: EthAPI(ethImpl),
Version: "1.0",
})
case "debug":
list = append(list, rpc.API{
Namespace: "debug",
Public: true,
Service: PrivateDebugAPI(debugImpl),
Version: "1.0",
})
case "net":
list = append(list, rpc.API{
Namespace: "net",
Public: true,
Service: NetAPI(netImpl),
Version: "1.0",
})
case "txpool":
list = append(list, rpc.API{
Namespace: "txpool",
Public: true,
Service: TxPoolAPI(txpoolImpl),
Version: "1.0",
})
case "web3":
list = append(list, rpc.API{
Namespace: "web3",
Public: true,
Service: Web3API(web3Impl),
Version: "1.0",
})
case "trace":
list = append(list, rpc.API{
Namespace: "trace",
Public: true,
Service: TraceAPI(traceImpl),
Version: "1.0",
})
case "db": /* Deprecated */
list = append(list, rpc.API{
Namespace: "db",
Public: true,
Service: DBAPI(dbImpl),
Version: "1.0",
})
case "erigon":
list = append(list, rpc.API{
Namespace: "erigon",
Public: true,
Service: ErigonAPI(erigonImpl),
Version: "1.0",
})
case "bor":
if borImpl != nil {
list = append(list, rpc.API{
Namespace: "bor",
Public: true,
Service: BorAPI(borImpl),
Version: "1.0",
})
}
case "admin":
list = append(list, rpc.API{
Namespace: "admin",
Public: false,
Service: AdminAPI(adminImpl),
Version: "1.0",
})
case "parity":
list = append(list, rpc.API{
Namespace: "parity",
Public: false,
Service: ParityAPI(parityImpl),
Version: "1.0",
})
case "ots":
list = append(list, rpc.API{
Namespace: "ots",
Public: true,
Service: OtterscanAPI(otsImpl),
Version: "1.0",
})
case "clique":
list = append(list, clique.NewCliqueAPI(db, engine, blockReader))
}
}
return list
}