diff options
author | obscuren <geffobscura@gmail.com> | 2015-02-21 01:13:46 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-02-21 01:13:46 +0800 |
commit | bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca (patch) | |
tree | 46ab5943fd5e26198067aeec4a44287452eb2a32 /ui | |
parent | 771bfe9e78f9952002a71cccc8d41c8c544fdfcb (diff) | |
parent | d586a633ff005ac01c9f1eb33552d147cf6c883e (diff) | |
download | dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.gz dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.bz2 dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.lz dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.xz dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.zst dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.zip |
Merge branch 'release/0.9.0'
Diffstat (limited to 'ui')
-rw-r--r-- | ui/filter.go | 42 | ||||
-rw-r--r-- | ui/qt/filter.go | 26 | ||||
-rw-r--r-- | ui/qt/qwhisper/message.go | 23 | ||||
-rw-r--r-- | ui/qt/qwhisper/watch.go | 13 | ||||
-rw-r--r-- | ui/qt/qwhisper/whisper.go | 93 | ||||
-rw-r--r-- | ui/qt/qwhisper/whisper_test.go | 15 | ||||
-rw-r--r-- | ui/qt/webengine/all.cpp | 1 | ||||
-rw-r--r-- | ui/qt/webengine/cpp/webengine.cpp | 6 | ||||
-rw-r--r-- | ui/qt/webengine/cpp/webengine.h | 14 | ||||
-rw-r--r-- | ui/qt/webengine/webengine.go | 18 |
10 files changed, 193 insertions, 58 deletions
diff --git a/ui/filter.go b/ui/filter.go index 88faad5ca..0d1746915 100644 --- a/ui/filter.go +++ b/ui/filter.go @@ -5,7 +5,17 @@ import ( "github.com/ethereum/go-ethereum/ethutil" ) -func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter { +func fromHex(s string) []byte { + if len(s) > 1 { + if s[0:2] == "0x" { + s = s[2:] + } + return ethutil.Hex2Bytes(s) + } + return nil +} + +func NewFilterFromMap(object map[string]interface{}, eth core.Backend) *core.Filter { filter := core.NewFilter(eth) if object["earliest"] != nil { @@ -18,14 +28,9 @@ func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core. filter.SetLatestBlock(val.Int()) } - if object["to"] != nil { - val := ethutil.NewValue(object["to"]) - filter.AddTo(ethutil.Hex2Bytes(val.Str())) - } - - if object["from"] != nil { - val := ethutil.NewValue(object["from"]) - filter.AddFrom(ethutil.Hex2Bytes(val.Str())) + if object["address"] != nil { + //val := ethutil.NewValue(object["address"]) + //filter.SetAddress(fromHex(val.Str())) } if object["max"] != nil { @@ -38,8 +43,8 @@ func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core. filter.SetSkip(int(val.Uint())) } - if object["altered"] != nil { - filter.Altered = makeAltered(object["altered"]) + if object["topics"] != nil { + filter.SetTopics(MakeTopics(object["topics"])) } return filter @@ -48,11 +53,11 @@ func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core. // Conversion methodn func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) { if str, ok := m["id"].(string); ok { - d.Address = ethutil.Hex2Bytes(str) + d.Address = fromHex(str) } if str, ok := m["at"].(string); ok { - d.StateAddress = ethutil.Hex2Bytes(str) + d.StateAddress = fromHex(str) } return @@ -60,16 +65,13 @@ func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) { // data can come in in the following formats: // ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"} -func makeAltered(v interface{}) (d []core.AccountChange) { +func MakeTopics(v interface{}) (d [][]byte) { if str, ok := v.(string); ok { - d = append(d, core.AccountChange{ethutil.Hex2Bytes(str), nil}) - } else if obj, ok := v.(map[string]interface{}); ok { - d = append(d, mapToAccountChange(obj)) - } else if slice, ok := v.([]interface{}); ok { + d = append(d, fromHex(str)) + } else if slice, ok := v.([]string); ok { for _, item := range slice { - d = append(d, makeAltered(item)...) + d = append(d, fromHex(item)) } } - return } diff --git a/ui/qt/filter.go b/ui/qt/filter.go index c68936401..48e8a7fae 100644 --- a/ui/qt/filter.go +++ b/ui/qt/filter.go @@ -1,37 +1,29 @@ package qt import ( - "fmt" - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/ui" - "gopkg.in/qml.v1" + "github.com/obscuren/qml" ) -func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter { +func NewFilterFromMap(object map[string]interface{}, eth core.Backend) *core.Filter { filter := ui.NewFilterFromMap(object, eth) - if object["altered"] != nil { - filter.Altered = makeAltered(object["altered"]) + if object["topics"] != nil { + filter.SetTopics(makeTopics(object["topics"])) } return filter } -func makeAltered(v interface{}) (d []core.AccountChange) { +func makeTopics(v interface{}) (d [][]byte) { if qList, ok := v.(*qml.List); ok { - var s []interface{} + var s []string qList.Convert(&s) - fmt.Println(s) - - d = makeAltered(s) - } else if qMap, ok := v.(*qml.Map); ok { - var m map[string]interface{} - qMap.Convert(&m) - fmt.Println(m) - - d = makeAltered(m) + d = ui.MakeTopics(s) + } else if str, ok := v.(string); ok { + d = ui.MakeTopics(str) } return diff --git a/ui/qt/qwhisper/message.go b/ui/qt/qwhisper/message.go new file mode 100644 index 000000000..26e72ac93 --- /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 `json:"flags"` + Payload string `json:"payload"` + From string `json:"from"` +} + +func ToQMessage(msg *whisper.Message) *Message { + return &Message{ + ref: msg, + Flags: int32(msg.Flags), + Payload: "0x" + ethutil.Bytes2Hex(msg.Payload), + From: "0x" + 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..2bc455b0b 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -1,3 +1,4 @@ +// QWhisper package. This package is temporarily on hold until QML DApp dev will reemerge. package qwhisper import ( @@ -5,9 +6,13 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/whisper" + "github.com/obscuren/qml" ) +var qlogger = logger.NewLogger("QSHH") + func fromHex(s string) []byte { if len(s) > 1 { return ethutil.Hex2Bytes(s[2:]) @@ -18,53 +23,99 @@ 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) { - 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)), - }) - if err != nil { - // handle error - return +func (self *Whisper) Post(payload []string, to, from string, topics []string, priority, ttl uint32) { + var data []byte + for _, d := range payload { + data = append(data, fromHex(d)...) } - if err := self.Whisper.Send(envelope); err != nil { - // handle error - return + pk := crypto.ToECDSAPub(fromHex(from)) + if key := self.Whisper.GetIdentity(pk); key != nil { + msg := whisper.NewMessage(data) + envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ + Ttl: time.Duration(ttl) * time.Second, + To: crypto.ToECDSAPub(fromHex(to)), + From: key, + Topics: whisper.TopicsFromString(topics...), + }) + + if err != nil { + qlogger.Infoln(err) + // handle error + return + } + + if err := self.Whisper.Send(envelope); err != nil { + qlogger.Infoln(err) + // handle error + return + } + } else { + qlogger.Infoln("unmatched pub / priv for seal") } + } func (self *Whisper) NewIdentity() string { - return toHex(self.Whisper.NewIdentity().D.Bytes()) + key := self.Whisper.NewIdentity() + + return toHex(crypto.FromECDSAPub(&key.PublicKey)) } -func (self *Whisper) HasIdentify(key string) bool { - return self.Whisper.HasIdentity(crypto.ToECDSA(fromHex(key))) +func (self *Whisper) HasIdentity(key string) bool { + return self.Whisper.HasIdentity(crypto.ToECDSAPub(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 (self *Whisper) Messages(id int) (messages *ethutil.List) { + msgs := self.Whisper.Messages(id) + messages = ethutil.EmptyList() + for _, message := range msgs { + messages.Append(ToQMessage(message)) + } + + return } func filterFromMap(opts map[string]interface{}) (f whisper.Filter) { if to, ok := opts["to"].(string); ok { - f.To = crypto.ToECDSA(fromHex(to)) + f.To = crypto.ToECDSAPub(fromHex(to)) } 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") + } +} diff --git a/ui/qt/webengine/all.cpp b/ui/qt/webengine/all.cpp new file mode 100644 index 000000000..3b7c2f7b8 --- /dev/null +++ b/ui/qt/webengine/all.cpp @@ -0,0 +1 @@ +#include "cpp/webengine.cpp" diff --git a/ui/qt/webengine/cpp/webengine.cpp b/ui/qt/webengine/cpp/webengine.cpp new file mode 100644 index 000000000..118b451ef --- /dev/null +++ b/ui/qt/webengine/cpp/webengine.cpp @@ -0,0 +1,6 @@ +#include <QtWebEngine> +#include "webengine.h" + +void webengineInitialize() { + QtWebEngine::initialize(); +} diff --git a/ui/qt/webengine/cpp/webengine.h b/ui/qt/webengine/cpp/webengine.h new file mode 100644 index 000000000..9c3b13bfa --- /dev/null +++ b/ui/qt/webengine/cpp/webengine.h @@ -0,0 +1,14 @@ +#ifndef WEBENGINE_H +#define WEBENGINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +void webengineInitialize(); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // WEBENGINE_H diff --git a/ui/qt/webengine/webengine.go b/ui/qt/webengine/webengine.go new file mode 100644 index 000000000..600dbb6cb --- /dev/null +++ b/ui/qt/webengine/webengine.go @@ -0,0 +1,18 @@ +package webengine + +// #cgo CPPFLAGS: -I./ +// #cgo CXXFLAGS: -std=c++0x -pedantic-errors -Wall -fno-strict-aliasing +// #cgo LDFLAGS: -lstdc++ +// #cgo pkg-config: Qt5WebEngine +// +// #include "cpp/webengine.h" +import "C" + +import "github.com/obscuren/qml" + +// Initializes the WebEngine extension. +func Initialize() { + qml.RunMain(func() { + C.webengineInitialize() + }) +} |