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
195c2d3d
Unverified
Commit
195c2d3d
authored
Apr 26, 2022
by
s7v7nislands
Committed by
GitHub
Apr 26, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/*: refactor get flag value (#24761)
parent
0914234d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
59 deletions
+87
-59
enrcmd.go
cmd/devp2p/enrcmd.go
+4
-2
generate.go
cmd/ethkey/generate.go
+15
-10
inspect.go
cmd/ethkey/inspect.go
+9
-5
message.go
cmd/ethkey/message.go
+1
-1
main.go
cmd/p2psim/main.go
+58
-41
No files found.
cmd/devp2p/enrcmd.go
View file @
195c2d3d
...
@@ -34,18 +34,20 @@ import (
...
@@ -34,18 +34,20 @@ import (
"gopkg.in/urfave/cli.v1"
"gopkg.in/urfave/cli.v1"
)
)
var
fileFlag
=
cli
.
StringFlag
{
Name
:
"file"
}
var
enrdumpCommand
=
cli
.
Command
{
var
enrdumpCommand
=
cli
.
Command
{
Name
:
"enrdump"
,
Name
:
"enrdump"
,
Usage
:
"Pretty-prints node records"
,
Usage
:
"Pretty-prints node records"
,
Action
:
enrdump
,
Action
:
enrdump
,
Flags
:
[]
cli
.
Flag
{
Flags
:
[]
cli
.
Flag
{
cli
.
StringFlag
{
Name
:
"file"
}
,
fileFlag
,
},
},
}
}
func
enrdump
(
ctx
*
cli
.
Context
)
error
{
func
enrdump
(
ctx
*
cli
.
Context
)
error
{
var
source
string
var
source
string
if
file
:=
ctx
.
String
(
"file"
);
file
!=
""
{
if
file
:=
ctx
.
String
(
fileFlag
.
Name
);
file
!=
""
{
if
ctx
.
NArg
()
!=
0
{
if
ctx
.
NArg
()
!=
0
{
return
fmt
.
Errorf
(
"can't dump record from command-line argument in -file mode"
)
return
fmt
.
Errorf
(
"can't dump record from command-line argument in -file mode"
)
}
}
...
...
cmd/ethkey/generate.go
View file @
195c2d3d
...
@@ -35,6 +35,17 @@ type outputGenerate struct {
...
@@ -35,6 +35,17 @@ type outputGenerate struct {
AddressEIP55
string
AddressEIP55
string
}
}
var
(
privateKeyFlag
=
cli
.
StringFlag
{
Name
:
"privatekey"
,
Usage
:
"file containing a raw private key to encrypt"
,
}
lightKDFFlag
=
cli
.
BoolFlag
{
Name
:
"lightkdf"
,
Usage
:
"use less secure scrypt parameters"
,
}
)
var
commandGenerate
=
cli
.
Command
{
var
commandGenerate
=
cli
.
Command
{
Name
:
"generate"
,
Name
:
"generate"
,
Usage
:
"generate new keyfile"
,
Usage
:
"generate new keyfile"
,
...
@@ -48,14 +59,8 @@ If you want to encrypt an existing private key, it can be specified by setting
...
@@ -48,14 +59,8 @@ If you want to encrypt an existing private key, it can be specified by setting
Flags
:
[]
cli
.
Flag
{
Flags
:
[]
cli
.
Flag
{
passphraseFlag
,
passphraseFlag
,
jsonFlag
,
jsonFlag
,
cli
.
StringFlag
{
privateKeyFlag
,
Name
:
"privatekey"
,
lightKDFFlag
,
Usage
:
"file containing a raw private key to encrypt"
,
},
cli
.
BoolFlag
{
Name
:
"lightkdf"
,
Usage
:
"use less secure scrypt parameters"
,
},
},
},
Action
:
func
(
ctx
*
cli
.
Context
)
error
{
Action
:
func
(
ctx
*
cli
.
Context
)
error
{
// Check if keyfile path given and make sure it doesn't already exist.
// Check if keyfile path given and make sure it doesn't already exist.
...
@@ -71,7 +76,7 @@ If you want to encrypt an existing private key, it can be specified by setting
...
@@ -71,7 +76,7 @@ If you want to encrypt an existing private key, it can be specified by setting
var
privateKey
*
ecdsa
.
PrivateKey
var
privateKey
*
ecdsa
.
PrivateKey
var
err
error
var
err
error
if
file
:=
ctx
.
String
(
"privatekey"
);
file
!=
""
{
if
file
:=
ctx
.
String
(
privateKeyFlag
.
Name
);
file
!=
""
{
// Load private key from file.
// Load private key from file.
privateKey
,
err
=
crypto
.
LoadECDSA
(
file
)
privateKey
,
err
=
crypto
.
LoadECDSA
(
file
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -99,7 +104,7 @@ If you want to encrypt an existing private key, it can be specified by setting
...
@@ -99,7 +104,7 @@ If you want to encrypt an existing private key, it can be specified by setting
// Encrypt key with passphrase.
// Encrypt key with passphrase.
passphrase
:=
getPassphrase
(
ctx
,
true
)
passphrase
:=
getPassphrase
(
ctx
,
true
)
scryptN
,
scryptP
:=
keystore
.
StandardScryptN
,
keystore
.
StandardScryptP
scryptN
,
scryptP
:=
keystore
.
StandardScryptN
,
keystore
.
StandardScryptP
if
ctx
.
Bool
(
"lightkdf"
)
{
if
ctx
.
Bool
(
lightKDFFlag
.
Name
)
{
scryptN
,
scryptP
=
keystore
.
LightScryptN
,
keystore
.
LightScryptP
scryptN
,
scryptP
=
keystore
.
LightScryptN
,
keystore
.
LightScryptP
}
}
keyjson
,
err
:=
keystore
.
EncryptKey
(
key
,
passphrase
,
scryptN
,
scryptP
)
keyjson
,
err
:=
keystore
.
EncryptKey
(
key
,
passphrase
,
scryptN
,
scryptP
)
...
...
cmd/ethkey/inspect.go
View file @
195c2d3d
...
@@ -33,6 +33,13 @@ type outputInspect struct {
...
@@ -33,6 +33,13 @@ type outputInspect struct {
PrivateKey
string
PrivateKey
string
}
}
var
(
privateFlag
=
cli
.
BoolFlag
{
Name
:
"private"
,
Usage
:
"include the private key in the output"
,
}
)
var
commandInspect
=
cli
.
Command
{
var
commandInspect
=
cli
.
Command
{
Name
:
"inspect"
,
Name
:
"inspect"
,
Usage
:
"inspect a keyfile"
,
Usage
:
"inspect a keyfile"
,
...
@@ -45,10 +52,7 @@ make sure to use this feature with great caution!`,
...
@@ -45,10 +52,7 @@ make sure to use this feature with great caution!`,
Flags
:
[]
cli
.
Flag
{
Flags
:
[]
cli
.
Flag
{
passphraseFlag
,
passphraseFlag
,
jsonFlag
,
jsonFlag
,
cli
.
BoolFlag
{
privateFlag
,
Name
:
"private"
,
Usage
:
"include the private key in the output"
,
},
},
},
Action
:
func
(
ctx
*
cli
.
Context
)
error
{
Action
:
func
(
ctx
*
cli
.
Context
)
error
{
keyfilepath
:=
ctx
.
Args
()
.
First
()
keyfilepath
:=
ctx
.
Args
()
.
First
()
...
@@ -67,7 +71,7 @@ make sure to use this feature with great caution!`,
...
@@ -67,7 +71,7 @@ make sure to use this feature with great caution!`,
}
}
// Output all relevant information we can retrieve.
// Output all relevant information we can retrieve.
showPrivate
:=
ctx
.
Bool
(
"private"
)
showPrivate
:=
ctx
.
Bool
(
privateFlag
.
Name
)
out
:=
outputInspect
{
out
:=
outputInspect
{
Address
:
key
.
Address
.
Hex
(),
Address
:
key
.
Address
.
Hex
(),
PublicKey
:
hex
.
EncodeToString
(
PublicKey
:
hex
.
EncodeToString
(
...
...
cmd/ethkey/message.go
View file @
195c2d3d
...
@@ -142,7 +142,7 @@ It is possible to refer to a file containing the message.`,
...
@@ -142,7 +142,7 @@ It is possible to refer to a file containing the message.`,
}
}
func
getMessage
(
ctx
*
cli
.
Context
,
msgarg
int
)
[]
byte
{
func
getMessage
(
ctx
*
cli
.
Context
,
msgarg
int
)
[]
byte
{
if
file
:=
ctx
.
String
(
"msgfile"
);
file
!=
""
{
if
file
:=
ctx
.
String
(
msgfileFlag
.
Name
);
file
!=
""
{
if
len
(
ctx
.
Args
())
>
msgarg
{
if
len
(
ctx
.
Args
())
>
msgarg
{
utils
.
Fatalf
(
"Can't use --msgfile and message argument at the same time."
)
utils
.
Fatalf
(
"Can't use --msgfile and message argument at the same time."
)
}
}
...
...
cmd/p2psim/main.go
View file @
195c2d3d
...
@@ -56,19 +56,58 @@ import (
...
@@ -56,19 +56,58 @@ import (
var
client
*
simulations
.
Client
var
client
*
simulations
.
Client
var
(
// global command flags
apiFlag
=
cli
.
StringFlag
{
Name
:
"api"
,
Value
:
"http://localhost:8888"
,
Usage
:
"simulation API URL"
,
EnvVar
:
"P2PSIM_API_URL"
,
}
// events subcommand flags
currentFlag
=
cli
.
BoolFlag
{
Name
:
"current"
,
Usage
:
"get existing nodes and conns first"
,
}
filterFlag
=
cli
.
StringFlag
{
Name
:
"filter"
,
Value
:
""
,
Usage
:
"message filter"
,
}
// node create subcommand flags
nameFlag
=
cli
.
StringFlag
{
Name
:
"name"
,
Value
:
""
,
Usage
:
"node name"
,
}
servicesFlag
=
cli
.
StringFlag
{
Name
:
"services"
,
Value
:
""
,
Usage
:
"node services (comma separated)"
,
}
keyFlag
=
cli
.
StringFlag
{
Name
:
"key"
,
Value
:
""
,
Usage
:
"node private key (hex encoded)"
,
}
// node rpc subcommand flags
subscribeFlag
=
cli
.
BoolFlag
{
Name
:
"subscribe"
,
Usage
:
"method is a subscription"
,
}
)
func
main
()
{
func
main
()
{
app
:=
cli
.
NewApp
()
app
:=
cli
.
NewApp
()
app
.
Usage
=
"devp2p simulation command-line client"
app
.
Usage
=
"devp2p simulation command-line client"
app
.
Flags
=
[]
cli
.
Flag
{
app
.
Flags
=
[]
cli
.
Flag
{
cli
.
StringFlag
{
apiFlag
,
Name
:
"api"
,
Value
:
"http://localhost:8888"
,
Usage
:
"simulation API URL"
,
EnvVar
:
"P2PSIM_API_URL"
,
},
}
}
app
.
Before
=
func
(
ctx
*
cli
.
Context
)
error
{
app
.
Before
=
func
(
ctx
*
cli
.
Context
)
error
{
client
=
simulations
.
NewClient
(
ctx
.
GlobalString
(
"api"
))
client
=
simulations
.
NewClient
(
ctx
.
GlobalString
(
apiFlag
.
Name
))
return
nil
return
nil
}
}
app
.
Commands
=
[]
cli
.
Command
{
app
.
Commands
=
[]
cli
.
Command
{
...
@@ -82,15 +121,8 @@ func main() {
...
@@ -82,15 +121,8 @@ func main() {
Usage
:
"stream network events"
,
Usage
:
"stream network events"
,
Action
:
streamNetwork
,
Action
:
streamNetwork
,
Flags
:
[]
cli
.
Flag
{
Flags
:
[]
cli
.
Flag
{
cli
.
BoolFlag
{
currentFlag
,
Name
:
"current"
,
filterFlag
,
Usage
:
"get existing nodes and conns first"
,
},
cli
.
StringFlag
{
Name
:
"filter"
,
Value
:
""
,
Usage
:
"message filter"
,
},
},
},
},
},
{
{
...
@@ -118,21 +150,9 @@ func main() {
...
@@ -118,21 +150,9 @@ func main() {
Usage
:
"create a node"
,
Usage
:
"create a node"
,
Action
:
createNode
,
Action
:
createNode
,
Flags
:
[]
cli
.
Flag
{
Flags
:
[]
cli
.
Flag
{
cli
.
StringFlag
{
nameFlag
,
Name
:
"name"
,
servicesFlag
,
Value
:
""
,
keyFlag
,
Usage
:
"node name"
,
},
cli
.
StringFlag
{
Name
:
"services"
,
Value
:
""
,
Usage
:
"node services (comma separated)"
,
},
cli
.
StringFlag
{
Name
:
"key"
,
Value
:
""
,
Usage
:
"node private key (hex encoded)"
,
},
},
},
},
},
{
{
...
@@ -171,10 +191,7 @@ func main() {
...
@@ -171,10 +191,7 @@ func main() {
Usage
:
"call a node RPC method"
,
Usage
:
"call a node RPC method"
,
Action
:
rpcNode
,
Action
:
rpcNode
,
Flags
:
[]
cli
.
Flag
{
Flags
:
[]
cli
.
Flag
{
cli
.
BoolFlag
{
subscribeFlag
,
Name
:
"subscribe"
,
Usage
:
"method is a subscription"
,
},
},
},
},
},
},
},
...
@@ -207,8 +224,8 @@ func streamNetwork(ctx *cli.Context) error {
...
@@ -207,8 +224,8 @@ func streamNetwork(ctx *cli.Context) error {
}
}
events
:=
make
(
chan
*
simulations
.
Event
)
events
:=
make
(
chan
*
simulations
.
Event
)
sub
,
err
:=
client
.
SubscribeNetwork
(
events
,
simulations
.
SubscribeOpts
{
sub
,
err
:=
client
.
SubscribeNetwork
(
events
,
simulations
.
SubscribeOpts
{
Current
:
ctx
.
Bool
(
"current"
),
Current
:
ctx
.
Bool
(
currentFlag
.
Name
),
Filter
:
ctx
.
String
(
"filter"
),
Filter
:
ctx
.
String
(
filterFlag
.
Name
),
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -279,8 +296,8 @@ func createNode(ctx *cli.Context) error {
...
@@ -279,8 +296,8 @@ func createNode(ctx *cli.Context) error {
return
cli
.
ShowCommandHelp
(
ctx
,
ctx
.
Command
.
Name
)
return
cli
.
ShowCommandHelp
(
ctx
,
ctx
.
Command
.
Name
)
}
}
config
:=
adapters
.
RandomNodeConfig
()
config
:=
adapters
.
RandomNodeConfig
()
config
.
Name
=
ctx
.
String
(
"name"
)
config
.
Name
=
ctx
.
String
(
nameFlag
.
Name
)
if
key
:=
ctx
.
String
(
"key"
);
key
!=
""
{
if
key
:=
ctx
.
String
(
keyFlag
.
Name
);
key
!=
""
{
privKey
,
err
:=
crypto
.
HexToECDSA
(
key
)
privKey
,
err
:=
crypto
.
HexToECDSA
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -288,7 +305,7 @@ func createNode(ctx *cli.Context) error {
...
@@ -288,7 +305,7 @@ func createNode(ctx *cli.Context) error {
config
.
ID
=
enode
.
PubkeyToIDV4
(
&
privKey
.
PublicKey
)
config
.
ID
=
enode
.
PubkeyToIDV4
(
&
privKey
.
PublicKey
)
config
.
PrivateKey
=
privKey
config
.
PrivateKey
=
privKey
}
}
if
services
:=
ctx
.
String
(
"services"
);
services
!=
""
{
if
services
:=
ctx
.
String
(
servicesFlag
.
Name
);
services
!=
""
{
config
.
Lifecycles
=
strings
.
Split
(
services
,
","
)
config
.
Lifecycles
=
strings
.
Split
(
services
,
","
)
}
}
node
,
err
:=
client
.
CreateNode
(
config
)
node
,
err
:=
client
.
CreateNode
(
config
)
...
@@ -389,7 +406,7 @@ func rpcNode(ctx *cli.Context) error {
...
@@ -389,7 +406,7 @@ func rpcNode(ctx *cli.Context) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
ctx
.
Bool
(
"subscribe"
)
{
if
ctx
.
Bool
(
subscribeFlag
.
Name
)
{
return
rpcSubscribe
(
rpcClient
,
ctx
.
App
.
Writer
,
method
,
args
[
3
:
]
...
)
return
rpcSubscribe
(
rpcClient
,
ctx
.
App
.
Writer
,
method
,
args
[
3
:
]
...
)
}
}
var
result
interface
{}
var
result
interface
{}
...
...
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