forked from coinbase/mesh-geth-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
173 lines (132 loc) · 5.18 KB
/
configuration.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2022 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package configuration
import (
"math/big"
RosettaTypes "github.com/coinbase/rosetta-sdk-go/types"
"github.com/ethereum/go-ethereum/params"
)
// Configuration determines how the we setup the blockchain and Rosetta server
type Configuration struct {
// Mode is the setting that determines if
// the implementation is "online" or "offline".
Mode Mode
// NetworkIdentifier specifies which network our Rosetta server uses
Network *RosettaTypes.NetworkIdentifier
// GenesisBlockIdentifier is the genesis block
GenesisBlockIdentifier *RosettaTypes.BlockIdentifier
// GethURL is the blockchain node we are connecting to
GethURL string
// RemoteGeth indicates whether we are using a local or remote blockchain node
RemoteGeth bool
// Port is the Rosetta server's listening port
Port int
// SkipGethAdminEnv is an optional environment variable
// to skip geth `admin` calls which are typically not supported
// by hosted node services. When not set, defaults to false.
SkipGethAdmin bool
// GethArguments are the arguments to start a blockchain instance.
GethArguments string
// ChainConfig is the core config which determines the blockchain settings.
ChainConfig *params.ChainConfig
// RosettaCfg defines the config that used to implement Rosetta APIs
RosettaCfg RosettaConfig
}
type RosettaConfig struct {
// SupportRewardTx indicates whether the blockchain supports block reward
SupportRewardTx bool
// TraceType sets which type of tracing the blockchain supports
// The options are: GethNativeTrace, GethJsTrace, and OpenEthereumTrace
TraceType int
// SupportsSyncing indicates if the blockchain support eth_syncing RPC or not.
// Status syncing is used in Rosetta /network/status api
SupportsSyncing bool
// SupportsPeering indicates if the blockchain support admin_peers RPC or not.
// Peers retrieving is used in Rosetta /network/status api
SupportsPeering bool
// SupportsBlockAuthor indicates if blockchain supports author
SupportsBlockAuthor bool
// SupportsEIP1559 indicates if the blockchain supports EIP-1559
SupportsEIP1559 bool
// SupportsOpStack indicates if the blockchain supports OP stack
SupportsOpStack bool
// Currency is the native currency blockchain supports
Currency *RosettaTypes.Currency
// TracePrefix is the prefix appended to trace RPC calls
TracePrefix string
// IngestionMode indicates if blockchain ingestion mode
IngestionMode string
// IndexUnknownTokens determines whether we parse unknown ERC20 tokens
IndexUnknownTokens bool
// FilterToken determines whether we using our token whitelist
FilterTokens bool
// TokenWhiteList is a list of ERC20 tokens we only support
TokenWhiteList []Token
// DefaultBlockNumber is the default block number if block identifier is not specified
// This is mainly used for Optimism and Base, it can be "safe" or "finalized" to avoid reorg issues
DefaultBlockNumber string
// BaseFeeFloor is the floor base fee for EIP-1559
BaseFeeFloor *big.Int
// BaseFeeMultiplier is the multiplier of base fee for EIP-1559
BaseFeeMultiplier *big.Int
// PriorityFeeDivisor is the divisor of priority fee for EIP-1559
PriorityFeeDivisor *big.Int
}
type Token struct {
ChainID uint64 `json:"chainId"`
Address string `json:"address"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals uint64 `json:"decimals"`
}
// Mode is the setting that determines if
// the implementation is "online" or "offline".
type Mode string
// HTTPHeader is key, value pair to be set on the HTTP and GraphQL SDKClient.
type HTTPHeader struct {
Key string
Value string
}
const (
GethNativeTrace = iota // == 0
GethJsTrace = iota // == 1
OpenEthereumTrace = iota // == 2
ModeOffline = "OFFLINE"
ModeOnline = "ONLINE"
StandardIngestion = "standard"
AnalyticsIngestion = "analytics"
DefaultBaseFeeFloor = 0
DefaultBaseFeeMultiplier = 1
DefaultPriorityFeeDivisor = 1
)
// IsOfflineMode returns true if running in offline mode
func (c Configuration) IsOfflineMode() bool {
return c.Mode == ModeOffline
}
// IsOnlineMode returns true if running in online mode
func (c Configuration) IsOnlineMode() bool {
return c.Mode == ModeOnline
}
// IsStandardMode returns true if running in standard
func (c Configuration) IsStandardMode() bool {
return c.RosettaCfg.IngestionMode == StandardIngestion
}
// IsAnalyticsMode returns true if running in standard
func (c Configuration) IsAnalyticsMode() bool {
return c.RosettaCfg.IngestionMode == AnalyticsIngestion
}
// IsTokenListEmpty returns true if the token addresses list is empty
func (c Configuration) IsTokenListEmpty() bool {
return len(c.RosettaCfg.TokenWhiteList) == 0
}