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
872b2497
Commit
872b2497
authored
Jan 28, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
further cleaned up xeth interface
parent
1146f250
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
123 additions
and
133 deletions
+123
-133
ext_app.go
cmd/mist/ext_app.go
+2
-2
gui.go
cmd/mist/gui.go
+6
-6
html_container.go
cmd/mist/html_container.go
+1
-1
qml_container.go
cmd/mist/qml_container.go
+1
-1
ui_lib.go
cmd/mist/ui_lib.go
+6
-6
cmd.go
cmd/utils/cmd.go
+1
-1
javascript_runtime.go
javascript/javascript_runtime.go
+2
-2
types.go
javascript/types.go
+9
-9
server.go
rpc/http/server.go
+2
-2
packages.go
rpc/packages.go
+5
-5
server.go
rpc/ws/server.go
+1
-1
object.go
xeth/object.go
+0
-26
types.go
xeth/types.go
+51
-35
world.go
xeth/world.go
+2
-2
xeth.go
xeth/xeth.go
+34
-34
No files found.
cmd/mist/ext_app.go
View file @
872b2497
...
@@ -47,7 +47,7 @@ type AppContainer interface {
...
@@ -47,7 +47,7 @@ type AppContainer interface {
}
}
type
ExtApplication
struct
{
type
ExtApplication
struct
{
*
xeth
.
JS
XEth
*
xeth
.
XEth
eth
core
.
EthManager
eth
core
.
EthManager
events
event
.
Subscription
events
event
.
Subscription
...
@@ -61,7 +61,7 @@ type ExtApplication struct {
...
@@ -61,7 +61,7 @@ type ExtApplication struct {
func
NewExtApplication
(
container
AppContainer
,
lib
*
UiLib
)
*
ExtApplication
{
func
NewExtApplication
(
container
AppContainer
,
lib
*
UiLib
)
*
ExtApplication
{
return
&
ExtApplication
{
return
&
ExtApplication
{
JSXEth
:
xeth
.
NewJSXEth
(
lib
.
eth
),
XEth
:
xeth
.
New
(
lib
.
eth
),
eth
:
lib
.
eth
,
eth
:
lib
.
eth
,
watcherQuitChan
:
make
(
chan
bool
),
watcherQuitChan
:
make
(
chan
bool
),
filters
:
make
(
map
[
string
]
*
core
.
Filter
),
filters
:
make
(
map
[
string
]
*
core
.
Filter
),
...
...
cmd/mist/gui.go
View file @
872b2497
...
@@ -75,7 +75,7 @@ type Gui struct {
...
@@ -75,7 +75,7 @@ type Gui struct {
logLevel
logger
.
LogLevel
logLevel
logger
.
LogLevel
open
bool
open
bool
xeth
*
xeth
.
JS
XEth
xeth
*
xeth
.
XEth
Session
string
Session
string
clientIdentity
*
p2p
.
SimpleClientIdentity
clientIdentity
*
p2p
.
SimpleClientIdentity
...
@@ -93,7 +93,7 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
...
@@ -93,7 +93,7 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
panic
(
err
)
panic
(
err
)
}
}
xeth
:=
xeth
.
New
JSXEth
(
ethereum
)
xeth
:=
xeth
.
New
(
ethereum
)
gui
:=
&
Gui
{
eth
:
ethereum
,
gui
:=
&
Gui
{
eth
:
ethereum
,
txDb
:
db
,
txDb
:
db
,
xeth
:
xeth
,
xeth
:
xeth
,
...
@@ -120,9 +120,9 @@ func (gui *Gui) Start(assetPath string) {
...
@@ -120,9 +120,9 @@ func (gui *Gui) Start(assetPath string) {
// Register ethereum functions
// Register ethereum functions
qml
.
RegisterTypes
(
"Ethereum"
,
1
,
0
,
[]
qml
.
TypeSpec
{{
qml
.
RegisterTypes
(
"Ethereum"
,
1
,
0
,
[]
qml
.
TypeSpec
{{
Init
:
func
(
p
*
xeth
.
JS
Block
,
obj
qml
.
Object
)
{
p
.
Number
=
0
;
p
.
Hash
=
""
},
Init
:
func
(
p
*
xeth
.
Block
,
obj
qml
.
Object
)
{
p
.
Number
=
0
;
p
.
Hash
=
""
},
},
{
},
{
Init
:
func
(
p
*
xeth
.
JS
Transaction
,
obj
qml
.
Object
)
{
p
.
Value
=
""
;
p
.
Hash
=
""
;
p
.
Address
=
""
},
Init
:
func
(
p
*
xeth
.
Transaction
,
obj
qml
.
Object
)
{
p
.
Value
=
""
;
p
.
Hash
=
""
;
p
.
Address
=
""
},
},
{
},
{
Init
:
func
(
p
*
xeth
.
KeyVal
,
obj
qml
.
Object
)
{
p
.
Key
=
""
;
p
.
Value
=
""
},
Init
:
func
(
p
*
xeth
.
KeyVal
,
obj
qml
.
Object
)
{
p
.
Key
=
""
;
p
.
Value
=
""
},
}})
}})
...
@@ -276,7 +276,7 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
...
@@ -276,7 +276,7 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
}
}
var
(
var
(
ptx
=
xeth
.
New
JS
Tx
(
tx
)
ptx
=
xeth
.
NewTx
(
tx
)
send
=
ethutil
.
Bytes2Hex
(
tx
.
From
())
send
=
ethutil
.
Bytes2Hex
(
tx
.
From
())
rec
=
ethutil
.
Bytes2Hex
(
tx
.
To
())
rec
=
ethutil
.
Bytes2Hex
(
tx
.
To
())
)
)
...
@@ -303,7 +303,7 @@ func (gui *Gui) readPreviousTransactions() {
...
@@ -303,7 +303,7 @@ func (gui *Gui) readPreviousTransactions() {
func
(
gui
*
Gui
)
processBlock
(
block
*
types
.
Block
,
initial
bool
)
{
func
(
gui
*
Gui
)
processBlock
(
block
*
types
.
Block
,
initial
bool
)
{
name
:=
ethutil
.
Bytes2Hex
(
block
.
Coinbase
())
name
:=
ethutil
.
Bytes2Hex
(
block
.
Coinbase
())
b
:=
xeth
.
New
JS
Block
(
block
)
b
:=
xeth
.
NewBlock
(
block
)
b
.
Name
=
name
b
.
Name
=
name
gui
.
getObjectByName
(
"chainView"
)
.
Call
(
"addBlock"
,
b
,
initial
)
gui
.
getObjectByName
(
"chainView"
)
.
Call
(
"addBlock"
,
b
,
initial
)
...
...
cmd/mist/html_container.go
View file @
872b2497
...
@@ -142,7 +142,7 @@ func (app *HtmlApplication) Window() *qml.Window {
...
@@ -142,7 +142,7 @@ func (app *HtmlApplication) Window() *qml.Window {
}
}
func
(
app
*
HtmlApplication
)
NewBlock
(
block
*
types
.
Block
)
{
func
(
app
*
HtmlApplication
)
NewBlock
(
block
*
types
.
Block
)
{
b
:=
&
xeth
.
JS
Block
{
Number
:
int
(
block
.
NumberU64
()),
Hash
:
ethutil
.
Bytes2Hex
(
block
.
Hash
())}
b
:=
&
xeth
.
Block
{
Number
:
int
(
block
.
NumberU64
()),
Hash
:
ethutil
.
Bytes2Hex
(
block
.
Hash
())}
app
.
webView
.
Call
(
"onNewBlockCb"
,
b
)
app
.
webView
.
Call
(
"onNewBlockCb"
,
b
)
}
}
...
...
cmd/mist/qml_container.go
View file @
872b2497
...
@@ -70,7 +70,7 @@ func (app *QmlApplication) NewWatcher(quitChan chan bool) {
...
@@ -70,7 +70,7 @@ func (app *QmlApplication) NewWatcher(quitChan chan bool) {
// Events
// Events
func
(
app
*
QmlApplication
)
NewBlock
(
block
*
types
.
Block
)
{
func
(
app
*
QmlApplication
)
NewBlock
(
block
*
types
.
Block
)
{
pblock
:=
&
xeth
.
JS
Block
{
Number
:
int
(
block
.
NumberU64
()),
Hash
:
ethutil
.
Bytes2Hex
(
block
.
Hash
())}
pblock
:=
&
xeth
.
Block
{
Number
:
int
(
block
.
NumberU64
()),
Hash
:
ethutil
.
Bytes2Hex
(
block
.
Hash
())}
app
.
win
.
Call
(
"onNewBlockCb"
,
pblock
)
app
.
win
.
Call
(
"onNewBlockCb"
,
pblock
)
}
}
...
...
cmd/mist/ui_lib.go
View file @
872b2497
...
@@ -44,7 +44,7 @@ type memAddr struct {
...
@@ -44,7 +44,7 @@ type memAddr struct {
// UI Library that has some basic functionality exposed
// UI Library that has some basic functionality exposed
type
UiLib
struct
{
type
UiLib
struct
{
*
xeth
.
JS
XEth
*
xeth
.
XEth
engine
*
qml
.
Engine
engine
*
qml
.
Engine
eth
*
eth
.
Ethereum
eth
*
eth
.
Ethereum
connected
bool
connected
bool
...
@@ -63,7 +63,7 @@ type UiLib struct {
...
@@ -63,7 +63,7 @@ type UiLib struct {
}
}
func
NewUiLib
(
engine
*
qml
.
Engine
,
eth
*
eth
.
Ethereum
,
assetPath
string
)
*
UiLib
{
func
NewUiLib
(
engine
*
qml
.
Engine
,
eth
*
eth
.
Ethereum
,
assetPath
string
)
*
UiLib
{
lib
:=
&
UiLib
{
JSXEth
:
xeth
.
NewJSXEth
(
eth
),
engine
:
engine
,
eth
:
eth
,
assetPath
:
assetPath
,
jsEngine
:
javascript
.
NewJSRE
(
eth
),
filterCallbacks
:
make
(
map
[
int
][]
int
)}
//, filters: make(map[int]*xeth.JSFilter)}
lib
:=
&
UiLib
{
XEth
:
xeth
.
New
(
eth
),
engine
:
engine
,
eth
:
eth
,
assetPath
:
assetPath
,
jsEngine
:
javascript
.
NewJSRE
(
eth
),
filterCallbacks
:
make
(
map
[
int
][]
int
)}
//, filters: make(map[int]*xeth.JSFilter)}
lib
.
miner
=
miner
.
New
(
eth
.
KeyManager
()
.
Address
(),
eth
)
lib
.
miner
=
miner
.
New
(
eth
.
KeyManager
()
.
Address
(),
eth
)
lib
.
filterManager
=
filter
.
NewFilterManager
(
eth
.
EventMux
())
lib
.
filterManager
=
filter
.
NewFilterManager
(
eth
.
EventMux
())
go
lib
.
filterManager
.
Start
()
go
lib
.
filterManager
.
Start
()
...
@@ -180,7 +180,7 @@ func (self *UiLib) StartDebugger() {
...
@@ -180,7 +180,7 @@ func (self *UiLib) StartDebugger() {
func
(
self
*
UiLib
)
Transact
(
params
map
[
string
]
interface
{})
(
string
,
error
)
{
func
(
self
*
UiLib
)
Transact
(
params
map
[
string
]
interface
{})
(
string
,
error
)
{
object
:=
mapToTxParams
(
params
)
object
:=
mapToTxParams
(
params
)
return
self
.
JS
XEth
.
Transact
(
return
self
.
XEth
.
Transact
(
object
[
"from"
],
object
[
"from"
],
object
[
"to"
],
object
[
"to"
],
object
[
"value"
],
object
[
"value"
],
...
@@ -202,7 +202,7 @@ func (self *UiLib) Compile(code string) (string, error) {
...
@@ -202,7 +202,7 @@ func (self *UiLib) Compile(code string) (string, error) {
func
(
self
*
UiLib
)
Call
(
params
map
[
string
]
interface
{})
(
string
,
error
)
{
func
(
self
*
UiLib
)
Call
(
params
map
[
string
]
interface
{})
(
string
,
error
)
{
object
:=
mapToTxParams
(
params
)
object
:=
mapToTxParams
(
params
)
return
self
.
JS
XEth
.
Execute
(
return
self
.
XEth
.
Execute
(
object
[
"to"
],
object
[
"to"
],
object
[
"value"
],
object
[
"value"
],
object
[
"gas"
],
object
[
"gas"
],
...
@@ -261,7 +261,7 @@ func (self *UiLib) ToAscii(data string) string {
...
@@ -261,7 +261,7 @@ func (self *UiLib) ToAscii(data string) string {
func
(
self
*
UiLib
)
NewFilter
(
object
map
[
string
]
interface
{},
view
*
qml
.
Common
)
(
id
int
)
{
func
(
self
*
UiLib
)
NewFilter
(
object
map
[
string
]
interface
{},
view
*
qml
.
Common
)
(
id
int
)
{
filter
:=
qt
.
NewFilterFromMap
(
object
,
self
.
eth
)
filter
:=
qt
.
NewFilterFromMap
(
object
,
self
.
eth
)
filter
.
MessageCallback
=
func
(
messages
state
.
Messages
)
{
filter
.
MessageCallback
=
func
(
messages
state
.
Messages
)
{
view
.
Call
(
"messages"
,
xeth
.
To
JS
Messages
(
messages
),
id
)
view
.
Call
(
"messages"
,
xeth
.
ToMessages
(
messages
),
id
)
}
}
id
=
self
.
filterManager
.
InstallFilter
(
filter
)
id
=
self
.
filterManager
.
InstallFilter
(
filter
)
return
id
return
id
...
@@ -279,7 +279,7 @@ func (self *UiLib) NewFilterString(typ string, view *qml.Common) (id int) {
...
@@ -279,7 +279,7 @@ func (self *UiLib) NewFilterString(typ string, view *qml.Common) (id int) {
func
(
self
*
UiLib
)
Messages
(
id
int
)
*
ethutil
.
List
{
func
(
self
*
UiLib
)
Messages
(
id
int
)
*
ethutil
.
List
{
filter
:=
self
.
filterManager
.
GetFilter
(
id
)
filter
:=
self
.
filterManager
.
GetFilter
(
id
)
if
filter
!=
nil
{
if
filter
!=
nil
{
messages
:=
xeth
.
To
JS
Messages
(
filter
.
Find
())
messages
:=
xeth
.
ToMessages
(
filter
.
Find
())
return
messages
return
messages
}
}
...
...
cmd/utils/cmd.go
View file @
872b2497
...
@@ -194,7 +194,7 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
...
@@ -194,7 +194,7 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
func
StartRpc
(
ethereum
*
eth
.
Ethereum
,
RpcPort
int
)
{
func
StartRpc
(
ethereum
*
eth
.
Ethereum
,
RpcPort
int
)
{
var
err
error
var
err
error
ethereum
.
RpcServer
,
err
=
rpchttp
.
NewRpcHttpServer
(
xeth
.
New
JSXEth
(
ethereum
),
RpcPort
)
ethereum
.
RpcServer
,
err
=
rpchttp
.
NewRpcHttpServer
(
xeth
.
New
(
ethereum
),
RpcPort
)
if
err
!=
nil
{
if
err
!=
nil
{
clilogger
.
Errorf
(
"Could not start RPC interface (port %v): %v"
,
RpcPort
,
err
)
clilogger
.
Errorf
(
"Could not start RPC interface (port %v): %v"
,
RpcPort
,
err
)
}
else
{
}
else
{
...
...
javascript/javascript_runtime.go
View file @
872b2497
...
@@ -24,7 +24,7 @@ var jsrelogger = logger.NewLogger("JSRE")
...
@@ -24,7 +24,7 @@ var jsrelogger = logger.NewLogger("JSRE")
type
JSRE
struct
{
type
JSRE
struct
{
ethereum
*
eth
.
Ethereum
ethereum
*
eth
.
Ethereum
Vm
*
otto
.
Otto
Vm
*
otto
.
Otto
pipe
*
xeth
.
JS
XEth
pipe
*
xeth
.
XEth
events
event
.
Subscription
events
event
.
Subscription
...
@@ -49,7 +49,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
...
@@ -49,7 +49,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
re
:=
&
JSRE
{
re
:=
&
JSRE
{
ethereum
,
ethereum
,
otto
.
New
(),
otto
.
New
(),
xeth
.
New
JSXEth
(
ethereum
),
xeth
.
New
(
ethereum
),
nil
,
nil
,
make
(
map
[
string
][]
otto
.
Value
),
make
(
map
[
string
][]
otto
.
Value
),
}
}
...
...
javascript/types.go
View file @
872b2497
...
@@ -12,14 +12,14 @@ import (
...
@@ -12,14 +12,14 @@ import (
)
)
type
JSStateObject
struct
{
type
JSStateObject
struct
{
*
xeth
.
JS
Object
*
xeth
.
Object
eth
*
JSEthereum
eth
*
JSEthereum
}
}
func
(
self
*
JSStateObject
)
EachStorage
(
call
otto
.
FunctionCall
)
otto
.
Value
{
func
(
self
*
JSStateObject
)
EachStorage
(
call
otto
.
FunctionCall
)
otto
.
Value
{
cb
:=
call
.
Argument
(
0
)
cb
:=
call
.
Argument
(
0
)
it
:=
self
.
JS
Object
.
Trie
()
.
Iterator
()
it
:=
self
.
Object
.
Trie
()
.
Iterator
()
for
it
.
Next
()
{
for
it
.
Next
()
{
cb
.
Call
(
self
.
eth
.
toVal
(
self
),
self
.
eth
.
toVal
(
ethutil
.
Bytes2Hex
(
it
.
Key
)),
self
.
eth
.
toVal
(
ethutil
.
Bytes2Hex
(
it
.
Value
)))
cb
.
Call
(
self
.
eth
.
toVal
(
self
),
self
.
eth
.
toVal
(
ethutil
.
Bytes2Hex
(
it
.
Key
)),
self
.
eth
.
toVal
(
ethutil
.
Bytes2Hex
(
it
.
Value
)))
}
}
...
@@ -30,12 +30,12 @@ func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value {
...
@@ -30,12 +30,12 @@ func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value {
// The JSEthereum object attempts to wrap the PEthereum object and returns
// The JSEthereum object attempts to wrap the PEthereum object and returns
// meaningful javascript objects
// meaningful javascript objects
type
JSBlock
struct
{
type
JSBlock
struct
{
*
xeth
.
JS
Block
*
xeth
.
Block
eth
*
JSEthereum
eth
*
JSEthereum
}
}
func
(
self
*
JSBlock
)
GetTransaction
(
hash
string
)
otto
.
Value
{
func
(
self
*
JSBlock
)
GetTransaction
(
hash
string
)
otto
.
Value
{
return
self
.
eth
.
toVal
(
self
.
JS
Block
.
GetTransaction
(
hash
))
return
self
.
eth
.
toVal
(
self
.
Block
.
GetTransaction
(
hash
))
}
}
type
JSMessage
struct
{
type
JSMessage
struct
{
...
@@ -67,27 +67,27 @@ func NewJSMessage(message *state.Message) JSMessage {
...
@@ -67,27 +67,27 @@ func NewJSMessage(message *state.Message) JSMessage {
}
}
type
JSEthereum
struct
{
type
JSEthereum
struct
{
*
xeth
.
JS
XEth
*
xeth
.
XEth
vm
*
otto
.
Otto
vm
*
otto
.
Otto
ethereum
*
eth
.
Ethereum
ethereum
*
eth
.
Ethereum
}
}
func
(
self
*
JSEthereum
)
Block
(
v
interface
{})
otto
.
Value
{
func
(
self
*
JSEthereum
)
Block
(
v
interface
{})
otto
.
Value
{
if
number
,
ok
:=
v
.
(
int64
);
ok
{
if
number
,
ok
:=
v
.
(
int64
);
ok
{
return
self
.
toVal
(
&
JSBlock
{
self
.
JS
XEth
.
BlockByNumber
(
int32
(
number
)),
self
})
return
self
.
toVal
(
&
JSBlock
{
self
.
XEth
.
BlockByNumber
(
int32
(
number
)),
self
})
}
else
if
hash
,
ok
:=
v
.
(
string
);
ok
{
}
else
if
hash
,
ok
:=
v
.
(
string
);
ok
{
return
self
.
toVal
(
&
JSBlock
{
self
.
JS
XEth
.
BlockByHash
(
hash
),
self
})
return
self
.
toVal
(
&
JSBlock
{
self
.
XEth
.
BlockByHash
(
hash
),
self
})
}
}
return
otto
.
UndefinedValue
()
return
otto
.
UndefinedValue
()
}
}
func
(
self
*
JSEthereum
)
GetStateObject
(
addr
string
)
otto
.
Value
{
func
(
self
*
JSEthereum
)
GetStateObject
(
addr
string
)
otto
.
Value
{
return
self
.
toVal
(
&
JSStateObject
{
xeth
.
NewJSObject
(
self
.
JSXEth
.
State
()
.
SafeGet
(
addr
)
),
self
})
return
self
.
toVal
(
&
JSStateObject
{
self
.
XEth
.
State
()
.
SafeGet
(
addr
),
self
})
}
}
func
(
self
*
JSEthereum
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
otto
.
Value
{
func
(
self
*
JSEthereum
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
otto
.
Value
{
r
,
err
:=
self
.
JS
XEth
.
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
)
r
,
err
:=
self
.
XEth
.
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
...
...
rpc/http/server.go
View file @
872b2497
...
@@ -29,7 +29,7 @@ import (
...
@@ -29,7 +29,7 @@ import (
var
rpchttplogger
=
logger
.
NewLogger
(
"RPC-HTTP"
)
var
rpchttplogger
=
logger
.
NewLogger
(
"RPC-HTTP"
)
var
JSON
rpc
.
JsonWrapper
var
JSON
rpc
.
JsonWrapper
func
NewRpcHttpServer
(
pipe
*
xeth
.
JS
XEth
,
port
int
)
(
*
RpcHttpServer
,
error
)
{
func
NewRpcHttpServer
(
pipe
*
xeth
.
XEth
,
port
int
)
(
*
RpcHttpServer
,
error
)
{
sport
:=
fmt
.
Sprintf
(
":%d"
,
port
)
sport
:=
fmt
.
Sprintf
(
":%d"
,
port
)
l
,
err
:=
net
.
Listen
(
"tcp"
,
sport
)
l
,
err
:=
net
.
Listen
(
"tcp"
,
sport
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -47,7 +47,7 @@ func NewRpcHttpServer(pipe *xeth.JSXEth, port int) (*RpcHttpServer, error) {
...
@@ -47,7 +47,7 @@ func NewRpcHttpServer(pipe *xeth.JSXEth, port int) (*RpcHttpServer, error) {
type
RpcHttpServer
struct
{
type
RpcHttpServer
struct
{
quit
chan
bool
quit
chan
bool
listener
net
.
Listener
listener
net
.
Listener
pipe
*
xeth
.
JS
XEth
pipe
*
xeth
.
XEth
port
int
port
int
}
}
...
...
rpc/packages.go
View file @
872b2497
...
@@ -19,8 +19,8 @@
...
@@ -19,8 +19,8 @@
For each request type, define the following:
For each request type, define the following:
1. RpcRequest "To" method [message.go], which does basic validation and conversion to "Args" type via json.Decoder()
1. RpcRequest "To" method [message.go], which does basic validation and conversion to "Args" type via json.Decoder()
2. json.Decoder() calls "Unmarshal
JS
ON" defined on each "Args" struct
2. json.Decoder() calls "UnmarshalON" defined on each "Args" struct
3. EthereumApi method, taking the "Args" type and replying with an interface to be marshalled to
JS
ON
3. EthereumApi method, taking the "Args" type and replying with an interface to be marshalled to ON
*/
*/
package
rpc
package
rpc
...
@@ -38,12 +38,12 @@ type RpcServer interface {
...
@@ -38,12 +38,12 @@ type RpcServer interface {
Stop
()
Stop
()
}
}
func
NewEthereumApi
(
xeth
*
xeth
.
JS
XEth
)
*
EthereumApi
{
func
NewEthereumApi
(
xeth
*
xeth
.
XEth
)
*
EthereumApi
{
return
&
EthereumApi
{
xeth
:
xeth
}
return
&
EthereumApi
{
xeth
:
xeth
}
}
}
type
EthereumApi
struct
{
type
EthereumApi
struct
{
xeth
*
xeth
.
JS
XEth
xeth
*
xeth
.
XEth
}
}
func
(
p
*
EthereumApi
)
GetBlock
(
args
*
GetBlockArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
GetBlock
(
args
*
GetBlockArgs
,
reply
*
interface
{})
error
{
...
@@ -162,7 +162,7 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
...
@@ -162,7 +162,7 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
}
}
func
(
p
*
EthereumApi
)
GetRequestReply
(
req
*
RpcRequest
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
GetRequestReply
(
req
*
RpcRequest
,
reply
*
interface
{})
error
{
// Spec at https://github.com/ethereum/wiki/wiki/Generic-
JS
ON-RPC
// Spec at https://github.com/ethereum/wiki/wiki/Generic-ON-RPC
rpclogger
.
DebugDetailf
(
"%T %s"
,
req
.
Params
,
req
.
Params
)
rpclogger
.
DebugDetailf
(
"%T %s"
,
req
.
Params
,
req
.
Params
)
switch
req
.
Method
{
switch
req
.
Method
{
case
"eth_coinbase"
:
case
"eth_coinbase"
:
...
...
rpc/ws/server.go
View file @
872b2497
...
@@ -75,7 +75,7 @@ func (self *WebSocketServer) Start() {
...
@@ -75,7 +75,7 @@ func (self *WebSocketServer) Start() {
wslogger
.
Infof
(
"Starting RPC-WS server on port %d"
,
self
.
port
)
wslogger
.
Infof
(
"Starting RPC-WS server on port %d"
,
self
.
port
)
go
self
.
handlerLoop
()
go
self
.
handlerLoop
()
api
:=
rpc
.
NewEthereumApi
(
xeth
.
New
JSXEth
(
self
.
eth
))
api
:=
rpc
.
NewEthereumApi
(
xeth
.
New
(
self
.
eth
))
h
:=
self
.
apiHandler
(
api
)
h
:=
self
.
apiHandler
(
api
)
http
.
Handle
(
"/ws"
,
h
)
http
.
Handle
(
"/ws"
,
h
)
...
...
xeth/object.go
deleted
100644 → 0
View file @
1146f250
package
xeth
import
(
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
)
type
Object
struct
{
*
state
.
StateObject
}
func
(
self
*
Object
)
StorageString
(
str
string
)
*
ethutil
.
Value
{
if
ethutil
.
IsHex
(
str
)
{
return
self
.
Storage
(
ethutil
.
Hex2Bytes
(
str
[
2
:
]))
}
else
{
return
self
.
Storage
(
ethutil
.
RightPadBytes
([]
byte
(
str
),
32
))
}
}
func
(
self
*
Object
)
StorageValue
(
addr
*
ethutil
.
Value
)
*
ethutil
.
Value
{
return
self
.
Storage
(
addr
.
Bytes
())
}
func
(
self
*
Object
)
Storage
(
addr
[]
byte
)
*
ethutil
.
Value
{
return
self
.
StateObject
.
GetStorage
(
ethutil
.
BigD
(
addr
))
}
xeth/
js_
types.go
→
xeth/types.go
View file @
872b2497
...
@@ -25,8 +25,32 @@ func fromHex(s string) []byte {
...
@@ -25,8 +25,32 @@ func fromHex(s string) []byte {
return
nil
return
nil
}
}
type
Object
struct
{
*
state
.
StateObject
}
func
NewObject
(
state
*
state
.
StateObject
)
*
Object
{
return
&
Object
{
state
}
}
func
(
self
*
Object
)
StorageString
(
str
string
)
*
ethutil
.
Value
{
if
ethutil
.
IsHex
(
str
)
{
return
self
.
Storage
(
ethutil
.
Hex2Bytes
(
str
[
2
:
]))
}
else
{
return
self
.
Storage
(
ethutil
.
RightPadBytes
([]
byte
(
str
),
32
))
}
}
func
(
self
*
Object
)
StorageValue
(
addr
*
ethutil
.
Value
)
*
ethutil
.
Value
{
return
self
.
Storage
(
addr
.
Bytes
())
}
func
(
self
*
Object
)
Storage
(
addr
[]
byte
)
*
ethutil
.
Value
{
return
self
.
StateObject
.
GetStorage
(
ethutil
.
BigD
(
addr
))
}
// Block interface exposed to QML
// Block interface exposed to QML
type
JS
Block
struct
{
type
Block
struct
{
//Transactions string `json:"transactions"`
//Transactions string `json:"transactions"`
ref
*
types
.
Block
ref
*
types
.
Block
Size
string
`json:"size"`
Size
string
`json:"size"`
...
@@ -45,24 +69,24 @@ type JSBlock struct {
...
@@ -45,24 +69,24 @@ type JSBlock struct {
}
}
// Creates a new QML Block from a chain block
// Creates a new QML Block from a chain block
func
New
JSBlock
(
block
*
types
.
Block
)
*
JS
Block
{
func
New
Block
(
block
*
types
.
Block
)
*
Block
{
if
block
==
nil
{
if
block
==
nil
{
return
&
JS
Block
{}
return
&
Block
{}
}
}
ptxs
:=
make
([]
*
JS
Transaction
,
len
(
block
.
Transactions
()))
ptxs
:=
make
([]
*
Transaction
,
len
(
block
.
Transactions
()))
for
i
,
tx
:=
range
block
.
Transactions
()
{
for
i
,
tx
:=
range
block
.
Transactions
()
{
ptxs
[
i
]
=
New
JS
Tx
(
tx
)
ptxs
[
i
]
=
NewTx
(
tx
)
}
}
txlist
:=
ethutil
.
NewList
(
ptxs
)
txlist
:=
ethutil
.
NewList
(
ptxs
)
puncles
:=
make
([]
*
JS
Block
,
len
(
block
.
Uncles
()))
puncles
:=
make
([]
*
Block
,
len
(
block
.
Uncles
()))
for
i
,
uncle
:=
range
block
.
Uncles
()
{
for
i
,
uncle
:=
range
block
.
Uncles
()
{
puncles
[
i
]
=
New
JS
Block
(
types
.
NewBlockWithHeader
(
uncle
))
puncles
[
i
]
=
NewBlock
(
types
.
NewBlockWithHeader
(
uncle
))
}
}
ulist
:=
ethutil
.
NewList
(
puncles
)
ulist
:=
ethutil
.
NewList
(
puncles
)
return
&
JS
Block
{
return
&
Block
{
ref
:
block
,
Size
:
block
.
Size
()
.
String
(),
ref
:
block
,
Size
:
block
.
Size
()
.
String
(),
Number
:
int
(
block
.
NumberU64
()),
GasUsed
:
block
.
GasUsed
()
.
String
(),
Number
:
int
(
block
.
NumberU64
()),
GasUsed
:
block
.
GasUsed
()
.
String
(),
GasLimit
:
block
.
GasLimit
()
.
String
(),
Hash
:
toHex
(
block
.
Hash
()),
GasLimit
:
block
.
GasLimit
()
.
String
(),
Hash
:
toHex
(
block
.
Hash
()),
...
@@ -75,7 +99,7 @@ func NewJSBlock(block *types.Block) *JSBlock {
...
@@ -75,7 +99,7 @@ func NewJSBlock(block *types.Block) *JSBlock {
}
}
}
}
func
(
self
*
JS
Block
)
ToString
()
string
{
func
(
self
*
Block
)
ToString
()
string
{
if
self
.
ref
!=
nil
{
if
self
.
ref
!=
nil
{
return
self
.
ref
.
String
()
return
self
.
ref
.
String
()
}
}
...
@@ -83,16 +107,16 @@ func (self *JSBlock) ToString() string {
...
@@ -83,16 +107,16 @@ func (self *JSBlock) ToString() string {
return
""
return
""
}
}
func
(
self
*
JSBlock
)
GetTransaction
(
hash
string
)
*
JS
Transaction
{
func
(
self
*
Block
)
GetTransaction
(
hash
string
)
*
Transaction
{
tx
:=
self
.
ref
.
Transaction
(
fromHex
(
hash
))
tx
:=
self
.
ref
.
Transaction
(
fromHex
(
hash
))
if
tx
==
nil
{
if
tx
==
nil
{
return
nil
return
nil
}
}
return
New
JS
Tx
(
tx
)
return
NewTx
(
tx
)
}
}
type
JS
Transaction
struct
{
type
Transaction
struct
{
ref
*
types
.
Transaction
ref
*
types
.
Transaction
Value
string
`json:"value"`
Value
string
`json:"value"`
...
@@ -108,7 +132,7 @@ type JSTransaction struct {
...
@@ -108,7 +132,7 @@ type JSTransaction struct {
Confirmations
int
`json:"confirmations"`
Confirmations
int
`json:"confirmations"`
}
}
func
New
JSTx
(
tx
*
types
.
Transaction
)
*
JS
Transaction
{
func
New
Tx
(
tx
*
types
.
Transaction
)
*
Transaction
{
hash
:=
toHex
(
tx
.
Hash
())
hash
:=
toHex
(
tx
.
Hash
())
receiver
:=
toHex
(
tx
.
To
())
receiver
:=
toHex
(
tx
.
To
())
if
receiver
==
"0000000000000000000000000000000000000000"
{
if
receiver
==
"0000000000000000000000000000000000000000"
{
...
@@ -124,29 +148,21 @@ func NewJSTx(tx *types.Transaction) *JSTransaction {
...
@@ -124,29 +148,21 @@ func NewJSTx(tx *types.Transaction) *JSTransaction {
data
=
toHex
(
tx
.
Data
())
data
=
toHex
(
tx
.
Data
())
}
}
return
&
JS
Transaction
{
ref
:
tx
,
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
()),
Address
:
receiver
,
Contract
:
createsContract
,
Gas
:
tx
.
Gas
()
.
String
(),
GasPrice
:
tx
.
GasPrice
()
.
String
(),
Data
:
data
,
Sender
:
sender
,
CreatesContract
:
createsContract
,
RawData
:
toHex
(
tx
.
Data
())}
return
&
Transaction
{
ref
:
tx
,
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
()),
Address
:
receiver
,
Contract
:
createsContract
,
Gas
:
tx
.
Gas
()
.
String
(),
GasPrice
:
tx
.
GasPrice
()
.
String
(),
Data
:
data
,
Sender
:
sender
,
CreatesContract
:
createsContract
,
RawData
:
toHex
(
tx
.
Data
())}
}
}
func
(
self
*
JS
Transaction
)
ToString
()
string
{
func
(
self
*
Transaction
)
ToString
()
string
{
return
self
.
ref
.
String
()
return
self
.
ref
.
String
()
}
}
type
JS
Key
struct
{
type
Key
struct
{
Address
string
`json:"address"`
Address
string
`json:"address"`
PrivateKey
string
`json:"privateKey"`
PrivateKey
string
`json:"privateKey"`
PublicKey
string
`json:"publicKey"`
PublicKey
string
`json:"publicKey"`
}
}
func
NewJSKey
(
key
*
crypto
.
KeyPair
)
*
JSKey
{
func
NewKey
(
key
*
crypto
.
KeyPair
)
*
Key
{
return
&
JSKey
{
toHex
(
key
.
Address
()),
toHex
(
key
.
PrivateKey
),
toHex
(
key
.
PublicKey
)}
return
&
Key
{
toHex
(
key
.
Address
()),
toHex
(
key
.
PrivateKey
),
toHex
(
key
.
PublicKey
)}
}
type
JSObject
struct
{
*
Object
}
func
NewJSObject
(
object
*
Object
)
*
JSObject
{
return
&
JSObject
{
object
}
}
}
type
PReceipt
struct
{
type
PReceipt
struct
{
...
@@ -167,20 +183,20 @@ func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *
...
@@ -167,20 +183,20 @@ func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *
// Peer interface exposed to QML
// Peer interface exposed to QML
type
JS
Peer
struct
{
type
Peer
struct
{
ref
*
p2p
.
Peer
ref
*
p2p
.
Peer
Ip
string
`json:"ip"`
Ip
string
`json:"ip"`
Version
string
`json:"version"`
Version
string
`json:"version"`
Caps
string
`json:"caps"`
Caps
string
`json:"caps"`
}
}
func
New
JSPeer
(
peer
*
p2p
.
Peer
)
*
JS
Peer
{
func
New
Peer
(
peer
*
p2p
.
Peer
)
*
Peer
{
var
caps
[]
string
var
caps
[]
string
for
_
,
cap
:=
range
peer
.
Caps
()
{
for
_
,
cap
:=
range
peer
.
Caps
()
{
caps
=
append
(
caps
,
fmt
.
Sprintf
(
"%s/%d"
,
cap
.
Name
,
cap
.
Version
))
caps
=
append
(
caps
,
fmt
.
Sprintf
(
"%s/%d"
,
cap
.
Name
,
cap
.
Version
))
}
}
return
&
JS
Peer
{
return
&
Peer
{
ref
:
peer
,
ref
:
peer
,
Ip
:
fmt
.
Sprintf
(
"%v"
,
peer
.
RemoteAddr
()),
Ip
:
fmt
.
Sprintf
(
"%v"
,
peer
.
RemoteAddr
()),
Version
:
fmt
.
Sprintf
(
"%v"
,
peer
.
Identity
()),
Version
:
fmt
.
Sprintf
(
"%v"
,
peer
.
Identity
()),
...
@@ -188,15 +204,15 @@ func NewJSPeer(peer *p2p.Peer) *JSPeer {
...
@@ -188,15 +204,15 @@ func NewJSPeer(peer *p2p.Peer) *JSPeer {
}
}
}
}
type
JS
Receipt
struct
{
type
Receipt
struct
{
CreatedContract
bool
`json:"createdContract"`
CreatedContract
bool
`json:"createdContract"`
Address
string
`json:"address"`
Address
string
`json:"address"`
Hash
string
`json:"hash"`
Hash
string
`json:"hash"`
Sender
string
`json:"sender"`
Sender
string
`json:"sender"`
}
}
func
New
JSReciept
(
contractCreation
bool
,
creationAddress
,
hash
,
address
[]
byte
)
*
JS
Receipt
{
func
New
Reciept
(
contractCreation
bool
,
creationAddress
,
hash
,
address
[]
byte
)
*
Receipt
{
return
&
JS
Receipt
{
return
&
Receipt
{
contractCreation
,
contractCreation
,
toHex
(
creationAddress
),
toHex
(
creationAddress
),
toHex
(
hash
),
toHex
(
hash
),
...
@@ -204,7 +220,7 @@ func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte)
...
@@ -204,7 +220,7 @@ func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte)
}
}
}
}
type
JS
Message
struct
{
type
Message
struct
{
To
string
`json:"to"`
To
string
`json:"to"`
From
string
`json:"from"`
From
string
`json:"from"`
Input
string
`json:"input"`
Input
string
`json:"input"`
...
@@ -218,8 +234,8 @@ type JSMessage struct {
...
@@ -218,8 +234,8 @@ type JSMessage struct {
Value
string
`json:"value"`
Value
string
`json:"value"`
}
}
func
New
JSMessage
(
message
*
state
.
Message
)
JS
Message
{
func
New
Message
(
message
*
state
.
Message
)
Message
{
return
JS
Message
{
return
Message
{
To
:
toHex
(
message
.
To
),
To
:
toHex
(
message
.
To
),
From
:
toHex
(
message
.
From
),
From
:
toHex
(
message
.
From
),
Input
:
toHex
(
message
.
Input
),
Input
:
toHex
(
message
.
Input
),
...
...
xeth/world.go
View file @
872b2497
...
@@ -3,10 +3,10 @@ package xeth
...
@@ -3,10 +3,10 @@ package xeth
import
"github.com/ethereum/go-ethereum/state"
import
"github.com/ethereum/go-ethereum/state"
type
State
struct
{
type
State
struct
{
xeth
*
JS
XEth
xeth
*
XEth
}
}
func
NewState
(
xeth
*
JS
XEth
)
*
State
{
func
NewState
(
xeth
*
XEth
)
*
State
{
return
&
State
{
xeth
}
return
&
State
{
xeth
}
}
}
...
...
xeth/xeth.go
View file @
872b2497
...
@@ -31,15 +31,15 @@ type Backend interface {
...
@@ -31,15 +31,15 @@ type Backend interface {
TxPool
()
*
core
.
TxPool
TxPool
()
*
core
.
TxPool
}
}
type
JS
XEth
struct
{
type
XEth
struct
{
eth
Backend
eth
Backend
blockProcessor
*
core
.
BlockProcessor
blockProcessor
*
core
.
BlockProcessor
chainManager
*
core
.
ChainManager
chainManager
*
core
.
ChainManager
world
*
State
world
*
State
}
}
func
New
JSXEth
(
eth
Backend
)
*
JS
XEth
{
func
New
(
eth
Backend
)
*
XEth
{
xeth
:=
&
JS
XEth
{
xeth
:=
&
XEth
{
eth
:
eth
,
eth
:
eth
,
blockProcessor
:
eth
.
BlockProcessor
(),
blockProcessor
:
eth
.
BlockProcessor
(),
chainManager
:
eth
.
ChainManager
(),
chainManager
:
eth
.
ChainManager
(),
...
@@ -49,24 +49,24 @@ func NewJSXEth(eth Backend) *JSXEth {
...
@@ -49,24 +49,24 @@ func NewJSXEth(eth Backend) *JSXEth {
return
xeth
return
xeth
}
}
func
(
self
*
JS
XEth
)
State
()
*
State
{
return
self
.
world
}
func
(
self
*
XEth
)
State
()
*
State
{
return
self
.
world
}
func
(
self
*
JSXEth
)
BlockByHash
(
strHash
string
)
*
JS
Block
{
func
(
self
*
XEth
)
BlockByHash
(
strHash
string
)
*
Block
{
hash
:=
fromHex
(
strHash
)
hash
:=
fromHex
(
strHash
)
block
:=
self
.
chainManager
.
GetBlock
(
hash
)
block
:=
self
.
chainManager
.
GetBlock
(
hash
)
return
New
JS
Block
(
block
)
return
NewBlock
(
block
)
}
}
func
(
self
*
JSXEth
)
BlockByNumber
(
num
int32
)
*
JS
Block
{
func
(
self
*
XEth
)
BlockByNumber
(
num
int32
)
*
Block
{
if
num
==
-
1
{
if
num
==
-
1
{
return
New
JS
Block
(
self
.
chainManager
.
CurrentBlock
())
return
NewBlock
(
self
.
chainManager
.
CurrentBlock
())
}
}
return
New
JS
Block
(
self
.
chainManager
.
GetBlockByNumber
(
uint64
(
num
)))
return
NewBlock
(
self
.
chainManager
.
GetBlockByNumber
(
uint64
(
num
)))
}
}
func
(
self
*
JSXEth
)
Block
(
v
interface
{})
*
JS
Block
{
func
(
self
*
XEth
)
Block
(
v
interface
{})
*
Block
{
if
n
,
ok
:=
v
.
(
int32
);
ok
{
if
n
,
ok
:=
v
.
(
int32
);
ok
{
return
self
.
BlockByNumber
(
n
)
return
self
.
BlockByNumber
(
n
)
}
else
if
str
,
ok
:=
v
.
(
string
);
ok
{
}
else
if
str
,
ok
:=
v
.
(
string
);
ok
{
...
@@ -78,63 +78,63 @@ func (self *JSXEth) Block(v interface{}) *JSBlock {
...
@@ -78,63 +78,63 @@ func (self *JSXEth) Block(v interface{}) *JSBlock {
return
nil
return
nil
}
}
func
(
self
*
JS
XEth
)
Accounts
()
[]
string
{
func
(
self
*
XEth
)
Accounts
()
[]
string
{
return
[]
string
{
toHex
(
self
.
eth
.
KeyManager
()
.
Address
())}
return
[]
string
{
toHex
(
self
.
eth
.
KeyManager
()
.
Address
())}
}
}
/*
/*
func (self *
JSXEth) StateObject(addr string) *JS
Object {
func (self *
XEth) StateObject(addr string) *
Object {
object := &Object{self.State().safeGet(fromHex(addr))}
object := &Object{self.State().safeGet(fromHex(addr))}
return New
JS
Object(object)
return NewObject(object)
}
}
*/
*/
func
(
self
*
JS
XEth
)
PeerCount
()
int
{
func
(
self
*
XEth
)
PeerCount
()
int
{
return
self
.
eth
.
PeerCount
()
return
self
.
eth
.
PeerCount
()
}
}
func
(
self
*
JS
XEth
)
IsMining
()
bool
{
func
(
self
*
XEth
)
IsMining
()
bool
{
return
self
.
eth
.
IsMining
()
return
self
.
eth
.
IsMining
()
}
}
func
(
self
*
JS
XEth
)
IsListening
()
bool
{
func
(
self
*
XEth
)
IsListening
()
bool
{
return
self
.
eth
.
IsListening
()
return
self
.
eth
.
IsListening
()
}
}
func
(
self
*
JS
XEth
)
Coinbase
()
string
{
func
(
self
*
XEth
)
Coinbase
()
string
{
return
toHex
(
self
.
eth
.
KeyManager
()
.
Address
())
return
toHex
(
self
.
eth
.
KeyManager
()
.
Address
())
}
}
func
(
self
*
JS
XEth
)
NumberToHuman
(
balance
string
)
string
{
func
(
self
*
XEth
)
NumberToHuman
(
balance
string
)
string
{
b
:=
ethutil
.
Big
(
balance
)
b
:=
ethutil
.
Big
(
balance
)
return
ethutil
.
CurrencyToString
(
b
)
return
ethutil
.
CurrencyToString
(
b
)
}
}
func
(
self
*
JS
XEth
)
StorageAt
(
addr
,
storageAddr
string
)
string
{
func
(
self
*
XEth
)
StorageAt
(
addr
,
storageAddr
string
)
string
{
storage
:=
self
.
State
()
.
SafeGet
(
addr
)
.
StorageString
(
storageAddr
)
storage
:=
self
.
State
()
.
SafeGet
(
addr
)
.
StorageString
(
storageAddr
)
return
toHex
(
storage
.
Bytes
())
return
toHex
(
storage
.
Bytes
())
}
}
func
(
self
*
JS
XEth
)
BalanceAt
(
addr
string
)
string
{
func
(
self
*
XEth
)
BalanceAt
(
addr
string
)
string
{
return
self
.
State
()
.
SafeGet
(
addr
)
.
Balance
()
.
String
()
return
self
.
State
()
.
SafeGet
(
addr
)
.
Balance
()
.
String
()
}
}
func
(
self
*
JS
XEth
)
TxCountAt
(
address
string
)
int
{
func
(
self
*
XEth
)
TxCountAt
(
address
string
)
int
{
return
int
(
self
.
State
()
.
SafeGet
(
address
)
.
Nonce
)
return
int
(
self
.
State
()
.
SafeGet
(
address
)
.
Nonce
)
}
}
func
(
self
*
JS
XEth
)
CodeAt
(
address
string
)
string
{
func
(
self
*
XEth
)
CodeAt
(
address
string
)
string
{
return
toHex
(
self
.
State
()
.
SafeGet
(
address
)
.
Code
)
return
toHex
(
self
.
State
()
.
SafeGet
(
address
)
.
Code
)
}
}
func
(
self
*
JS
XEth
)
IsContract
(
address
string
)
bool
{
func
(
self
*
XEth
)
IsContract
(
address
string
)
bool
{
return
len
(
self
.
State
()
.
SafeGet
(
address
)
.
Code
)
>
0
return
len
(
self
.
State
()
.
SafeGet
(
address
)
.
Code
)
>
0
}
}
func
(
self
*
JS
XEth
)
SecretToAddress
(
key
string
)
string
{
func
(
self
*
XEth
)
SecretToAddress
(
key
string
)
string
{
pair
,
err
:=
crypto
.
NewKeyPairFromSec
(
fromHex
(
key
))
pair
,
err
:=
crypto
.
NewKeyPairFromSec
(
fromHex
(
key
))
if
err
!=
nil
{
if
err
!=
nil
{
return
""
return
""
...
@@ -143,7 +143,7 @@ func (self *JSXEth) SecretToAddress(key string) string {
...
@@ -143,7 +143,7 @@ func (self *JSXEth) SecretToAddress(key string) string {
return
toHex
(
pair
.
Address
())
return
toHex
(
pair
.
Address
())
}
}
func
(
self
*
JS
XEth
)
Execute
(
addr
,
value
,
gas
,
price
,
data
string
)
(
string
,
error
)
{
func
(
self
*
XEth
)
Execute
(
addr
,
value
,
gas
,
price
,
data
string
)
(
string
,
error
)
{
return
""
,
nil
return
""
,
nil
}
}
...
@@ -152,7 +152,7 @@ type KeyVal struct {
...
@@ -152,7 +152,7 @@ type KeyVal struct {
Value
string
`json:"value"`
Value
string
`json:"value"`
}
}
func
(
self
*
JS
XEth
)
EachStorage
(
addr
string
)
string
{
func
(
self
*
XEth
)
EachStorage
(
addr
string
)
string
{
var
values
[]
KeyVal
var
values
[]
KeyVal
object
:=
self
.
State
()
.
SafeGet
(
addr
)
object
:=
self
.
State
()
.
SafeGet
(
addr
)
it
:=
object
.
Trie
()
.
Iterator
()
it
:=
object
.
Trie
()
.
Iterator
()
...
@@ -168,13 +168,13 @@ func (self *JSXEth) EachStorage(addr string) string {
...
@@ -168,13 +168,13 @@ func (self *JSXEth) EachStorage(addr string) string {
return
string
(
valuesJson
)
return
string
(
valuesJson
)
}
}
func
(
self
*
JS
XEth
)
ToAscii
(
str
string
)
string
{
func
(
self
*
XEth
)
ToAscii
(
str
string
)
string
{
padded
:=
ethutil
.
RightPadBytes
([]
byte
(
str
),
32
)
padded
:=
ethutil
.
RightPadBytes
([]
byte
(
str
),
32
)
return
"0x"
+
toHex
(
padded
)
return
"0x"
+
toHex
(
padded
)
}
}
func
(
self
*
JS
XEth
)
FromAscii
(
str
string
)
string
{
func
(
self
*
XEth
)
FromAscii
(
str
string
)
string
{
if
ethutil
.
IsHex
(
str
)
{
if
ethutil
.
IsHex
(
str
)
{
str
=
str
[
2
:
]
str
=
str
[
2
:
]
}
}
...
@@ -182,7 +182,7 @@ func (self *JSXEth) FromAscii(str string) string {
...
@@ -182,7 +182,7 @@ func (self *JSXEth) FromAscii(str string) string {
return
string
(
bytes
.
Trim
(
fromHex
(
str
),
"
\x00
"
))
return
string
(
bytes
.
Trim
(
fromHex
(
str
),
"
\x00
"
))
}
}
func
(
self
*
JS
XEth
)
FromNumber
(
str
string
)
string
{
func
(
self
*
XEth
)
FromNumber
(
str
string
)
string
{
if
ethutil
.
IsHex
(
str
)
{
if
ethutil
.
IsHex
(
str
)
{
str
=
str
[
2
:
]
str
=
str
[
2
:
]
}
}
...
@@ -190,20 +190,20 @@ func (self *JSXEth) FromNumber(str string) string {
...
@@ -190,20 +190,20 @@ func (self *JSXEth) FromNumber(str string) string {
return
ethutil
.
BigD
(
fromHex
(
str
))
.
String
()
return
ethutil
.
BigD
(
fromHex
(
str
))
.
String
()
}
}
func
(
self
*
JS
XEth
)
Transact
(
key
,
toStr
,
valueStr
,
gasStr
,
gasPriceStr
,
codeStr
string
)
(
string
,
error
)
{
func
(
self
*
XEth
)
Transact
(
key
,
toStr
,
valueStr
,
gasStr
,
gasPriceStr
,
codeStr
string
)
(
string
,
error
)
{
return
""
,
nil
return
""
,
nil
}
}
func
To
JS
Messages
(
messages
state
.
Messages
)
*
ethutil
.
List
{
func
ToMessages
(
messages
state
.
Messages
)
*
ethutil
.
List
{
var
msgs
[]
JS
Message
var
msgs
[]
Message
for
_
,
m
:=
range
messages
{
for
_
,
m
:=
range
messages
{
msgs
=
append
(
msgs
,
New
JS
Message
(
m
))
msgs
=
append
(
msgs
,
NewMessage
(
m
))
}
}
return
ethutil
.
NewList
(
msgs
)
return
ethutil
.
NewList
(
msgs
)
}
}
func
(
self
*
JS
XEth
)
PushTx
(
encodedTx
string
)
(
string
,
error
)
{
func
(
self
*
XEth
)
PushTx
(
encodedTx
string
)
(
string
,
error
)
{
tx
:=
types
.
NewTransactionFromBytes
(
fromHex
(
encodedTx
))
tx
:=
types
.
NewTransactionFromBytes
(
fromHex
(
encodedTx
))
err
:=
self
.
eth
.
TxPool
()
.
Add
(
tx
)
err
:=
self
.
eth
.
TxPool
()
.
Add
(
tx
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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