From 9008b155d3c8d2a32c4c8945f1174243d48d4e90 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 10:28:02 +0100 Subject: Renamed `chain` => `core` --- ui/filter.go | 12 ++++++------ ui/qt/filter.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'ui') diff --git a/ui/filter.go b/ui/filter.go index 84209861e..88faad5ca 100644 --- a/ui/filter.go +++ b/ui/filter.go @@ -1,12 +1,12 @@ package ui import ( - "github.com/ethereum/go-ethereum/chain" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/ethutil" ) -func NewFilterFromMap(object map[string]interface{}, eth chain.EthManager) *chain.Filter { - filter := chain.NewFilter(eth) +func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter { + filter := core.NewFilter(eth) if object["earliest"] != nil { val := ethutil.NewValue(object["earliest"]) @@ -46,7 +46,7 @@ func NewFilterFromMap(object map[string]interface{}, eth chain.EthManager) *chai } // Conversion methodn -func mapToAccountChange(m map[string]interface{}) (d chain.AccountChange) { +func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) { if str, ok := m["id"].(string); ok { d.Address = ethutil.Hex2Bytes(str) } @@ -60,9 +60,9 @@ func mapToAccountChange(m map[string]interface{}) (d chain.AccountChange) { // data can come in in the following formats: // ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"} -func makeAltered(v interface{}) (d []chain.AccountChange) { +func makeAltered(v interface{}) (d []core.AccountChange) { if str, ok := v.(string); ok { - d = append(d, chain.AccountChange{ethutil.Hex2Bytes(str), nil}) + 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 { diff --git a/ui/qt/filter.go b/ui/qt/filter.go index 96c3ab3a3..c68936401 100644 --- a/ui/qt/filter.go +++ b/ui/qt/filter.go @@ -3,12 +3,12 @@ package qt import ( "fmt" - "github.com/ethereum/go-ethereum/chain" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/ui" "gopkg.in/qml.v1" ) -func NewFilterFromMap(object map[string]interface{}, eth chain.EthManager) *chain.Filter { +func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter { filter := ui.NewFilterFromMap(object, eth) if object["altered"] != nil { @@ -18,7 +18,7 @@ func NewFilterFromMap(object map[string]interface{}, eth chain.EthManager) *chai return filter } -func makeAltered(v interface{}) (d []chain.AccountChange) { +func makeAltered(v interface{}) (d []core.AccountChange) { if qList, ok := v.(*qml.List); ok { var s []interface{} qList.Convert(&s) -- cgit v1.2.3 From bf566a657c2de2ab7818ec14003a33d84302aef3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 12 Dec 2014 22:24:41 +0100 Subject: Implemented Qt whisper interface --- ui/qt/qwhisper/whisper.go | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ui/qt/qwhisper/whisper.go (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go new file mode 100644 index 000000000..fd2b62ac2 --- /dev/null +++ b/ui/qt/qwhisper/whisper.go @@ -0,0 +1,70 @@ +package qwhisper + +import ( + "time" + + "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/whisper" +) + +func fromHex(s string) []byte { + if len(s) > 1 { + return ethutil.Hex2Bytes(s[2:]) + } + return nil +} +func toHex(b []byte) string { return "0x" + ethutil.Bytes2Hex(b) } + +type Whisper struct { + *whisper.Whisper +} + +func New(w *whisper.Whisper) *Whisper { + return &Whisper{w} +} + +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.PubTECDSA(fromHex(to)), + From: crypto.ToECDSA(fromHex(from)), + }) + if err != nil { + // handle error + return + } + + if err := self.Whisper.Send(envolpe); err != nil { + // handle error + return + } +} + +func (self *Whisper) NewIdentity() string { + return toHex(self.Whisper.NewIdentity().D.Bytes()) +} + +func (self *Whisper) HasIdentify(key string) bool { + return self.Whisper.HasIdentity(crypto.ToECDSA(fromHex(key))) +} + +func (self *Whisper) Watch(opts map[string]interface{}) { + filter := filterFromMap(opts) + filter.Fn = func(msg *Message) { + // TODO POST TO QT WINDOW + } + self.Watch(filter) +} + +func filterFromMap(opts map[string]interface{}) whisper.Filter { + var f Filter + if to, ok := opts["to"].(string); ok { + f.To = ToECDSA(fromHex(to)) + } + if from, ok := opts["from"].(string); ok { + f.From = ToECDSAPub(fromHex(from)) + } + + return f +} -- cgit v1.2.3 From 4c84db85c52b586d8c30f270b03671f77c9c2534 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 12 Dec 2014 22:29:29 +0100 Subject: eth-go packages ended up in whisper --- ui/qt/qwhisper/whisper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index fd2b62ac2..d307366c8 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -3,7 +3,7 @@ package qwhisper import ( "time" - "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/whisper" ) -- cgit v1.2.3 From f8061fcba8648593e03ce3d847613d8c8e0f4797 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 12 Dec 2014 22:38:54 +0100 Subject: fixed tests --- ui/qt/qwhisper/whisper.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index d307366c8..bed23c8a7 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -3,6 +3,7 @@ package qwhisper import ( "time" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/whisper" ) @@ -27,7 +28,7 @@ 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.PubTECDSA(fromHex(to)), + To: crypto.ToECDSAPub(fromHex(to)), From: crypto.ToECDSA(fromHex(from)), }) if err != nil { @@ -35,7 +36,7 @@ func (self *Whisper) Post(data string, pow, ttl uint32, to, from string) { return } - if err := self.Whisper.Send(envolpe); err != nil { + if err := self.Whisper.Send(envelope); err != nil { // handle error return } @@ -51,20 +52,19 @@ func (self *Whisper) HasIdentify(key string) bool { func (self *Whisper) Watch(opts map[string]interface{}) { filter := filterFromMap(opts) - filter.Fn = func(msg *Message) { + filter.Fn = func(msg *whisper.Message) { // TODO POST TO QT WINDOW } - self.Watch(filter) + self.Whisper.Watch(filter) } -func filterFromMap(opts map[string]interface{}) whisper.Filter { - var f Filter +func filterFromMap(opts map[string]interface{}) (f whisper.Filter) { if to, ok := opts["to"].(string); ok { - f.To = ToECDSA(fromHex(to)) + f.To = crypto.ToECDSA(fromHex(to)) } if from, ok := opts["from"].(string); ok { - f.From = ToECDSAPub(fromHex(from)) + f.From = crypto.ToECDSAPub(fromHex(from)) } - return f + return } -- cgit v1.2.3 From 01a6db93241a01e98a0467b628423c9b5b1361cb Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Dec 2014 17:14:02 +0100 Subject: Added whisper debug interface + whisper fixes --- ui/qt/qwhisper/whisper.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index bed23c8a7..3e1ca7ab9 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,33 @@ func toHex(b []byte) string { return "0x" + ethutil.Bytes2Hex(b) } type Whisper struct { *whisper.Whisper + view qml.Object } func New(w *whisper.Whisper) *Whisper { - return &Whisper{w} + return &Whisper{w, nil} } -func (self *Whisper) Post(data string, pow, ttl uint32, to, from string) { +func (self *Whisper) SetView(view qml.Object) { + self.view = view +} + +func (self *Whisper) Post(data string, to, from string, topics []string, pow, 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)), + 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 } -- cgit v1.2.3 From c96e504adb4a547b5e293d6930626cf2f9401ac2 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Dec 2014 17:28:51 +0100 Subject: Typo --- ui/qt/qwhisper/whisper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 3e1ca7ab9..62c4c743b 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -56,7 +56,7 @@ 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))) } -- cgit v1.2.3 From 0291eff99a79fa1c844a4214c326c4f2b5f913ff Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Dec 2014 21:52:50 +0100 Subject: Identity test --- ui/qt/qwhisper/whisper_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ui/qt/qwhisper/whisper_test.go (limited to 'ui') 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") + } +} -- cgit v1.2.3 From 52b54631a47dfa46742635be178f2f8d33dd9f41 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 16 Dec 2014 19:55:57 +0100 Subject: Whisper watches fixes --- ui/qt/qwhisper/whisper.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 62c4c743b..8f05c0695 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -3,6 +3,7 @@ package qwhisper import ( "fmt" "time" + "unsafe" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" @@ -18,13 +19,22 @@ func fromHex(s string) []byte { } func toHex(b []byte) string { return "0x" + ethutil.Bytes2Hex(b) } +type Watch struct { +} + +func (self *Watch) Arrived(v unsafe.Pointer) { + fmt.Println(v) +} + type Whisper struct { *whisper.Whisper view qml.Object + + watches map[int]*Watch } func New(w *whisper.Whisper) *Whisper { - return &Whisper{w, nil} + return &Whisper{w, nil, make(map[int]*Watch)} } func (self *Whisper) SetView(view qml.Object) { @@ -37,7 +47,7 @@ func (self *Whisper) Post(data string, to, from string, topics []string, pow, tt Ttl: time.Duration(ttl), To: crypto.ToECDSAPub(fromHex(to)), From: crypto.ToECDSA(fromHex(from)), - Topics: whisper.TopicsFromString(topics), + Topics: whisper.TopicsFromString(topics...), }) if err != nil { fmt.Println(err) @@ -60,12 +70,15 @@ 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{}) *Watch { filter := filterFromMap(opts) filter.Fn = func(msg *whisper.Message) { - // TODO POST TO QT WINDOW + fmt.Println(msg) } - self.Whisper.Watch(filter) + i := self.Whisper.Watch(filter) + self.watches[i] = &Watch{} + + return self.watches[i] } func filterFromMap(opts map[string]interface{}) (f whisper.Filter) { @@ -75,6 +88,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 } -- cgit v1.2.3 From 0e5aed63ddbda716ba7373bed7cfc083ec35ced1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 21 Dec 2014 15:06:35 +0100 Subject: Updated QWhisper * changed api * general whisper debug interface --- ui/qt/qwhisper/message.go | 23 +++++++++++++++++++++++ ui/qt/qwhisper/watch.go | 13 +++++++++++++ ui/qt/qwhisper/whisper.go | 17 ++++++----------- 3 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 ui/qt/qwhisper/message.go create mode 100644 ui/qt/qwhisper/watch.go (limited to 'ui') diff --git a/ui/qt/qwhisper/message.go b/ui/qt/qwhisper/message.go new file mode 100644 index 000000000..07505ba09 --- /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 byte + Payload string + From string +} + +func ToQMessage(msg *whisper.Message) *Message { + return &Message{ + ref: msg, + Flags: 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 8f05c0695..6fb00cdac 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -3,7 +3,6 @@ package qwhisper import ( "fmt" "time" - "unsafe" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" @@ -19,13 +18,6 @@ func fromHex(s string) []byte { } func toHex(b []byte) string { return "0x" + ethutil.Bytes2Hex(b) } -type Watch struct { -} - -func (self *Watch) Arrived(v unsafe.Pointer) { - fmt.Println(v) -} - type Whisper struct { *whisper.Whisper view qml.Object @@ -70,15 +62,18 @@ func (self *Whisper) HasIdentity(key string) bool { return self.Whisper.HasIdentity(crypto.ToECDSA(fromHex(key))) } -func (self *Whisper) Watch(opts map[string]interface{}) *Watch { +func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int { filter := filterFromMap(opts) filter.Fn = func(msg *whisper.Message) { - fmt.Println(msg) + if view != nil { + view.Call("onMessage", ToQMessage(msg)) + } } + i := self.Whisper.Watch(filter) self.watches[i] = &Watch{} - return self.watches[i] + return i } func filterFromMap(opts map[string]interface{}) (f whisper.Filter) { -- cgit v1.2.3 From 4051c0333f43765a7414a4e0e8ac51e7148b0646 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 22 Dec 2014 13:23:11 +0100 Subject: Added whisper js api --- ui/qt/qwhisper/message.go | 4 ++-- ui/qt/qwhisper/whisper.go | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/message.go b/ui/qt/qwhisper/message.go index 07505ba09..c87647399 100644 --- a/ui/qt/qwhisper/message.go +++ b/ui/qt/qwhisper/message.go @@ -8,7 +8,7 @@ import ( type Message struct { ref *whisper.Message - Flags byte + Flags int32 Payload string From string } @@ -16,7 +16,7 @@ type Message struct { func ToQMessage(msg *whisper.Message) *Message { return &Message{ ref: msg, - Flags: msg.Flags, + Flags: int32(msg.Flags), Payload: ethutil.Bytes2Hex(msg.Payload), From: ethutil.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())), } diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 6fb00cdac..62676daf5 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -33,9 +33,9 @@ func (self *Whisper) SetView(view qml.Object) { 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)) - envelope, err := msg.Seal(time.Duration(pow), whisper.Opts{ + envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ Ttl: time.Duration(ttl), To: crypto.ToECDSAPub(fromHex(to)), From: crypto.ToECDSA(fromHex(from)), @@ -64,13 +64,14 @@ func (self *Whisper) HasIdentity(key string) bool { func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int { filter := filterFromMap(opts) + var i int filter.Fn = func(msg *whisper.Message) { if view != nil { - view.Call("onMessage", ToQMessage(msg)) + view.Call("onShhMessage", ToQMessage(msg), i) } } - i := self.Whisper.Watch(filter) + i = self.Whisper.Watch(filter) self.watches[i] = &Watch{} return i -- cgit v1.2.3 From e32f7baa0d5d949a84a3b29c57220f837eae356a Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 22 Dec 2014 14:59:52 +0100 Subject: Concat and pad data --- ui/qt/qwhisper/whisper.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 62676daf5..0627acd29 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -33,8 +33,13 @@ func (self *Whisper) SetView(view qml.Object) { self.view = view } -func (self *Whisper) Post(data, to, from string, topics []string, priority, ttl uint32) { - msg := whisper.NewMessage(fromHex(data)) +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)...) + } + + msg := whisper.NewMessage(data) envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ Ttl: time.Duration(ttl), To: crypto.ToECDSAPub(fromHex(to)), -- cgit v1.2.3 From 4a0ade4788b0e8d53c6b0eabaf9652643b6a073a Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 8 Jan 2015 21:41:32 +0100 Subject: Fixed some whisper issues --- ui/qt/qwhisper/whisper.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 0627acd29..8a064c81c 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -6,10 +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" "gopkg.in/qml.v1" ) +var qlogger = logger.NewLogger("QSHH") + func fromHex(s string) []byte { if len(s) > 1 { return ethutil.Hex2Bytes(s[2:]) @@ -36,9 +39,10 @@ func (self *Whisper) SetView(view qml.Object) { 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)...) + data = append(data, ethutil.Hex2Bytes(d)...) } + fmt.Println(payload, data, "from", from, fromHex(from), crypto.ToECDSA(fromHex(from))) msg := whisper.NewMessage(data) envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ Ttl: time.Duration(ttl), @@ -47,13 +51,13 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr Topics: whisper.TopicsFromString(topics...), }) if err != nil { - fmt.Println(err) + qlogger.Infoln(err) // handle error return } if err := self.Whisper.Send(envelope); err != nil { - fmt.Println(err) + qlogger.Infoln(err) // handle error return } -- cgit v1.2.3 From c9f566269b39780accfb7632b94dd7635be2022b Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 9 Jan 2015 13:28:48 +0100 Subject: merged --- ui/qt/qwhisper/whisper.go | 2 -- 1 file changed, 2 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 8a064c81c..62b68efaf 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -1,7 +1,6 @@ package qwhisper import ( - "fmt" "time" "github.com/ethereum/go-ethereum/crypto" @@ -42,7 +41,6 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr data = append(data, ethutil.Hex2Bytes(d)...) } - fmt.Println(payload, data, "from", from, fromHex(from), crypto.ToECDSA(fromHex(from))) msg := whisper.NewMessage(data) envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ Ttl: time.Duration(ttl), -- cgit v1.2.3 From f9b0d1a8e738a207e6101b27b667ea390def9f69 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 9 Jan 2015 13:36:47 +0100 Subject: Updated to new ethereum.js api --- ui/qt/qwhisper/whisper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 62b68efaf..8b4628a1b 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -38,7 +38,7 @@ func (self *Whisper) SetView(view qml.Object) { func (self *Whisper) Post(payload []string, to, from string, topics []string, priority, ttl uint32) { var data []byte for _, d := range payload { - data = append(data, ethutil.Hex2Bytes(d)...) + data = append(data, fromHex(d)...) } msg := whisper.NewMessage(data) -- cgit v1.2.3 From e3da85faedf21a3ddb73a0fa29decf65364e6c39 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 Jan 2015 00:51:56 +0100 Subject: Implemented filter for ws + fixes * proper 0xhex * filters fixed * start of filter manager * accounts for ws. Closes #246 --- ui/filter.go | 20 +++++++++++++++----- ui/qt/filter.go | 5 ----- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'ui') diff --git a/ui/filter.go b/ui/filter.go index 88faad5ca..e0797dad2 100644 --- a/ui/filter.go +++ b/ui/filter.go @@ -5,6 +5,16 @@ import ( "github.com/ethereum/go-ethereum/ethutil" ) +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.EthManager) *core.Filter { filter := core.NewFilter(eth) @@ -20,12 +30,12 @@ func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core. if object["to"] != nil { val := ethutil.NewValue(object["to"]) - filter.AddTo(ethutil.Hex2Bytes(val.Str())) + filter.AddTo(fromHex(val.Str())) } if object["from"] != nil { val := ethutil.NewValue(object["from"]) - filter.AddFrom(ethutil.Hex2Bytes(val.Str())) + filter.AddFrom(fromHex(val.Str())) } if object["max"] != nil { @@ -48,11 +58,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 @@ -62,7 +72,7 @@ func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) { // ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"} func makeAltered(v interface{}) (d []core.AccountChange) { if str, ok := v.(string); ok { - d = append(d, core.AccountChange{ethutil.Hex2Bytes(str), nil}) + d = append(d, core.AccountChange{fromHex(str), nil}) } else if obj, ok := v.(map[string]interface{}); ok { d = append(d, mapToAccountChange(obj)) } else if slice, ok := v.([]interface{}); ok { diff --git a/ui/qt/filter.go b/ui/qt/filter.go index c68936401..423d5bd43 100644 --- a/ui/qt/filter.go +++ b/ui/qt/filter.go @@ -1,8 +1,6 @@ package qt import ( - "fmt" - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/ui" "gopkg.in/qml.v1" @@ -23,13 +21,10 @@ func makeAltered(v interface{}) (d []core.AccountChange) { var s []interface{} 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) } -- cgit v1.2.3 From 34689cb3f369ad71164b81d0c05238d78cb67945 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 12 Jan 2015 20:36:45 +0100 Subject: Added manual triggering of filters --- ui/qt/qwhisper/whisper.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 8b4628a1b..becb2a29b 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -84,6 +84,10 @@ func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int { return i } +func (self *Whisper) Trigger(id int) { + go self.Whisper.Trigger(id) +} + func filterFromMap(opts map[string]interface{}) (f whisper.Filter) { if to, ok := opts["to"].(string); ok { f.To = crypto.ToECDSA(fromHex(to)) -- cgit v1.2.3 From e3cad04decbbc83a0c956850717cb0ae0b2b3eec Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 13 Jan 2015 13:36:44 +0100 Subject: Fixed whisper messages * Whisper protocol wasn't properly suppling envelope slices * Message history wasn't properly propagated * Added 'Messages' method, filtering any current envelope with the supplied filter. --- ui/qt/qwhisper/message.go | 6 +++--- ui/qt/qwhisper/whisper.go | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/message.go b/ui/qt/qwhisper/message.go index c87647399..3a80381ff 100644 --- a/ui/qt/qwhisper/message.go +++ b/ui/qt/qwhisper/message.go @@ -8,9 +8,9 @@ import ( type Message struct { ref *whisper.Message - Flags int32 - Payload string - From string + Flags int32 `json:"flags"` + Payload string `json:"payload"` + From string `json:"from"` } func ToQMessage(msg *whisper.Message) *Message { diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index becb2a29b..b904678f4 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -43,7 +43,7 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr msg := whisper.NewMessage(data) envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ - Ttl: time.Duration(ttl), + Ttl: time.Duration(ttl) * time.Second, To: crypto.ToECDSAPub(fromHex(to)), From: crypto.ToECDSA(fromHex(from)), Topics: whisper.TopicsFromString(topics...), @@ -84,8 +84,14 @@ func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int { return i } -func (self *Whisper) Trigger(id int) { - go self.Whisper.Trigger(id) +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) { -- cgit v1.2.3 From 62e0e18030c84fa19f54373ebdf25f7adbc64793 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 14 Jan 2015 18:12:18 +0100 Subject: Changed public whisper api not to reveal temporary private keys --- ui/qt/qwhisper/message.go | 4 ++-- ui/qt/qwhisper/whisper.go | 45 +++++++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 20 deletions(-) (limited to 'ui') diff --git a/ui/qt/qwhisper/message.go b/ui/qt/qwhisper/message.go index 3a80381ff..26e72ac93 100644 --- a/ui/qt/qwhisper/message.go +++ b/ui/qt/qwhisper/message.go @@ -17,7 +17,7 @@ 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())), + Payload: "0x" + ethutil.Bytes2Hex(msg.Payload), + From: "0x" + ethutil.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())), } } diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index b904678f4..644c147b7 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -41,32 +41,41 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr data = append(data, fromHex(d)...) } - 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: crypto.ToECDSA(fromHex(from)), - Topics: whisper.TopicsFromString(topics...), - }) - if err != nil { - qlogger.Infoln(err) - // 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 + 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) HasIdentity(key string) bool { - return self.Whisper.HasIdentity(crypto.ToECDSA(fromHex(key))) + return self.Whisper.HasIdentity(crypto.ToECDSAPub(fromHex(key))) } func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int { -- cgit v1.2.3 From f3e78c8f3cd2196ef70a41f298b6df556543d581 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 Jan 2015 10:23:18 +0100 Subject: reworking messages => log --- ui/filter.go | 26 +++++++++----------------- ui/qt/filter.go | 17 +++++++---------- 2 files changed, 16 insertions(+), 27 deletions(-) (limited to 'ui') diff --git a/ui/filter.go b/ui/filter.go index e0797dad2..8f298a40c 100644 --- a/ui/filter.go +++ b/ui/filter.go @@ -28,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(fromHex(val.Str())) - } - - if object["from"] != nil { - val := ethutil.NewValue(object["from"]) - filter.AddFrom(fromHex(val.Str())) + if object["address"] != nil { + val := ethutil.NewValue(object["address"]) + filter.SetAddress(fromHex(val.Str())) } if object["max"] != nil { @@ -48,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 @@ -70,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{fromHex(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 423d5bd43..cb4d0311b 100644 --- a/ui/qt/filter.go +++ b/ui/qt/filter.go @@ -9,24 +9,21 @@ import ( func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *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) - d = makeAltered(s) - } else if qMap, ok := v.(*qml.Map); ok { - var m map[string]interface{} - qMap.Convert(&m) - - d = makeAltered(m) + d = ui.MakeTopics(s) + } else if str, ok := v.(string); ok { + d = ui.MakeTopics(str) } return -- cgit v1.2.3 From fb7c03ff4dc759f7dd2fc5cee65b46111cbb7375 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 Jan 2015 14:51:54 +0100 Subject: switched to obscuren/qml --- ui/qt/filter.go | 2 +- ui/qt/qwhisper/whisper.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/qt/filter.go b/ui/qt/filter.go index cb4d0311b..bd3ad0303 100644 --- a/ui/qt/filter.go +++ b/ui/qt/filter.go @@ -3,7 +3,7 @@ package qt import ( "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 { diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 644c147b7..22671f1b5 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/whisper" - "gopkg.in/qml.v1" + "github.com/obscuren/qml" ) var qlogger = logger.NewLogger("QSHH") -- cgit v1.2.3 From adda54ac5537b9f5e93a9b66ea6907a71da45aaf Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 Jan 2015 20:50:20 +0100 Subject: Added webengine initializer --- ui/qt/webengine/all.cpp | 1 + ui/qt/webengine/cpp/webengine.cpp | 6 ++++++ ui/qt/webengine/cpp/webengine.h | 14 ++++++++++++++ ui/qt/webengine/webengine.go | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 ui/qt/webengine/all.cpp create mode 100644 ui/qt/webengine/cpp/webengine.cpp create mode 100644 ui/qt/webengine/cpp/webengine.h create mode 100644 ui/qt/webengine/webengine.go (limited to 'ui') 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 +#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() + }) +} -- cgit v1.2.3 From c03d403437c20584bcbf3cf3fa9d79ac7a0a8ca7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 Jan 2015 13:25:12 +0100 Subject: Added whisper interface for xeth, added examples, updated RPC * Added RPC methods for whisper * Added whisper example --- ui/qt/qwhisper/whisper.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ui') diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 22671f1b5..98bfc69b0 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 ( -- cgit v1.2.3