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
4051c033
Commit
4051c033
authored
Dec 22, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added whisper js api
parent
e4251775
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
153 additions
and
130 deletions
+153
-130
browser.qml
cmd/mist/assets/qml/browser.qml
+35
-5
whisper.qml
cmd/mist/assets/qml/views/whisper.qml
+1
-1
gui.go
cmd/mist/gui.go
+32
-32
ui_lib.go
cmd/mist/ui_lib.go
+77
-85
message.go
ui/qt/qwhisper/message.go
+2
-2
whisper.go
ui/qt/qwhisper/whisper.go
+5
-4
whisper.go
whisper/whisper.go
+1
-1
No files found.
cmd/mist/assets/qml/browser.qml
View file @
4051c033
...
@@ -59,15 +59,18 @@ Rectangle {
...
@@ -59,15 +59,18 @@ Rectangle {
}
}
Component.onCompleted
:
{
Component.onCompleted
:
{
//webview.url = "http://etherian.io"
webview
.
url
=
"http://etherian.io"
webview
.
url
=
"file:///Users/jeffrey/test.html"
}
}
signal
messages
(
var
messages
,
int
id
);
signal
messages
(
var
messages
,
int
id
);
onMessages
:
{
onMessages
:
{
// Bit of a cheat to get proper JSON
// Bit of a cheat to get proper JSON
var
m
=
JSON
.
parse
(
JSON
.
parse
(
JSON
.
stringify
(
messages
)))
var
m
=
JSON
.
parse
(
JSON
.
parse
(
JSON
.
stringify
(
messages
)))
webview
.
postEvent
(
"messages"
,
[
m
,
id
]);
webview
.
postEvent
(
"messages"
,
id
,
m
);
}
function
onShhMessage
(
message
,
id
)
{
webview
.
postEvent
(
"shhChanged"
,
id
,
message
)
}
}
Item
{
Item
{
...
@@ -328,6 +331,33 @@ Rectangle {
...
@@ -328,6 +331,33 @@ Rectangle {
require
(
1
);
require
(
1
);
eth
.
uninstallFilter
(
data
.
args
[
0
])
eth
.
uninstallFilter
(
data
.
args
[
0
])
break
;
break
;
case
"shhNewFilter"
:
require
(
1
);
var
id
=
shh
.
watch
(
data
.
args
[
0
],
window
);
postData
(
data
.
_id
,
id
);
break
;
case
"newIdentity"
:
postData
(
data
.
_id
,
shh
.
newIdentity
())
break
case
"post"
:
require
(
1
);
var
params
=
data
.
args
[
0
];
var
fields
=
[
"payload"
,
"to"
,
"from"
];
for
(
var
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
params
[
fields
[
i
]]
=
params
[
fields
[
i
]]
||
""
;
}
if
(
typeof
params
.
payload
===
"object"
)
{
params
.
payload
=
params
.
payload
.
join
(
""
);
}
params
.
topics
=
params
.
topics
||
[];
params
.
priority
=
params
.
priority
||
1000
;
params
.
ttl
=
params
.
ttl
||
100
;
console
.
log
(
JSON
.
stringify
(
params
))
shh
.
post
(
params
.
payload
,
params
.
to
,
params
.
from
,
params
.
topics
,
params
.
priority
,
params
.
ttl
);
break
;
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
data
.
call
+
": "
+
e
)
console
.
log
(
data
.
call
+
": "
+
e
)
...
@@ -349,8 +379,8 @@ Rectangle {
...
@@ -349,8 +379,8 @@ Rectangle {
function
postData
(
seed
,
data
)
{
function
postData
(
seed
,
data
)
{
webview
.
experimental
.
postMessage
(
JSON
.
stringify
({
data
:
data
,
_id
:
seed
}))
webview
.
experimental
.
postMessage
(
JSON
.
stringify
({
data
:
data
,
_id
:
seed
}))
}
}
function
postEvent
(
event
,
data
)
{
function
postEvent
(
event
,
id
,
data
)
{
webview
.
experimental
.
postMessage
(
JSON
.
stringify
({
data
:
data
,
_event
:
event
}))
webview
.
experimental
.
postMessage
(
JSON
.
stringify
({
data
:
data
,
_
id
:
id
,
_
event
:
event
}))
}
}
function
onWatchedCb
(
data
,
id
)
{
function
onWatchedCb
(
data
,
id
)
{
...
...
cmd/mist/assets/qml/views/whisper.qml
View file @
4051c033
...
@@ -24,7 +24,7 @@ Rectangle {
...
@@ -24,7 +24,7 @@ Rectangle {
var
t
=
shh
.
watch
({},
root
)
var
t
=
shh
.
watch
({},
root
)
}
}
function
on
Message
(
message
)
{
function
on
ShhMessage
(
message
,
i
)
{
whisperModel
.
insert
(
0
,
{
from
:
message
.
from
,
payload
:
eth
.
toAscii
(
message
.
payload
)})
whisperModel
.
insert
(
0
,
{
from
:
message
.
from
,
payload
:
eth
.
toAscii
(
message
.
payload
)})
}
}
...
...
cmd/mist/gui.go
View file @
4051c033
...
@@ -43,38 +43,6 @@ import (
...
@@ -43,38 +43,6 @@ import (
"gopkg.in/qml.v1"
"gopkg.in/qml.v1"
)
)
/*
func LoadExtension(path string) (uintptr, error) {
lib, err := ffi.NewLibrary(path)
if err != nil {
return 0, err
}
so, err := lib.Fct("sharedObject", ffi.Pointer, nil)
if err != nil {
return 0, err
}
ptr := so()
err = lib.Close()
if err != nil {
return 0, err
}
return ptr.Interface().(uintptr), nil
}
*/
/*
vec, errr := LoadExtension("/Users/jeffrey/Desktop/build-libqmltest-Desktop_Qt_5_2_1_clang_64bit-Debug/liblibqmltest_debug.dylib")
fmt.Printf("Fetched vec with addr: %#x\n", vec)
if errr != nil {
fmt.Println(errr)
} else {
context.SetVar("vec", (unsafe.Pointer)(vec))
}
*/
var
guilogger
=
logger
.
NewLogger
(
"GUI"
)
var
guilogger
=
logger
.
NewLogger
(
"GUI"
)
type
Gui
struct
{
type
Gui
struct
{
...
@@ -535,3 +503,35 @@ func (gui *Gui) privateKey() string {
...
@@ -535,3 +503,35 @@ func (gui *Gui) privateKey() string {
func
(
gui
*
Gui
)
address
()
[]
byte
{
func
(
gui
*
Gui
)
address
()
[]
byte
{
return
gui
.
eth
.
KeyManager
()
.
Address
()
return
gui
.
eth
.
KeyManager
()
.
Address
()
}
}
/*
func LoadExtension(path string) (uintptr, error) {
lib, err := ffi.NewLibrary(path)
if err != nil {
return 0, err
}
so, err := lib.Fct("sharedObject", ffi.Pointer, nil)
if err != nil {
return 0, err
}
ptr := so()
err = lib.Close()
if err != nil {
return 0, err
}
return ptr.Interface().(uintptr), nil
}
*/
/*
vec, errr := LoadExtension("/Users/jeffrey/Desktop/build-libqmltest-Desktop_Qt_5_2_1_clang_64bit-Debug/liblibqmltest_debug.dylib")
fmt.Printf("Fetched vec with addr: %#x\n", vec)
if errr != nil {
fmt.Println(errr)
} else {
context.SetVar("vec", (unsafe.Pointer)(vec))
}
*/
cmd/mist/ui_lib.go
View file @
4051c033
...
@@ -225,6 +225,83 @@ func (self *UiLib) StartDebugger() {
...
@@ -225,6 +225,83 @@ func (self *UiLib) StartDebugger() {
dbWindow
.
Show
()
dbWindow
.
Show
()
}
}
func
(
self
*
UiLib
)
Transact
(
params
map
[
string
]
interface
{})
(
string
,
error
)
{
object
:=
mapToTxParams
(
params
)
return
self
.
JSXEth
.
Transact
(
object
[
"from"
],
object
[
"to"
],
object
[
"value"
],
object
[
"gas"
],
object
[
"gasPrice"
],
object
[
"data"
],
)
}
func
(
self
*
UiLib
)
Compile
(
code
string
)
(
string
,
error
)
{
bcode
,
err
:=
ethutil
.
Compile
(
code
,
false
)
if
err
!=
nil
{
return
err
.
Error
(),
err
}
return
ethutil
.
Bytes2Hex
(
bcode
),
err
}
func
(
self
*
UiLib
)
Call
(
params
map
[
string
]
interface
{})
(
string
,
error
)
{
object
:=
mapToTxParams
(
params
)
return
self
.
JSXEth
.
Execute
(
object
[
"to"
],
object
[
"value"
],
object
[
"gas"
],
object
[
"gasPrice"
],
object
[
"data"
],
)
}
func
(
self
*
UiLib
)
AddLocalTransaction
(
to
,
data
,
gas
,
gasPrice
,
value
string
)
int
{
return
self
.
miner
.
AddLocalTx
(
&
miner
.
LocalTx
{
To
:
ethutil
.
Hex2Bytes
(
to
),
Data
:
ethutil
.
Hex2Bytes
(
data
),
Gas
:
gas
,
GasPrice
:
gasPrice
,
Value
:
value
,
})
-
1
}
func
(
self
*
UiLib
)
RemoveLocalTransaction
(
id
int
)
{
self
.
miner
.
RemoveLocalTx
(
id
)
}
func
(
self
*
UiLib
)
SetGasPrice
(
price
string
)
{
self
.
miner
.
MinAcceptedGasPrice
=
ethutil
.
Big
(
price
)
}
func
(
self
*
UiLib
)
ToggleMining
()
bool
{
if
!
self
.
miner
.
Mining
()
{
self
.
miner
.
Start
()
return
true
}
else
{
self
.
miner
.
Stop
()
return
false
}
}
func
(
self
*
UiLib
)
ToHex
(
data
string
)
string
{
return
"0x"
+
ethutil
.
Bytes2Hex
([]
byte
(
data
))
}
func
(
self
*
UiLib
)
ToAscii
(
data
string
)
string
{
start
:=
0
if
len
(
data
)
>
1
&&
data
[
0
:
2
]
==
"0x"
{
start
=
2
}
return
string
(
ethutil
.
Hex2Bytes
(
data
[
start
:
]))
}
/// Ethereum filter methods
func
(
self
*
UiLib
)
NewFilter
(
object
map
[
string
]
interface
{})
(
id
int
)
{
func
(
self
*
UiLib
)
NewFilter
(
object
map
[
string
]
interface
{})
(
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
)
{
...
@@ -312,88 +389,3 @@ func mapToTxParams(object map[string]interface{}) map[string]string {
...
@@ -312,88 +389,3 @@ func mapToTxParams(object map[string]interface{}) map[string]string {
return
conv
return
conv
}
}
func
(
self
*
UiLib
)
Transact
(
params
map
[
string
]
interface
{})
(
string
,
error
)
{
object
:=
mapToTxParams
(
params
)
return
self
.
JSXEth
.
Transact
(
object
[
"from"
],
object
[
"to"
],
object
[
"value"
],
object
[
"gas"
],
object
[
"gasPrice"
],
object
[
"data"
],
)
}
func
(
self
*
UiLib
)
Compile
(
code
string
)
(
string
,
error
)
{
bcode
,
err
:=
ethutil
.
Compile
(
code
,
false
)
if
err
!=
nil
{
return
err
.
Error
(),
err
}
return
ethutil
.
Bytes2Hex
(
bcode
),
err
}
func
(
self
*
UiLib
)
Call
(
params
map
[
string
]
interface
{})
(
string
,
error
)
{
object
:=
mapToTxParams
(
params
)
return
self
.
JSXEth
.
Execute
(
object
[
"to"
],
object
[
"value"
],
object
[
"gas"
],
object
[
"gasPrice"
],
object
[
"data"
],
)
}
func
(
self
*
UiLib
)
AddLocalTransaction
(
to
,
data
,
gas
,
gasPrice
,
value
string
)
int
{
return
self
.
miner
.
AddLocalTx
(
&
miner
.
LocalTx
{
To
:
ethutil
.
Hex2Bytes
(
to
),
Data
:
ethutil
.
Hex2Bytes
(
data
),
Gas
:
gas
,
GasPrice
:
gasPrice
,
Value
:
value
,
})
-
1
}
func
(
self
*
UiLib
)
RemoveLocalTransaction
(
id
int
)
{
self
.
miner
.
RemoveLocalTx
(
id
)
}
func
(
self
*
UiLib
)
SetGasPrice
(
price
string
)
{
self
.
miner
.
MinAcceptedGasPrice
=
ethutil
.
Big
(
price
)
}
func
(
self
*
UiLib
)
ToggleMining
()
bool
{
if
!
self
.
miner
.
Mining
()
{
self
.
miner
.
Start
()
return
true
}
else
{
self
.
miner
.
Stop
()
return
false
}
}
func
(
self
*
UiLib
)
ToHex
(
data
string
)
string
{
return
"0x"
+
ethutil
.
Bytes2Hex
([]
byte
(
data
))
}
func
(
self
*
UiLib
)
ToAscii
(
data
string
)
string
{
start
:=
0
if
len
(
data
)
>
1
&&
data
[
0
:
2
]
==
"0x"
{
start
=
2
}
return
string
(
ethutil
.
Hex2Bytes
(
data
[
start
:
]))
}
/*
// XXX Refactor me & MOVE
func (self *Ethereum) InstallFilter(filter *core.Filter) (id int) {
return self.filterManager.InstallFilter(filter)
}
func (self *Ethereum) UninstallFilter(id int) { self.filterManager.UninstallFilter(id) }
func (self *Ethereum) GetFilter(id int) *core.Filter { return self.filterManager.GetFilter(id) }
*/
ui/qt/qwhisper/message.go
View file @
4051c033
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
type
Message
struct
{
type
Message
struct
{
ref
*
whisper
.
Message
ref
*
whisper
.
Message
Flags
byte
Flags
int32
Payload
string
Payload
string
From
string
From
string
}
}
...
@@ -16,7 +16,7 @@ type Message struct {
...
@@ -16,7 +16,7 @@ type Message struct {
func
ToQMessage
(
msg
*
whisper
.
Message
)
*
Message
{
func
ToQMessage
(
msg
*
whisper
.
Message
)
*
Message
{
return
&
Message
{
return
&
Message
{
ref
:
msg
,
ref
:
msg
,
Flags
:
msg
.
Flags
,
Flags
:
int32
(
msg
.
Flags
)
,
Payload
:
ethutil
.
Bytes2Hex
(
msg
.
Payload
),
Payload
:
ethutil
.
Bytes2Hex
(
msg
.
Payload
),
From
:
ethutil
.
Bytes2Hex
(
crypto
.
FromECDSAPub
(
msg
.
Recover
())),
From
:
ethutil
.
Bytes2Hex
(
crypto
.
FromECDSAPub
(
msg
.
Recover
())),
}
}
...
...
ui/qt/qwhisper/whisper.go
View file @
4051c033
...
@@ -33,9 +33,9 @@ func (self *Whisper) SetView(view qml.Object) {
...
@@ -33,9 +33,9 @@ func (self *Whisper) SetView(view qml.Object) {
self
.
view
=
view
self
.
view
=
view
}
}
func
(
self
*
Whisper
)
Post
(
data
string
,
to
,
from
string
,
topics
[]
string
,
pow
,
ttl
uint32
)
{
func
(
self
*
Whisper
)
Post
(
data
,
to
,
from
string
,
topics
[]
string
,
priority
,
ttl
uint32
)
{
msg
:=
whisper
.
NewMessage
(
fromHex
(
data
))
msg
:=
whisper
.
NewMessage
(
fromHex
(
data
))
envelope
,
err
:=
msg
.
Seal
(
time
.
Duration
(
p
ow
),
whisper
.
Opts
{
envelope
,
err
:=
msg
.
Seal
(
time
.
Duration
(
p
riority
*
100000
),
whisper
.
Opts
{
Ttl
:
time
.
Duration
(
ttl
),
Ttl
:
time
.
Duration
(
ttl
),
To
:
crypto
.
ToECDSAPub
(
fromHex
(
to
)),
To
:
crypto
.
ToECDSAPub
(
fromHex
(
to
)),
From
:
crypto
.
ToECDSA
(
fromHex
(
from
)),
From
:
crypto
.
ToECDSA
(
fromHex
(
from
)),
...
@@ -64,13 +64,14 @@ func (self *Whisper) HasIdentity(key string) bool {
...
@@ -64,13 +64,14 @@ func (self *Whisper) HasIdentity(key string) bool {
func
(
self
*
Whisper
)
Watch
(
opts
map
[
string
]
interface
{},
view
*
qml
.
Common
)
int
{
func
(
self
*
Whisper
)
Watch
(
opts
map
[
string
]
interface
{},
view
*
qml
.
Common
)
int
{
filter
:=
filterFromMap
(
opts
)
filter
:=
filterFromMap
(
opts
)
var
i
int
filter
.
Fn
=
func
(
msg
*
whisper
.
Message
)
{
filter
.
Fn
=
func
(
msg
*
whisper
.
Message
)
{
if
view
!=
nil
{
if
view
!=
nil
{
view
.
Call
(
"on
Message"
,
ToQMessage
(
msg
)
)
view
.
Call
(
"on
ShhMessage"
,
ToQMessage
(
msg
),
i
)
}
}
}
}
i
:
=
self
.
Whisper
.
Watch
(
filter
)
i
=
self
.
Whisper
.
Watch
(
filter
)
self
.
watches
[
i
]
=
&
Watch
{}
self
.
watches
[
i
]
=
&
Watch
{}
return
i
return
i
...
...
whisper/whisper.go
View file @
4051c033
...
@@ -175,7 +175,7 @@ func (self *Whisper) add(envelope *Envelope) error {
...
@@ -175,7 +175,7 @@ func (self *Whisper) add(envelope *Envelope) error {
if
!
self
.
expiry
[
envelope
.
Expiry
]
.
Has
(
hash
)
{
if
!
self
.
expiry
[
envelope
.
Expiry
]
.
Has
(
hash
)
{
self
.
expiry
[
envelope
.
Expiry
]
.
Add
(
hash
)
self
.
expiry
[
envelope
.
Expiry
]
.
Add
(
hash
)
self
.
postEvent
(
envelope
)
go
self
.
postEvent
(
envelope
)
}
}
return
nil
return
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