good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
3c532959
Commit
3c532959
authored
8 years ago
by
Bas van Kervel
Browse files
Options
Downloads
Patches
Plain Diff
cmd/geth: add JS preload parameter
parent
7e021056
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/geth/js.go
+18
-0
18 additions, 0 deletions
cmd/geth/js.go
cmd/geth/main.go
+15
-0
15 additions, 0 deletions
cmd/geth/main.go
cmd/geth/usage.go
+1
-0
1 addition, 0 deletions
cmd/geth/usage.go
cmd/utils/flags.go
+4
-0
4 additions, 0 deletions
cmd/utils/flags.go
with
38 additions
and
0 deletions
cmd/geth/js.go
+
18
−
0
View file @
3c532959
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
"sort"
"sort"
"strings"
"strings"
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/registrar"
"github.com/ethereum/go-ethereum/common/registrar"
...
@@ -331,6 +332,23 @@ func (self *jsre) UnlockAccount(addr []byte) bool {
...
@@ -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
{
func
(
self
*
jsre
)
exec
(
filename
string
)
error
{
if
err
:=
self
.
re
.
Exec
(
filename
);
err
!=
nil
{
if
err
:=
self
.
re
.
Exec
(
filename
);
err
!=
nil
{
self
.
re
.
Stop
(
false
)
self
.
re
.
Stop
(
false
)
...
...
This diff is collapsed.
Click to expand it.
cmd/geth/main.go
+
15
−
0
View file @
3c532959
...
@@ -331,6 +331,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
...
@@ -331,6 +331,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils
.
IPCApiFlag
,
utils
.
IPCApiFlag
,
utils
.
IPCPathFlag
,
utils
.
IPCPathFlag
,
utils
.
ExecFlag
,
utils
.
ExecFlag
,
utils
.
PreLoadJSFlag
,
utils
.
WhisperEnabledFlag
,
utils
.
WhisperEnabledFlag
,
utils
.
DevModeFlag
,
utils
.
DevModeFlag
,
utils
.
TestNetFlag
,
utils
.
TestNetFlag
,
...
@@ -427,6 +428,13 @@ func attach(ctx *cli.Context) {
...
@@ -427,6 +428,13 @@ func attach(ctx *cli.Context) {
true
,
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
)
!=
""
{
if
ctx
.
GlobalString
(
utils
.
ExecFlag
.
Name
)
!=
""
{
repl
.
batch
(
ctx
.
GlobalString
(
utils
.
ExecFlag
.
Name
))
repl
.
batch
(
ctx
.
GlobalString
(
utils
.
ExecFlag
.
Name
))
}
else
{
}
else
{
...
@@ -477,6 +485,13 @@ func console(ctx *cli.Context) {
...
@@ -477,6 +485,13 @@ func console(ctx *cli.Context) {
ctx
.
GlobalString
(
utils
.
RPCCORSDomainFlag
.
Name
),
ctx
.
GlobalString
(
utils
.
RPCCORSDomainFlag
.
Name
),
client
,
true
)
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
!=
""
{
if
script
:=
ctx
.
GlobalString
(
utils
.
ExecFlag
.
Name
);
script
!=
""
{
repl
.
batch
(
script
)
repl
.
batch
(
script
)
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
cmd/geth/usage.go
+
1
−
0
View file @
3c532959
...
@@ -101,6 +101,7 @@ var AppHelpFlagGroups = []flagGroup{
...
@@ -101,6 +101,7 @@ var AppHelpFlagGroups = []flagGroup{
utils
.
RPCCORSDomainFlag
,
utils
.
RPCCORSDomainFlag
,
utils
.
JSpathFlag
,
utils
.
JSpathFlag
,
utils
.
ExecFlag
,
utils
.
ExecFlag
,
utils
.
PreLoadJSFlag
,
},
},
},
},
{
{
...
...
This diff is collapsed.
Click to expand it.
cmd/utils/flags.go
+
4
−
0
View file @
3c532959
...
@@ -296,6 +296,10 @@ var (
...
@@ -296,6 +296,10 @@ var (
Name
:
"exec"
,
Name
:
"exec"
,
Usage
:
"Execute JavaScript statement (only in combination with console/attach)"
,
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
// Network Settings
MaxPeersFlag
=
cli
.
IntFlag
{
MaxPeersFlag
=
cli
.
IntFlag
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment