forked from coinbase/mesh-geth-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
137 lines (108 loc) · 4.08 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
// 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 (
"github.com/ubiq/go-ubiq/v7/params"
RosettaTypes "github.com/ubiq/rosetta-sdk-go/types"
)
// 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
// Currency is the native currency blockchain supports
Currency *RosettaTypes.Currency
IngestionMode string
IndexUnknownTokens bool
TokenWhiteList []Token
}
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"
)
// 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
}