-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.go
86 lines (77 loc) · 2.38 KB
/
server.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
// Copyright 2020 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
package jsonrpc
import (
"time"
"github.com/ethereum/go-ethereum/rpc"
"github.com/iotaledger/wasp/packages/metrics"
)
type Parameters struct {
Logs LogsLimits
WebsocketRateLimitMessagesPerSecond int
WebsocketRateLimitBurst int
WebsocketRateLimitEnabled bool
WebsocketConnectionCleanupDuration time.Duration
WebsocketClientBlockDuration time.Duration
}
func NewParameters(
maxBlocksInLogsFilterRange int,
maxLogsInResult int,
websocketRateLimitMessagesPerSecond int,
websocketRateLimitBurst int,
websocketConnectionCleanupDuration time.Duration,
websocketClientBlockDuration time.Duration,
WebsocketRateLimitEnabled bool,
) *Parameters {
return &Parameters{
Logs: LogsLimits{
MaxBlocksInLogsFilterRange: maxBlocksInLogsFilterRange,
MaxLogsInResult: maxLogsInResult,
},
WebsocketRateLimitMessagesPerSecond: websocketRateLimitMessagesPerSecond,
WebsocketRateLimitBurst: websocketRateLimitBurst,
WebsocketRateLimitEnabled: WebsocketRateLimitEnabled,
WebsocketConnectionCleanupDuration: websocketConnectionCleanupDuration,
WebsocketClientBlockDuration: websocketClientBlockDuration,
}
}
func ParametersDefault() *Parameters {
return &Parameters{
Logs: LogsLimits{
MaxBlocksInLogsFilterRange: 1000,
MaxLogsInResult: 10000,
},
WebsocketRateLimitMessagesPerSecond: 20,
WebsocketRateLimitBurst: 5,
WebsocketRateLimitEnabled: true,
WebsocketConnectionCleanupDuration: 5 * time.Minute,
WebsocketClientBlockDuration: 5 * time.Minute,
}
}
func NewServer(
evmChain *EVMChain,
accountManager *AccountManager,
metrics *metrics.ChainWebAPIMetrics,
params *Parameters,
) (*rpc.Server, error) {
chainID := evmChain.ChainID()
rpcsrv := rpc.NewServer()
for _, srv := range []struct {
namespace string
service interface{}
}{
{"web3", NewWeb3Service()},
{"net", NewNetService(int(chainID))},
{"eth", NewEthService(evmChain, accountManager, metrics, params)},
{"debug", NewDebugService(evmChain, metrics)},
{"txpool", NewTxPoolService()},
{"evm", NewEVMService(evmChain)},
{"trace", NewTraceService(evmChain, metrics)},
} {
err := rpcsrv.RegisterName(srv.namespace, srv.service)
if err != nil {
return nil, err
}
}
return rpcsrv, nil
}