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
563c035e
Commit
563c035e
authored
May 20, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored some of the functions
parent
de1dfae7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
16 deletions
+81
-16
javascript_runtime.go
ethereum/javascript_runtime.go
+76
-13
repl_darwin.go
ethereum/repl_darwin.go
+5
-3
No files found.
ethereum/javascript_runtime.go
View file @
563c035e
...
@@ -7,6 +7,9 @@ import (
...
@@ -7,6 +7,9 @@ import (
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/otto"
"github.com/obscuren/otto"
"io/ioutil"
"os"
"path/filepath"
)
)
type
JSRE
struct
{
type
JSRE
struct
{
...
@@ -53,6 +56,22 @@ func (self *JSRE) Run(code string) (otto.Value, error) {
...
@@ -53,6 +56,22 @@ func (self *JSRE) Run(code string) (otto.Value, error) {
return
self
.
vm
.
Run
(
code
)
return
self
.
vm
.
Run
(
code
)
}
}
func
(
self
*
JSRE
)
Require
(
file
string
)
error
{
if
len
(
filepath
.
Ext
(
file
))
==
0
{
file
+=
".js"
}
fh
,
err
:=
os
.
Open
(
file
)
if
err
!=
nil
{
return
err
}
content
,
_
:=
ioutil
.
ReadAll
(
fh
)
self
.
Run
(
"exports = {};(function() {"
+
string
(
content
)
+
"})();"
)
return
nil
}
func
(
self
*
JSRE
)
Stop
()
{
func
(
self
*
JSRE
)
Stop
()
{
// Kill the main loop
// Kill the main loop
self
.
quitChan
<-
true
self
.
quitChan
<-
true
...
@@ -82,7 +101,10 @@ out:
...
@@ -82,7 +101,10 @@ out:
cb
.
Call
(
cb
,
val
)
cb
.
Call
(
cb
,
val
)
}
}
}
else
if
storageObject
,
ok
:=
object
.
Resource
.
(
*
ethchain
.
StorageState
);
ok
{
}
else
if
storageObject
,
ok
:=
object
.
Resource
.
(
*
ethchain
.
StorageState
);
ok
{
fmt
.
Println
(
storageObject
)
for
_
,
cb
:=
range
self
.
objectCb
[
ethutil
.
Hex
(
storageObject
.
Address
)
+
ethutil
.
Hex
(
storageObject
.
StateAddress
)]
{
val
,
_
:=
self
.
vm
.
ToValue
(
ethpub
.
NewPStorageState
(
storageObject
))
cb
.
Call
(
cb
,
val
)
}
}
}
}
}
}
}
...
@@ -91,24 +113,65 @@ out:
...
@@ -91,24 +113,65 @@ out:
func
(
self
*
JSRE
)
initStdFuncs
()
{
func
(
self
*
JSRE
)
initStdFuncs
()
{
t
,
_
:=
self
.
vm
.
Get
(
"eth"
)
t
,
_
:=
self
.
vm
.
Get
(
"eth"
)
eth
:=
t
.
Object
()
eth
:=
t
.
Object
()
eth
.
Set
(
"watch"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
eth
.
Set
(
"watch"
,
self
.
watch
)
addr
,
_
:=
call
.
Argument
(
0
)
.
ToString
()
eth
.
Set
(
"addPeer"
,
self
.
addPeer
)
cb
:=
call
.
Argument
(
1
)
self
.
Set
(
"require"
,
self
.
require
)
}
/*
* The following methods are natively implemented javascript functions
*/
// eth.watch
func
(
self
JSRE
)
watch
(
call
otto
.
FunctionCall
)
otto
.
Value
{
addr
,
_
:=
call
.
Argument
(
0
)
.
ToString
()
var
storageAddr
string
var
cb
otto
.
Value
var
storageCallback
bool
if
len
(
call
.
ArgumentList
)
>
2
{
storageCallback
=
true
storageAddr
,
_
=
call
.
Argument
(
1
)
.
ToString
()
cb
=
call
.
Argument
(
2
)
}
else
{
cb
=
call
.
Argument
(
1
)
}
if
storageCallback
{
self
.
objectCb
[
addr
+
storageAddr
]
=
append
(
self
.
objectCb
[
addr
+
storageAddr
],
cb
)
event
:=
"storage:"
+
string
(
ethutil
.
FromHex
(
addr
))
+
":"
+
string
(
ethutil
.
FromHex
(
storageAddr
))
self
.
ethereum
.
Reactor
()
.
Subscribe
(
event
,
self
.
changeChan
)
}
else
{
self
.
objectCb
[
addr
]
=
append
(
self
.
objectCb
[
addr
],
cb
)
self
.
objectCb
[
addr
]
=
append
(
self
.
objectCb
[
addr
],
cb
)
event
:=
"object:"
+
string
(
ethutil
.
FromHex
(
addr
))
event
:=
"object:"
+
string
(
ethutil
.
FromHex
(
addr
))
self
.
ethereum
.
Reactor
()
.
Subscribe
(
event
,
self
.
changeChan
)
self
.
ethereum
.
Reactor
()
.
Subscribe
(
event
,
self
.
changeChan
)
}
return
otto
.
UndefinedValue
()
}
func
(
self
*
JSRE
)
addPeer
(
call
otto
.
FunctionCall
)
otto
.
Value
{
host
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
return
otto
.
FalseValue
()
}
self
.
ethereum
.
ConnectToPeer
(
host
)
return
otto
.
TrueValue
()
}
func
(
self
*
JSRE
)
require
(
call
otto
.
FunctionCall
)
otto
.
Value
{
file
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
return
otto
.
UndefinedValue
()
return
otto
.
UndefinedValue
()
}
)
}
eth
.
Set
(
"addPeer"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
if
err
:=
self
.
Require
(
file
);
err
!=
nil
{
host
,
err
:=
call
.
Argument
(
0
)
.
ToString
(
)
fmt
.
Println
(
"err:"
,
err
)
if
err
!=
nil
{
return
otto
.
UndefinedValue
()
return
otto
.
FalseValue
()
}
}
self
.
ethereum
.
ConnectToPeer
(
host
)
t
,
_
:=
self
.
vm
.
Get
(
"exports"
)
return
otto
.
TrueValue
()
return
t
})
}
}
ethereum/repl_darwin.go
View file @
563c035e
...
@@ -8,7 +8,6 @@ package main
...
@@ -8,7 +8,6 @@ package main
import
"C"
import
"C"
import
(
import
(
"github.com/obscuren/otto"
"strings"
"strings"
"unsafe"
"unsafe"
)
)
...
@@ -87,7 +86,10 @@ L:
...
@@ -87,7 +86,10 @@ L:
}
}
}
}
func
(
self
*
JSRepl
)
PrintValue
(
v
alue
otto
.
Value
)
{
func
(
self
*
JSRepl
)
PrintValue
(
v
interface
{}
)
{
method
,
_
:=
self
.
re
.
vm
.
Get
(
"prettyPrint"
)
method
,
_
:=
self
.
re
.
vm
.
Get
(
"prettyPrint"
)
method
.
Call
(
method
,
value
)
v
,
err
:=
self
.
re
.
vm
.
ToValue
(
v
)
if
err
==
nil
{
method
.
Call
(
method
,
v
)
}
}
}
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