aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/qwhisper/message.go23
-rw-r--r--ui/qt/qwhisper/watch.go13
-rw-r--r--ui/qt/qwhisper/whisper.go44
-rw-r--r--ui/qt/qwhisper/whisper_test.go15
4 files changed, 85 insertions, 10 deletions
diff --git a/ui/qt/qwhisper/message.go b/ui/qt/qwhisper/message.go
new file mode 100644
index 000000000..c87647399
--- /dev/null
+++ b/ui/qt/qwhisper/message.go
@@ -0,0 +1,23 @@
+package qwhisper
+
+import (
+ "github.com/ethereum/go-ethereum/crypto"
+ "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/whisper"
+)
+
+type Message struct {
+ ref *whisper.Message
+ Flags int32
+ Payload string
+ From string
+}
+
+func ToQMessage(msg *whisper.Message) *Message {
+ return &Message{
+ ref: msg,
+ Flags: int32(msg.Flags),
+ Payload: ethutil.Bytes2Hex(msg.Payload),
+ From: ethutil.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())),
+ }
+}
diff --git a/ui/qt/qwhisper/watch.go b/ui/qt/qwhisper/watch.go
new file mode 100644
index 000000000..0ccedc719
--- /dev/null
+++ b/ui/qt/qwhisper/watch.go
@@ -0,0 +1,13 @@
+package qwhisper
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+type Watch struct {
+}
+
+func (self *Watch) Arrived(v unsafe.Pointer) {
+ fmt.Println(v)
+}
diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go
index bed23c8a7..62676daf5 100644
--- a/ui/qt/qwhisper/whisper.go
+++ b/ui/qt/qwhisper/whisper.go
@@ -1,11 +1,13 @@
package qwhisper
import (
+ "fmt"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/whisper"
+ "gopkg.in/qml.v1"
)
func fromHex(s string) []byte {
@@ -18,25 +20,35 @@ func toHex(b []byte) string { return "0x" + ethutil.Bytes2Hex(b) }
type Whisper struct {
*whisper.Whisper
+ view qml.Object
+
+ watches map[int]*Watch
}
func New(w *whisper.Whisper) *Whisper {
- return &Whisper{w}
+ return &Whisper{w, nil, make(map[int]*Watch)}
+}
+
+func (self *Whisper) SetView(view qml.Object) {
+ self.view = view
}
-func (self *Whisper) Post(data string, pow, ttl uint32, to, from string) {
+func (self *Whisper) Post(data, to, from string, topics []string, priority, ttl uint32) {
msg := whisper.NewMessage(fromHex(data))
- envelope, err := msg.Seal(time.Duration(pow), whisper.Opts{
- Ttl: time.Duration(ttl),
- To: crypto.ToECDSAPub(fromHex(to)),
- From: crypto.ToECDSA(fromHex(from)),
+ envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{
+ Ttl: time.Duration(ttl),
+ To: crypto.ToECDSAPub(fromHex(to)),
+ From: crypto.ToECDSA(fromHex(from)),
+ Topics: whisper.TopicsFromString(topics...),
})
if err != nil {
+ fmt.Println(err)
// handle error
return
}
if err := self.Whisper.Send(envelope); err != nil {
+ fmt.Println(err)
// handle error
return
}
@@ -46,16 +58,23 @@ func (self *Whisper) NewIdentity() string {
return toHex(self.Whisper.NewIdentity().D.Bytes())
}
-func (self *Whisper) HasIdentify(key string) bool {
+func (self *Whisper) HasIdentity(key string) bool {
return self.Whisper.HasIdentity(crypto.ToECDSA(fromHex(key)))
}
-func (self *Whisper) Watch(opts map[string]interface{}) {
+func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int {
filter := filterFromMap(opts)
+ var i int
filter.Fn = func(msg *whisper.Message) {
- // TODO POST TO QT WINDOW
+ if view != nil {
+ view.Call("onShhMessage", ToQMessage(msg), i)
+ }
}
- self.Whisper.Watch(filter)
+
+ i = self.Whisper.Watch(filter)
+ self.watches[i] = &Watch{}
+
+ return i
}
func filterFromMap(opts map[string]interface{}) (f whisper.Filter) {
@@ -65,6 +84,11 @@ func filterFromMap(opts map[string]interface{}) (f whisper.Filter) {
if from, ok := opts["from"].(string); ok {
f.From = crypto.ToECDSAPub(fromHex(from))
}
+ if topicList, ok := opts["topics"].(*qml.List); ok {
+ var topics []string
+ topicList.Convert(&topics)
+ f.Topics = whisper.TopicsFromString(topics...)
+ }
return
}
diff --git a/ui/qt/qwhisper/whisper_test.go b/ui/qt/qwhisper/whisper_test.go
new file mode 100644
index 000000000..efa4e6238
--- /dev/null
+++ b/ui/qt/qwhisper/whisper_test.go
@@ -0,0 +1,15 @@
+package qwhisper
+
+import (
+ "testing"
+
+ "github.com/ethereum/go-ethereum/whisper"
+)
+
+func TestHasIdentity(t *testing.T) {
+ qw := New(whisper.New())
+ id := qw.NewIdentity()
+ if !qw.HasIdentity(id) {
+ t.Error("expected to have identity")
+ }
+}