Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
fdb74241
Unverified
Commit
fdb74241
authored
4 years ago
by
Binacs
Committed by
GitHub
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/clef, cmd/geth: use SplitAndTrim from cmd/utils (#21579)
parent
129cf075
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
60 deletions
+28
-60
main.go
cmd/clef/main.go
+3
-23
retesteth.go
cmd/geth/retesteth.go
+2
-13
customflags.go
cmd/utils/customflags.go
+2
-2
flags.go
cmd/utils/flags.go
+21
-22
No files found.
cmd/clef/main.go
View file @
fdb74241
...
...
@@ -29,7 +29,6 @@ import (
"math/big"
"os"
"os/signal"
"os/user"
"path/filepath"
"runtime"
"sort"
...
...
@@ -666,8 +665,8 @@ func signer(c *cli.Context) error {
Version
:
"1.0"
},
}
if
c
.
GlobalBool
(
utils
.
HTTPEnabledFlag
.
Name
)
{
vhosts
:=
s
plitAndTrim
(
c
.
GlobalString
(
utils
.
HTTPVirtualHostsFlag
.
Name
))
cors
:=
s
plitAndTrim
(
c
.
GlobalString
(
utils
.
HTTPCORSDomainFlag
.
Name
))
vhosts
:=
utils
.
S
plitAndTrim
(
c
.
GlobalString
(
utils
.
HTTPVirtualHostsFlag
.
Name
))
cors
:=
utils
.
S
plitAndTrim
(
c
.
GlobalString
(
utils
.
HTTPCORSDomainFlag
.
Name
))
srv
:=
rpc
.
NewServer
()
err
:=
node
.
RegisterApisFromWhitelist
(
rpcAPI
,
[]
string
{
"account"
},
srv
,
false
)
...
...
@@ -736,21 +735,11 @@ func signer(c *cli.Context) error {
return
nil
}
// splitAndTrim splits input separated by a comma
// and trims excessive white space from the substrings.
func
splitAndTrim
(
input
string
)
[]
string
{
result
:=
strings
.
Split
(
input
,
","
)
for
i
,
r
:=
range
result
{
result
[
i
]
=
strings
.
TrimSpace
(
r
)
}
return
result
}
// DefaultConfigDir is the default config directory to use for the vaults and other
// persistence requirements.
func
DefaultConfigDir
()
string
{
// Try to place the data folder in the user's home dir
home
:=
h
omeDir
()
home
:=
utils
.
H
omeDir
()
if
home
!=
""
{
if
runtime
.
GOOS
==
"darwin"
{
return
filepath
.
Join
(
home
,
"Library"
,
"Signer"
)
...
...
@@ -769,15 +758,6 @@ func DefaultConfigDir() string {
return
""
}
func
homeDir
()
string
{
if
home
:=
os
.
Getenv
(
"HOME"
);
home
!=
""
{
return
home
}
if
usr
,
err
:=
user
.
Current
();
err
==
nil
{
return
usr
.
HomeDir
}
return
""
}
func
readMasterKey
(
ctx
*
cli
.
Context
,
ui
core
.
UIClientAPI
)
([]
byte
,
error
)
{
var
(
file
string
...
...
This diff is collapsed.
Click to expand it.
cmd/geth/retesteth.go
View file @
fdb74241
...
...
@@ -23,7 +23,6 @@ import (
"math/big"
"os"
"os/signal"
"strings"
"time"
"github.com/ethereum/go-ethereum/cmd/utils"
...
...
@@ -840,16 +839,6 @@ func (api *RetestethAPI) ClientVersion(ctx context.Context) (string, error) {
return
"Geth-"
+
params
.
VersionWithCommit
(
gitCommit
,
gitDate
),
nil
}
// splitAndTrim splits input separated by a comma
// and trims excessive white space from the substrings.
func
splitAndTrim
(
input
string
)
[]
string
{
result
:=
strings
.
Split
(
input
,
","
)
for
i
,
r
:=
range
result
{
result
[
i
]
=
strings
.
TrimSpace
(
r
)
}
return
result
}
func
retesteth
(
ctx
*
cli
.
Context
)
error
{
log
.
Info
(
"Welcome to retesteth!"
)
// register signer API with server
...
...
@@ -887,8 +876,8 @@ func retesteth(ctx *cli.Context) error {
Version
:
"1.0"
,
},
}
vhosts
:=
s
plitAndTrim
(
ctx
.
GlobalString
(
utils
.
HTTPVirtualHostsFlag
.
Name
))
cors
:=
s
plitAndTrim
(
ctx
.
GlobalString
(
utils
.
HTTPCORSDomainFlag
.
Name
))
vhosts
:=
utils
.
S
plitAndTrim
(
ctx
.
GlobalString
(
utils
.
HTTPVirtualHostsFlag
.
Name
))
cors
:=
utils
.
S
plitAndTrim
(
ctx
.
GlobalString
(
utils
.
HTTPCORSDomainFlag
.
Name
))
// register apis and create handler stack
srv
:=
rpc
.
NewServer
()
...
...
This diff is collapsed.
Click to expand it.
cmd/utils/customflags.go
View file @
fdb74241
...
...
@@ -192,14 +192,14 @@ func GlobalBig(ctx *cli.Context, name string) *big.Int {
// Note, it has limitations, e.g. ~someuser/tmp will not be expanded
func
expandPath
(
p
string
)
string
{
if
strings
.
HasPrefix
(
p
,
"~/"
)
||
strings
.
HasPrefix
(
p
,
"~
\\
"
)
{
if
home
:=
h
omeDir
();
home
!=
""
{
if
home
:=
H
omeDir
();
home
!=
""
{
p
=
home
+
p
[
1
:
]
}
}
return
path
.
Clean
(
os
.
ExpandEnv
(
p
))
}
func
h
omeDir
()
string
{
func
H
omeDir
()
string
{
if
home
:=
os
.
Getenv
(
"HOME"
);
home
!=
""
{
return
home
}
...
...
This diff is collapsed.
Click to expand it.
cmd/utils/flags.go
View file @
fdb74241
...
...
@@ -162,7 +162,7 @@ var (
DocRootFlag
=
DirectoryFlag
{
Name
:
"docroot"
,
Usage
:
"Document Root for HTTPClient file scheme"
,
Value
:
DirectoryString
(
h
omeDir
()),
Value
:
DirectoryString
(
H
omeDir
()),
}
ExitWhenSyncedFlag
=
cli
.
BoolFlag
{
Name
:
"exitwhensynced"
,
...
...
@@ -793,9 +793,9 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
switch
{
case
ctx
.
GlobalIsSet
(
BootnodesFlag
.
Name
)
||
ctx
.
GlobalIsSet
(
LegacyBootnodesV4Flag
.
Name
)
:
if
ctx
.
GlobalIsSet
(
LegacyBootnodesV4Flag
.
Name
)
{
urls
=
s
plitAndTrim
(
ctx
.
GlobalString
(
LegacyBootnodesV4Flag
.
Name
))
urls
=
S
plitAndTrim
(
ctx
.
GlobalString
(
LegacyBootnodesV4Flag
.
Name
))
}
else
{
urls
=
s
plitAndTrim
(
ctx
.
GlobalString
(
BootnodesFlag
.
Name
))
urls
=
S
plitAndTrim
(
ctx
.
GlobalString
(
BootnodesFlag
.
Name
))
}
case
ctx
.
GlobalBool
(
LegacyTestnetFlag
.
Name
)
||
ctx
.
GlobalBool
(
RopstenFlag
.
Name
)
:
urls
=
params
.
RopstenBootnodes
...
...
@@ -829,9 +829,9 @@ func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
switch
{
case
ctx
.
GlobalIsSet
(
BootnodesFlag
.
Name
)
||
ctx
.
GlobalIsSet
(
LegacyBootnodesV5Flag
.
Name
)
:
if
ctx
.
GlobalIsSet
(
LegacyBootnodesV5Flag
.
Name
)
{
urls
=
s
plitAndTrim
(
ctx
.
GlobalString
(
LegacyBootnodesV5Flag
.
Name
))
urls
=
S
plitAndTrim
(
ctx
.
GlobalString
(
LegacyBootnodesV5Flag
.
Name
))
}
else
{
urls
=
s
plitAndTrim
(
ctx
.
GlobalString
(
BootnodesFlag
.
Name
))
urls
=
S
plitAndTrim
(
ctx
.
GlobalString
(
BootnodesFlag
.
Name
))
}
case
ctx
.
GlobalBool
(
RopstenFlag
.
Name
)
:
urls
=
params
.
RopstenBootnodes
...
...
@@ -877,13 +877,12 @@ func setNAT(ctx *cli.Context, cfg *p2p.Config) {
}
}
//
s
plitAndTrim splits input separated by a comma
//
S
plitAndTrim splits input separated by a comma
// and trims excessive white space from the substrings.
func
s
plitAndTrim
(
input
string
)
(
ret
[]
string
)
{
func
S
plitAndTrim
(
input
string
)
(
ret
[]
string
)
{
l
:=
strings
.
Split
(
input
,
","
)
for
_
,
r
:=
range
l
{
r
=
strings
.
TrimSpace
(
r
)
if
len
(
r
)
>
0
{
if
r
=
strings
.
TrimSpace
(
r
);
r
!=
""
{
ret
=
append
(
ret
,
r
)
}
}
...
...
@@ -917,27 +916,27 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
}
if
ctx
.
GlobalIsSet
(
LegacyRPCCORSDomainFlag
.
Name
)
{
cfg
.
HTTPCors
=
s
plitAndTrim
(
ctx
.
GlobalString
(
LegacyRPCCORSDomainFlag
.
Name
))
cfg
.
HTTPCors
=
S
plitAndTrim
(
ctx
.
GlobalString
(
LegacyRPCCORSDomainFlag
.
Name
))
log
.
Warn
(
"The flag --rpccorsdomain is deprecated and will be removed in the future, please use --http.corsdomain"
)
}
if
ctx
.
GlobalIsSet
(
HTTPCORSDomainFlag
.
Name
)
{
cfg
.
HTTPCors
=
s
plitAndTrim
(
ctx
.
GlobalString
(
HTTPCORSDomainFlag
.
Name
))
cfg
.
HTTPCors
=
S
plitAndTrim
(
ctx
.
GlobalString
(
HTTPCORSDomainFlag
.
Name
))
}
if
ctx
.
GlobalIsSet
(
LegacyRPCApiFlag
.
Name
)
{
cfg
.
HTTPModules
=
s
plitAndTrim
(
ctx
.
GlobalString
(
LegacyRPCApiFlag
.
Name
))
cfg
.
HTTPModules
=
S
plitAndTrim
(
ctx
.
GlobalString
(
LegacyRPCApiFlag
.
Name
))
log
.
Warn
(
"The flag --rpcapi is deprecated and will be removed in the future, please use --http.api"
)
}
if
ctx
.
GlobalIsSet
(
HTTPApiFlag
.
Name
)
{
cfg
.
HTTPModules
=
s
plitAndTrim
(
ctx
.
GlobalString
(
HTTPApiFlag
.
Name
))
cfg
.
HTTPModules
=
S
plitAndTrim
(
ctx
.
GlobalString
(
HTTPApiFlag
.
Name
))
}
if
ctx
.
GlobalIsSet
(
LegacyRPCVirtualHostsFlag
.
Name
)
{
cfg
.
HTTPVirtualHosts
=
s
plitAndTrim
(
ctx
.
GlobalString
(
LegacyRPCVirtualHostsFlag
.
Name
))
cfg
.
HTTPVirtualHosts
=
S
plitAndTrim
(
ctx
.
GlobalString
(
LegacyRPCVirtualHostsFlag
.
Name
))
log
.
Warn
(
"The flag --rpcvhosts is deprecated and will be removed in the future, please use --http.vhosts"
)
}
if
ctx
.
GlobalIsSet
(
HTTPVirtualHostsFlag
.
Name
)
{
cfg
.
HTTPVirtualHosts
=
s
plitAndTrim
(
ctx
.
GlobalString
(
HTTPVirtualHostsFlag
.
Name
))
cfg
.
HTTPVirtualHosts
=
S
plitAndTrim
(
ctx
.
GlobalString
(
HTTPVirtualHostsFlag
.
Name
))
}
}
...
...
@@ -945,10 +944,10 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
// command line flags, returning empty if the GraphQL endpoint is disabled.
func
setGraphQL
(
ctx
*
cli
.
Context
,
cfg
*
node
.
Config
)
{
if
ctx
.
GlobalIsSet
(
GraphQLCORSDomainFlag
.
Name
)
{
cfg
.
GraphQLCors
=
s
plitAndTrim
(
ctx
.
GlobalString
(
GraphQLCORSDomainFlag
.
Name
))
cfg
.
GraphQLCors
=
S
plitAndTrim
(
ctx
.
GlobalString
(
GraphQLCORSDomainFlag
.
Name
))
}
if
ctx
.
GlobalIsSet
(
GraphQLVirtualHostsFlag
.
Name
)
{
cfg
.
GraphQLVirtualHosts
=
s
plitAndTrim
(
ctx
.
GlobalString
(
GraphQLVirtualHostsFlag
.
Name
))
cfg
.
GraphQLVirtualHosts
=
S
plitAndTrim
(
ctx
.
GlobalString
(
GraphQLVirtualHostsFlag
.
Name
))
}
}
...
...
@@ -974,19 +973,19 @@ func setWS(ctx *cli.Context, cfg *node.Config) {
}
if
ctx
.
GlobalIsSet
(
LegacyWSAllowedOriginsFlag
.
Name
)
{
cfg
.
WSOrigins
=
s
plitAndTrim
(
ctx
.
GlobalString
(
LegacyWSAllowedOriginsFlag
.
Name
))
cfg
.
WSOrigins
=
S
plitAndTrim
(
ctx
.
GlobalString
(
LegacyWSAllowedOriginsFlag
.
Name
))
log
.
Warn
(
"The flag --wsorigins is deprecated and will be removed in the future, please use --ws.origins"
)
}
if
ctx
.
GlobalIsSet
(
WSAllowedOriginsFlag
.
Name
)
{
cfg
.
WSOrigins
=
s
plitAndTrim
(
ctx
.
GlobalString
(
WSAllowedOriginsFlag
.
Name
))
cfg
.
WSOrigins
=
S
plitAndTrim
(
ctx
.
GlobalString
(
WSAllowedOriginsFlag
.
Name
))
}
if
ctx
.
GlobalIsSet
(
LegacyWSApiFlag
.
Name
)
{
cfg
.
WSModules
=
s
plitAndTrim
(
ctx
.
GlobalString
(
LegacyWSApiFlag
.
Name
))
cfg
.
WSModules
=
S
plitAndTrim
(
ctx
.
GlobalString
(
LegacyWSApiFlag
.
Name
))
log
.
Warn
(
"The flag --wsapi is deprecated and will be removed in the future, please use --ws.api"
)
}
if
ctx
.
GlobalIsSet
(
WSApiFlag
.
Name
)
{
cfg
.
WSModules
=
s
plitAndTrim
(
ctx
.
GlobalString
(
WSApiFlag
.
Name
))
cfg
.
WSModules
=
S
plitAndTrim
(
ctx
.
GlobalString
(
WSApiFlag
.
Name
))
}
}
...
...
@@ -1580,7 +1579,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if
urls
==
""
{
cfg
.
DiscoveryURLs
=
[]
string
{}
}
else
{
cfg
.
DiscoveryURLs
=
s
plitAndTrim
(
urls
)
cfg
.
DiscoveryURLs
=
S
plitAndTrim
(
urls
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment