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
a55f408c
Commit
a55f408c
authored
May 26, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1090 from fjl/jsre-fixes
jsre: fixes for concurrent use, improved timer handling
parents
39b1fe8e
e221a449
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
176 deletions
+124
-176
admin.go
cmd/geth/admin.go
+28
-17
js.go
cmd/geth/js.go
+1
-1
jsre.go
jsre/jsre.go
+86
-149
jsre_test.go
jsre/jsre_test.go
+6
-6
jeth.go
rpc/jeth.go
+3
-3
No files found.
cmd/geth/admin.go
View file @
a55f408c
...
...
@@ -144,7 +144,8 @@ func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value {
}
}
return
js
.
re
.
ToVal
(
ltxs
)
v
,
_
:=
call
.
Otto
.
ToValue
(
ltxs
)
return
v
}
func
(
js
*
jsre
)
resend
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -175,7 +176,8 @@ func (js *jsre) resend(call otto.FunctionCall) otto.Value {
}
js
.
ethereum
.
TxPool
()
.
RemoveTransactions
(
types
.
Transactions
{
tx
.
tx
})
return
js
.
re
.
ToVal
(
ret
)
v
,
_
:=
call
.
Otto
.
ToValue
(
ret
)
return
v
}
fmt
.
Println
(
"first argument must be a transaction"
)
...
...
@@ -198,12 +200,13 @@ func (js *jsre) sign(call otto.FunctionCall) otto.Value {
fmt
.
Println
(
err
)
return
otto
.
UndefinedValue
()
}
v
,
err
:=
js
.
xeth
.
Sign
(
signer
,
data
,
false
)
signed
,
err
:=
js
.
xeth
.
Sign
(
signer
,
data
,
false
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
otto
.
UndefinedValue
()
}
return
js
.
re
.
ToVal
(
v
)
v
,
_
:=
call
.
Otto
.
ToValue
(
signed
)
return
v
}
func
(
js
*
jsre
)
debugBlock
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -237,8 +240,8 @@ func (js *jsre) setHead(call otto.FunctionCall) otto.Value {
func
(
js
*
jsre
)
downloadProgress
(
call
otto
.
FunctionCall
)
otto
.
Value
{
current
,
max
:=
js
.
ethereum
.
Downloader
()
.
Stats
()
return
js
.
re
.
ToVal
(
fmt
.
Sprintf
(
"%d/%d"
,
current
,
max
))
v
,
_
:=
call
.
Otto
.
ToValue
(
fmt
.
Sprintf
(
"%d/%d"
,
current
,
max
))
return
v
}
func
(
js
*
jsre
)
getBlockRlp
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -248,7 +251,8 @@ func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
return
otto
.
UndefinedValue
()
}
encoded
,
_
:=
rlp
.
EncodeToBytes
(
block
)
return
js
.
re
.
ToVal
(
fmt
.
Sprintf
(
"%x"
,
encoded
))
v
,
_
:=
call
.
Otto
.
ToValue
(
fmt
.
Sprintf
(
"%x"
,
encoded
))
return
v
}
func
(
js
*
jsre
)
setExtra
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -278,8 +282,9 @@ func (js *jsre) setGasPrice(call otto.FunctionCall) otto.Value {
return
otto
.
UndefinedValue
()
}
func
(
js
*
jsre
)
hashrate
(
otto
.
FunctionCall
)
otto
.
Value
{
return
js
.
re
.
ToVal
(
js
.
ethereum
.
Miner
()
.
HashRate
())
func
(
js
*
jsre
)
hashrate
(
call
otto
.
FunctionCall
)
otto
.
Value
{
v
,
_
:=
call
.
Otto
.
ToValue
(
js
.
ethereum
.
Miner
()
.
HashRate
())
return
v
}
func
(
js
*
jsre
)
makeDAG
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -495,15 +500,18 @@ func (js *jsre) newAccount(call otto.FunctionCall) otto.Value {
fmt
.
Printf
(
"Could not create the account: %v"
,
err
)
return
otto
.
UndefinedValue
()
}
return
js
.
re
.
ToVal
(
acct
.
Address
.
Hex
())
v
,
_
:=
call
.
Otto
.
ToValue
(
acct
.
Address
.
Hex
())
return
v
}
func
(
js
*
jsre
)
nodeInfo
(
call
otto
.
FunctionCall
)
otto
.
Value
{
return
js
.
re
.
ToVal
(
js
.
ethereum
.
NodeInfo
())
v
,
_
:=
call
.
Otto
.
ToValue
(
js
.
ethereum
.
NodeInfo
())
return
v
}
func
(
js
*
jsre
)
peers
(
call
otto
.
FunctionCall
)
otto
.
Value
{
return
js
.
re
.
ToVal
(
js
.
ethereum
.
PeersInfo
())
v
,
_
:=
call
.
Otto
.
ToValue
(
js
.
ethereum
.
PeersInfo
())
return
v
}
func
(
js
*
jsre
)
importChain
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -562,7 +570,8 @@ func (js *jsre) dumpBlock(call otto.FunctionCall) otto.Value {
statedb
:=
state
.
New
(
block
.
Root
(),
js
.
ethereum
.
StateDb
())
dump
:=
statedb
.
RawDump
()
return
js
.
re
.
ToVal
(
dump
)
v
,
_
:=
call
.
Otto
.
ToValue
(
dump
)
return
v
}
func
(
js
*
jsre
)
waitForBlocks
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -611,7 +620,8 @@ func (js *jsre) waitForBlocks(call otto.FunctionCall) otto.Value {
return
otto
.
UndefinedValue
()
case
height
=
<-
wait
:
}
return
js
.
re
.
ToVal
(
height
.
Uint64
())
v
,
_
:=
call
.
Otto
.
ToValue
(
height
.
Uint64
())
return
v
}
func
(
js
*
jsre
)
sleep
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -704,8 +714,8 @@ func (js *jsre) register(call otto.FunctionCall) otto.Value {
return
otto
.
UndefinedValue
()
}
return
js
.
re
.
ToVal
(
contenthash
.
Hex
())
v
,
_
:=
call
.
Otto
.
ToValue
(
contenthash
.
Hex
())
return
v
}
func
(
js
*
jsre
)
registerUrl
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
@@ -764,7 +774,8 @@ func (js *jsre) getContractInfo(call otto.FunctionCall) otto.Value {
fmt
.
Println
(
err
)
return
otto
.
UndefinedValue
()
}
return
js
.
re
.
ToVal
(
info
)
v
,
_
:=
call
.
Otto
.
ToValue
(
info
)
return
v
}
func
(
js
*
jsre
)
startNatSpec
(
call
otto
.
FunctionCall
)
otto
.
Value
{
...
...
cmd/geth/js.go
View file @
a55f408c
...
...
@@ -104,7 +104,7 @@ func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive boo
func
(
js
*
jsre
)
apiBindings
(
f
xeth
.
Frontend
)
{
xe
:=
xeth
.
New
(
js
.
ethereum
,
f
)
ethApi
:=
rpc
.
NewEthereumApi
(
xe
)
jeth
:=
rpc
.
NewJeth
(
ethApi
,
js
.
re
.
ToVal
,
js
.
re
)
jeth
:=
rpc
.
NewJeth
(
ethApi
,
js
.
re
)
js
.
re
.
Set
(
"jeth"
,
struct
{}{})
t
,
_
:=
js
.
re
.
Get
(
"jeth"
)
...
...
jsre/jsre.go
View file @
a55f408c
This diff is collapsed.
Click to expand it.
jsre/jsre_test.go
View file @
a55f408c
package
jsre
import
(
"github.com/robertkrimen/otto"
"io/ioutil"
"os"
"testing"
"time"
"github.com/robertkrimen/otto"
)
type
testNativeObjectBinding
struct
{
toVal
func
(
interface
{})
otto
.
Value
}
type
testNativeObjectBinding
struct
{}
type
msg
struct
{
Msg
string
...
...
@@ -21,7 +20,8 @@ func (no *testNativeObjectBinding) TestMethod(call otto.FunctionCall) otto.Value
if
err
!=
nil
{
return
otto
.
UndefinedValue
()
}
return
no
.
toVal
(
&
msg
{
m
})
v
,
_
:=
call
.
Otto
.
ToValue
(
&
msg
{
m
})
return
v
}
func
TestExec
(
t
*
testing
.
T
)
{
...
...
@@ -74,7 +74,7 @@ func TestNatto(t *testing.T) {
func
TestBind
(
t
*
testing
.
T
)
{
jsre
:=
New
(
"/tmp"
)
jsre
.
Bind
(
"no"
,
&
testNativeObjectBinding
{
jsre
.
ToVal
})
jsre
.
Bind
(
"no"
,
&
testNativeObjectBinding
{})
val
,
err
:=
jsre
.
Run
(
`no.TestMethod("testMsg")`
)
if
err
!=
nil
{
...
...
rpc/jeth.go
View file @
a55f408c
...
...
@@ -3,18 +3,18 @@ package rpc
import
(
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/jsre"
"github.com/robertkrimen/otto"
)
type
Jeth
struct
{
ethApi
*
EthereumApi
toVal
func
(
interface
{})
otto
.
Value
re
*
jsre
.
JSRE
}
func
NewJeth
(
ethApi
*
EthereumApi
,
toVal
func
(
interface
{})
otto
.
Value
,
re
*
jsre
.
JSRE
)
*
Jeth
{
return
&
Jeth
{
ethApi
,
toVal
,
re
}
func
NewJeth
(
ethApi
*
EthereumApi
,
re
*
jsre
.
JSRE
)
*
Jeth
{
return
&
Jeth
{
ethApi
,
re
}
}
func
(
self
*
Jeth
)
err
(
call
otto
.
FunctionCall
,
code
int
,
msg
string
,
id
interface
{})
(
response
otto
.
Value
)
{
...
...
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