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
ce8f24e5
Commit
ce8f24e5
authored
Aug 11, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved JSRE to it's own package for sharing between ethere(um/al)
parent
51a20870
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
18 deletions
+93
-18
javascript_runtime.go
javascript/javascript_runtime.go
+15
-15
js_lib.go
javascript/js_lib.go
+1
-1
types.go
javascript/types.go
+77
-2
No files found.
ethereum/repl
/javascript_runtime.go
→
javascript
/javascript_runtime.go
View file @
ce8f24e5
package
ethrepl
package
javascript
import
(
"fmt"
...
...
@@ -22,7 +22,7 @@ var jsrelogger = ethlog.NewLogger("JSRE")
type
JSRE
struct
{
ethereum
*
eth
.
Ethereum
v
m
*
otto
.
Otto
V
m
*
otto
.
Otto
lib
*
ethpub
.
PEthereum
blockChan
chan
ethreact
.
Event
...
...
@@ -35,9 +35,9 @@ type JSRE struct {
func
(
jsre
*
JSRE
)
LoadExtFile
(
path
string
)
{
result
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
==
nil
{
jsre
.
v
m
.
Run
(
result
)
jsre
.
V
m
.
Run
(
result
)
}
else
{
jsrelogger
.
Debug
ln
(
"Could not load file:"
,
path
)
jsrelogger
.
Info
ln
(
"Could not load file:"
,
path
)
}
}
...
...
@@ -58,7 +58,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
}
// Init the JS lib
re
.
v
m
.
Run
(
jsLib
)
re
.
V
m
.
Run
(
jsLib
)
// Load extra javascript files
re
.
LoadIntFile
(
"string.js"
)
...
...
@@ -71,7 +71,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
reactor
:=
ethereum
.
Reactor
()
reactor
.
Subscribe
(
"newBlock"
,
re
.
blockChan
)
re
.
Bind
(
"eth"
,
&
JSEthereum
{
re
.
lib
,
re
.
v
m
})
re
.
Bind
(
"eth"
,
&
JSEthereum
{
re
.
lib
,
re
.
Vm
,
ethereu
m
})
re
.
initStdFuncs
()
...
...
@@ -81,11 +81,11 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
}
func
(
self
*
JSRE
)
Bind
(
name
string
,
v
interface
{})
{
self
.
v
m
.
Set
(
name
,
v
)
self
.
V
m
.
Set
(
name
,
v
)
}
func
(
self
*
JSRE
)
Run
(
code
string
)
(
otto
.
Value
,
error
)
{
return
self
.
v
m
.
Run
(
code
)
return
self
.
V
m
.
Run
(
code
)
}
func
(
self
*
JSRE
)
Require
(
file
string
)
error
{
...
...
@@ -126,12 +126,12 @@ out:
case
object
:=
<-
self
.
changeChan
:
if
stateObject
,
ok
:=
object
.
Resource
.
(
*
ethstate
.
StateObject
);
ok
{
for
_
,
cb
:=
range
self
.
objectCb
[
ethutil
.
Bytes2Hex
(
stateObject
.
Address
())]
{
val
,
_
:=
self
.
v
m
.
ToValue
(
ethpub
.
NewPStateObject
(
stateObject
))
val
,
_
:=
self
.
V
m
.
ToValue
(
ethpub
.
NewPStateObject
(
stateObject
))
cb
.
Call
(
cb
,
val
)
}
}
else
if
storageObject
,
ok
:=
object
.
Resource
.
(
*
ethstate
.
StorageState
);
ok
{
for
_
,
cb
:=
range
self
.
objectCb
[
ethutil
.
Bytes2Hex
(
storageObject
.
StateAddress
)
+
ethutil
.
Bytes2Hex
(
storageObject
.
Address
)]
{
val
,
_
:=
self
.
v
m
.
ToValue
(
ethpub
.
NewPStorageState
(
storageObject
))
val
,
_
:=
self
.
V
m
.
ToValue
(
ethpub
.
NewPStorageState
(
storageObject
))
cb
.
Call
(
cb
,
val
)
}
}
...
...
@@ -140,7 +140,7 @@ out:
}
func
(
self
*
JSRE
)
initStdFuncs
()
{
t
,
_
:=
self
.
v
m
.
Get
(
"eth"
)
t
,
_
:=
self
.
V
m
.
Get
(
"eth"
)
eth
:=
t
.
Object
()
eth
.
Set
(
"watch"
,
self
.
watch
)
eth
.
Set
(
"addPeer"
,
self
.
addPeer
)
...
...
@@ -181,18 +181,18 @@ func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
state
=
self
.
ethereum
.
StateManager
()
.
CurrentState
()
}
v
,
_
:=
self
.
v
m
.
ToValue
(
state
.
Dump
())
v
,
_
:=
self
.
V
m
.
ToValue
(
state
.
Dump
())
return
v
}
func
(
self
*
JSRE
)
stopMining
(
call
otto
.
FunctionCall
)
otto
.
Value
{
v
,
_
:=
self
.
v
m
.
ToValue
(
utils
.
StopMining
(
self
.
ethereum
))
v
,
_
:=
self
.
V
m
.
ToValue
(
utils
.
StopMining
(
self
.
ethereum
))
return
v
}
func
(
self
*
JSRE
)
startMining
(
call
otto
.
FunctionCall
)
otto
.
Value
{
v
,
_
:=
self
.
v
m
.
ToValue
(
utils
.
StartMining
(
self
.
ethereum
))
v
,
_
:=
self
.
V
m
.
ToValue
(
utils
.
StartMining
(
self
.
ethereum
))
return
v
}
...
...
@@ -245,7 +245,7 @@ func (self *JSRE) require(call otto.FunctionCall) otto.Value {
return
otto
.
UndefinedValue
()
}
t
,
_
:=
self
.
v
m
.
Get
(
"exports"
)
t
,
_
:=
self
.
V
m
.
Get
(
"exports"
)
return
t
}
...
...
ethereum/repl
/js_lib.go
→
javascript
/js_lib.go
View file @
ce8f24e5
package
ethrepl
package
javascript
const
jsLib
=
`
function pp(object) {
...
...
ethereum/repl
/types.go
→
javascript
/types.go
View file @
ce8f24e5
package
ethrepl
package
javascript
import
(
"fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/otto"
)
...
...
@@ -34,9 +38,37 @@ func (self *JSBlock) GetTransaction(hash string) otto.Value {
return
self
.
eth
.
toVal
(
self
.
PBlock
.
GetTransaction
(
hash
))
}
type
JSMessage
struct
{
To
,
From
string
Input
string
Output
string
Path
int
Origin
string
Timestamp
int32
Coinbase
string
Block
string
Number
int32
}
func
NewJSMessage
(
message
*
ethstate
.
Message
)
JSMessage
{
return
JSMessage
{
To
:
ethutil
.
Bytes2Hex
(
message
.
To
),
From
:
ethutil
.
Bytes2Hex
(
message
.
From
),
Input
:
ethutil
.
Bytes2Hex
(
message
.
Input
),
Output
:
ethutil
.
Bytes2Hex
(
message
.
Output
),
Path
:
message
.
Path
,
Origin
:
ethutil
.
Bytes2Hex
(
message
.
Origin
),
Timestamp
:
int32
(
message
.
Timestamp
),
Coinbase
:
ethutil
.
Bytes2Hex
(
message
.
Origin
),
Block
:
ethutil
.
Bytes2Hex
(
message
.
Block
),
Number
:
int32
(
message
.
Number
.
Int64
()),
}
}
type
JSEthereum
struct
{
*
ethpub
.
PEthereum
vm
*
otto
.
Otto
ethereum
*
eth
.
Ethereum
}
func
(
self
*
JSEthereum
)
GetBlock
(
hash
string
)
otto
.
Value
{
...
...
@@ -93,3 +125,46 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value {
return
result
}
func
(
self
*
JSEthereum
)
Messages
(
object
map
[
string
]
interface
{})
otto
.
Value
{
filter
:=
ethchain
.
NewFilter
(
self
.
ethereum
)
if
object
[
"earliest"
]
!=
nil
{
earliest
:=
object
[
"earliest"
]
if
e
,
ok
:=
earliest
.
(
string
);
ok
{
filter
.
SetEarliestBlock
(
ethutil
.
Hex2Bytes
(
e
))
}
else
{
filter
.
SetEarliestBlock
(
earliest
)
}
}
if
object
[
"latest"
]
!=
nil
{
latest
:=
object
[
"latest"
]
if
l
,
ok
:=
latest
.
(
string
);
ok
{
filter
.
SetLatestBlock
(
ethutil
.
Hex2Bytes
(
l
))
}
else
{
filter
.
SetLatestBlock
(
latest
)
}
}
if
object
[
"to"
]
!=
nil
{
filter
.
SetTo
(
ethutil
.
Hex2Bytes
(
object
[
"to"
]
.
(
string
)))
}
if
object
[
"from"
]
!=
nil
{
filter
.
SetFrom
(
ethutil
.
Hex2Bytes
(
object
[
"from"
]
.
(
string
)))
}
if
object
[
"max"
]
!=
nil
{
filter
.
SetMax
(
object
[
"max"
]
.
(
int
))
}
if
object
[
"skip"
]
!=
nil
{
filter
.
SetSkip
(
object
[
"skip"
]
.
(
int
))
}
messages
:=
filter
.
Find
()
var
msgs
[]
JSMessage
for
_
,
m
:=
range
messages
{
msgs
=
append
(
msgs
,
NewJSMessage
(
m
))
}
v
,
_
:=
self
.
vm
.
ToValue
(
msgs
)
return
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