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
cdd34fcb
Commit
cdd34fcb
authored
Jan 19, 2016
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console: add admin.sleep and admin.sleepBlocks
parent
5945a333
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
js.go
cmd/geth/js.go
+9
-0
jeth.go
rpc/jeth.go
+75
-0
No files found.
cmd/geth/js.go
View file @
cdd34fcb
...
@@ -348,6 +348,15 @@ func (js *jsre) apiBindings(f xeth.Frontend) error {
...
@@ -348,6 +348,15 @@ func (js *jsre) apiBindings(f xeth.Frontend) error {
persObj
.
Set
(
"newAccount"
,
jeth
.
NewAccount
)
persObj
.
Set
(
"newAccount"
,
jeth
.
NewAccount
)
}
}
// The admin.sleep and admin.sleepBlocks are offered by the console and not by the RPC layer.
// Bind these if the admin module is available.
if
a
,
err
:=
js
.
re
.
Get
(
"admin"
);
err
==
nil
{
if
adminObj
:=
a
.
Object
();
adminObj
!=
nil
{
adminObj
.
Set
(
"sleepBlocks"
,
jeth
.
SleepBlocks
)
adminObj
.
Set
(
"sleep"
,
jeth
.
Sleep
)
}
}
return
nil
return
nil
}
}
...
...
rpc/jeth.go
View file @
cdd34fcb
...
@@ -19,6 +19,7 @@ package rpc
...
@@ -19,6 +19,7 @@ package rpc
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"time"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/jsre"
"github.com/ethereum/go-ethereum/jsre"
...
@@ -247,3 +248,77 @@ func (self *Jeth) confirmTransaction(id interface{}, jsonrpc string, args []inte
...
@@ -247,3 +248,77 @@ func (self *Jeth) confirmTransaction(id interface{}, jsonrpc string, args []inte
// Accept all tx which are send from this console
// Accept all tx which are send from this console
return
self
.
client
.
Send
(
shared
.
NewRpcResponse
(
id
,
jsonrpc
,
true
,
nil
))
==
nil
return
self
.
client
.
Send
(
shared
.
NewRpcResponse
(
id
,
jsonrpc
,
true
,
nil
))
==
nil
}
}
// throwJSExeception panics on an otto value, the Otto VM will then throw msg as a javascript error.
func
throwJSExeception
(
msg
interface
{})
otto
.
Value
{
p
,
_
:=
otto
.
ToValue
(
msg
)
panic
(
p
)
return
p
}
// Sleep will halt the console for arg[0] seconds.
func
(
self
*
Jeth
)
Sleep
(
call
otto
.
FunctionCall
)
(
response
otto
.
Value
)
{
if
len
(
call
.
ArgumentList
)
>=
1
{
if
call
.
Argument
(
0
)
.
IsNumber
()
{
sleep
,
_
:=
call
.
Argument
(
0
)
.
ToInteger
()
time
.
Sleep
(
time
.
Duration
(
sleep
)
*
time
.
Second
)
return
otto
.
TrueValue
()
}
}
return
throwJSExeception
(
"usage: sleep(<sleep in seconds>)"
)
}
// SleepBlocks will wait for a specified number of new blocks or max for a
// given of seconds. sleepBlocks(nBlocks[, maxSleep]).
func
(
self
*
Jeth
)
SleepBlocks
(
call
otto
.
FunctionCall
)
(
response
otto
.
Value
)
{
nBlocks
:=
int64
(
0
)
maxSleep
:=
int64
(
9999999999999999
)
// indefinitely
nArgs
:=
len
(
call
.
ArgumentList
)
if
nArgs
==
0
{
throwJSExeception
(
"usage: sleepBlocks(<n blocks>[, max sleep in seconds])"
)
}
if
nArgs
>=
1
{
if
call
.
Argument
(
0
)
.
IsNumber
()
{
nBlocks
,
_
=
call
.
Argument
(
0
)
.
ToInteger
()
}
else
{
throwJSExeception
(
"expected number as first argument"
)
}
}
if
nArgs
>=
2
{
if
call
.
Argument
(
1
)
.
IsNumber
()
{
maxSleep
,
_
=
call
.
Argument
(
1
)
.
ToInteger
()
}
else
{
throwJSExeception
(
"expected number as second argument"
)
}
}
// go through the console, this will allow web3 to call the appropriate
// callbacks if a delayed response or notification is received.
currentBlockNr
:=
func
()
int64
{
result
,
err
:=
call
.
Otto
.
Run
(
"eth.blockNumber"
)
if
err
!=
nil
{
throwJSExeception
(
err
.
Error
())
}
blockNr
,
err
:=
result
.
ToInteger
()
if
err
!=
nil
{
throwJSExeception
(
err
.
Error
())
}
return
blockNr
}
targetBlockNr
:=
currentBlockNr
()
+
nBlocks
deadline
:=
time
.
Now
()
.
Add
(
time
.
Duration
(
maxSleep
)
*
time
.
Second
)
for
time
.
Now
()
.
Before
(
deadline
)
{
if
currentBlockNr
()
>=
targetBlockNr
{
return
otto
.
TrueValue
()
}
time
.
Sleep
(
time
.
Second
)
}
return
otto
.
FalseValue
()
}
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