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
3c532959
Commit
3c532959
authored
Apr 07, 2016
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/geth: add JS preload parameter
parent
7e021056
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
0 deletions
+38
-0
js.go
cmd/geth/js.go
+18
-0
main.go
cmd/geth/main.go
+15
-0
usage.go
cmd/geth/usage.go
+1
-0
flags.go
cmd/utils/flags.go
+4
-0
No files found.
cmd/geth/js.go
View file @
3c532959
...
...
@@ -27,6 +27,7 @@ import (
"sort"
"strings"
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/registrar"
...
...
@@ -331,6 +332,23 @@ func (self *jsre) UnlockAccount(addr []byte) bool {
}
}
// preloadJSFiles loads JS files that the user has specified with ctx.PreLoadJSFlag into
// the JSRE. If not all files could be loaded it will return an error describing the error.
func
(
self
*
jsre
)
preloadJSFiles
(
ctx
*
cli
.
Context
)
error
{
if
ctx
.
GlobalString
(
utils
.
PreLoadJSFlag
.
Name
)
!=
""
{
assetPath
:=
ctx
.
GlobalString
(
utils
.
JSpathFlag
.
Name
)
jsFiles
:=
strings
.
Split
(
ctx
.
GlobalString
(
utils
.
PreLoadJSFlag
.
Name
),
","
)
for
_
,
file
:=
range
jsFiles
{
filename
:=
common
.
AbsolutePath
(
assetPath
,
strings
.
TrimSpace
(
file
))
if
err
:=
self
.
re
.
Exec
(
filename
);
err
!=
nil
{
return
fmt
.
Errorf
(
"%s: %v"
,
file
,
err
)
}
}
}
return
nil
}
// exec executes the JS file with the given filename and stops the JSRE
func
(
self
*
jsre
)
exec
(
filename
string
)
error
{
if
err
:=
self
.
re
.
Exec
(
filename
);
err
!=
nil
{
self
.
re
.
Stop
(
false
)
...
...
cmd/geth/main.go
View file @
3c532959
...
...
@@ -331,6 +331,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils
.
IPCApiFlag
,
utils
.
IPCPathFlag
,
utils
.
ExecFlag
,
utils
.
PreLoadJSFlag
,
utils
.
WhisperEnabledFlag
,
utils
.
DevModeFlag
,
utils
.
TestNetFlag
,
...
...
@@ -427,6 +428,13 @@ func attach(ctx *cli.Context) {
true
,
)
// preload user defined JS files into the console
err
=
repl
.
preloadJSFiles
(
ctx
)
if
err
!=
nil
{
utils
.
Fatalf
(
"unable to preload JS file %v"
,
err
)
}
// in case the exec flag holds a JS statement execute it and return
if
ctx
.
GlobalString
(
utils
.
ExecFlag
.
Name
)
!=
""
{
repl
.
batch
(
ctx
.
GlobalString
(
utils
.
ExecFlag
.
Name
))
}
else
{
...
...
@@ -477,6 +485,13 @@ func console(ctx *cli.Context) {
ctx
.
GlobalString
(
utils
.
RPCCORSDomainFlag
.
Name
),
client
,
true
)
// preload user defined JS files into the console
err
=
repl
.
preloadJSFiles
(
ctx
)
if
err
!=
nil
{
utils
.
Fatalf
(
"unable to preload JS file %v"
,
err
)
}
// in case the exec flag holds a JS statement execute it and return
if
script
:=
ctx
.
GlobalString
(
utils
.
ExecFlag
.
Name
);
script
!=
""
{
repl
.
batch
(
script
)
}
else
{
...
...
cmd/geth/usage.go
View file @
3c532959
...
...
@@ -101,6 +101,7 @@ var AppHelpFlagGroups = []flagGroup{
utils
.
RPCCORSDomainFlag
,
utils
.
JSpathFlag
,
utils
.
ExecFlag
,
utils
.
PreLoadJSFlag
,
},
},
{
...
...
cmd/utils/flags.go
View file @
3c532959
...
...
@@ -296,6 +296,10 @@ var (
Name
:
"exec"
,
Usage
:
"Execute JavaScript statement (only in combination with console/attach)"
,
}
PreLoadJSFlag
=
cli
.
StringFlag
{
Name
:
"preload"
,
Usage
:
"Comma separated list of JavaScript files to preload into the console"
,
}
// Network Settings
MaxPeersFlag
=
cli
.
IntFlag
{
...
...
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