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
bedf6f40
Commit
bedf6f40
authored
Nov 20, 2017
by
Martin Holst Swende
Committed by
Felix Lange
Nov 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/geth: make geth account new faster with many keys (#15529)
parent
b4f2e4de
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
18 deletions
+46
-18
keystore_passphrase.go
accounts/keystore/keystore_passphrase.go
+7
-0
accountcmd.go
cmd/geth/accountcmd.go
+17
-4
config.go
node/config.go
+22
-14
No files found.
accounts/keystore/keystore_passphrase.go
View file @
bedf6f40
...
...
@@ -28,6 +28,7 @@ package keystore
import
(
"bytes"
"crypto/aes"
crand
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"encoding/json"
...
...
@@ -90,6 +91,12 @@ func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string)
return
key
,
nil
}
// StoreKey generates a key, encrypts with 'auth' and stores in the given directory
func
StoreKey
(
dir
,
auth
string
,
scryptN
,
scryptP
int
)
(
common
.
Address
,
error
)
{
_
,
a
,
err
:=
storeNewKey
(
&
keyStorePassphrase
{
dir
,
scryptN
,
scryptP
},
crand
.
Reader
,
auth
)
return
a
.
Address
,
err
}
func
(
ks
keyStorePassphrase
)
StoreKey
(
filename
string
,
key
*
Key
,
auth
string
)
error
{
keyjson
,
err
:=
EncryptKey
(
key
,
auth
,
ks
.
scryptN
,
ks
.
scryptP
)
if
err
!=
nil
{
...
...
cmd/geth/accountcmd.go
View file @
bedf6f40
...
...
@@ -291,15 +291,28 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
// accountCreate creates a new account into the keystore defined by the CLI flags.
func
accountCreate
(
ctx
*
cli
.
Context
)
error
{
stack
,
_
:=
makeConfigNode
(
ctx
)
cfg
:=
gethConfig
{
Node
:
defaultNodeConfig
()}
// Load config file.
if
file
:=
ctx
.
GlobalString
(
configFileFlag
.
Name
);
file
!=
""
{
if
err
:=
loadConfig
(
file
,
&
cfg
);
err
!=
nil
{
utils
.
Fatalf
(
"%v"
,
err
)
}
}
utils
.
SetNodeConfig
(
ctx
,
&
cfg
.
Node
)
scryptN
,
scryptP
,
keydir
,
err
:=
cfg
.
Node
.
AccountConfig
()
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to read configuration: %v"
,
err
)
}
password
:=
getPassPhrase
(
"Your new account is locked with a password. Please give a password. Do not forget this password."
,
true
,
0
,
utils
.
MakePasswordList
(
ctx
))
ks
:=
stack
.
AccountManager
()
.
Backends
(
keystore
.
KeyStoreType
)[
0
]
.
(
*
keystore
.
KeyStore
)
account
,
err
:=
ks
.
NewAccount
(
password
)
address
,
err
:=
keystore
.
StoreKey
(
keydir
,
password
,
scryptN
,
scryptP
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to create account: %v"
,
err
)
}
fmt
.
Printf
(
"Address: {%x}
\n
"
,
a
ccount
.
A
ddress
)
fmt
.
Printf
(
"Address: {%x}
\n
"
,
address
)
return
nil
}
...
...
node/config.go
View file @
bedf6f40
...
...
@@ -360,35 +360,43 @@ func (c *Config) parsePersistentNodes(path string) []*discover.Node {
return
nodes
}
func
makeAccountManager
(
conf
*
Config
)
(
*
accounts
.
Manager
,
string
,
error
)
{
// AccountConfig determines the settings for scrypt and keydirectory
func
(
c
*
Config
)
AccountConfig
()
(
int
,
int
,
string
,
error
)
{
scryptN
:=
keystore
.
StandardScryptN
scryptP
:=
keystore
.
StandardScryptP
if
c
onf
.
UseLightweightKDF
{
if
c
.
UseLightweightKDF
{
scryptN
=
keystore
.
LightScryptN
scryptP
=
keystore
.
LightScryptP
}
var
(
keydir
string
ephemeral
string
err
error
keydir
string
err
error
)
switch
{
case
filepath
.
IsAbs
(
c
onf
.
KeyStoreDir
)
:
keydir
=
c
onf
.
KeyStoreDir
case
c
onf
.
DataDir
!=
""
:
if
c
onf
.
KeyStoreDir
==
""
{
keydir
=
filepath
.
Join
(
c
onf
.
DataDir
,
datadirDefaultKeyStore
)
case
filepath
.
IsAbs
(
c
.
KeyStoreDir
)
:
keydir
=
c
.
KeyStoreDir
case
c
.
DataDir
!=
""
:
if
c
.
KeyStoreDir
==
""
{
keydir
=
filepath
.
Join
(
c
.
DataDir
,
datadirDefaultKeyStore
)
}
else
{
keydir
,
err
=
filepath
.
Abs
(
c
onf
.
KeyStoreDir
)
keydir
,
err
=
filepath
.
Abs
(
c
.
KeyStoreDir
)
}
case
conf
.
KeyStoreDir
!=
""
:
keydir
,
err
=
filepath
.
Abs
(
conf
.
KeyStoreDir
)
default
:
case
c
.
KeyStoreDir
!=
""
:
keydir
,
err
=
filepath
.
Abs
(
c
.
KeyStoreDir
)
}
return
scryptN
,
scryptP
,
keydir
,
err
}
func
makeAccountManager
(
conf
*
Config
)
(
*
accounts
.
Manager
,
string
,
error
)
{
scryptN
,
scryptP
,
keydir
,
err
:=
conf
.
AccountConfig
()
var
ephemeral
string
if
keydir
==
""
{
// There is no datadir.
keydir
,
err
=
ioutil
.
TempDir
(
""
,
"go-ethereum-keystore"
)
ephemeral
=
keydir
}
if
err
!=
nil
{
return
nil
,
""
,
err
}
...
...
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