diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-24 01:19:33 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-24 01:19:33 +0800 |
commit | 72e2613a9fe3205fa5a67b72b832e03b2357ee88 (patch) | |
tree | bbc987510d279d9e174ff8f684158d668131661e /ui/qt/qwhisper/whisper.go | |
parent | 5daf8729be88eca87b302ebf7a46fc69cad0f6d0 (diff) | |
parent | 67e6f74e9af00ff011a6a02f18644804eb18cdaa (diff) | |
download | go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.gz go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.bz2 go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.lz go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.xz go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.zst go-tangerine-72e2613a9fe3205fa5a67b72b832e03b2357ee88.zip |
Merge branch 'release/0.9.32'v0.9.32
Diffstat (limited to 'ui/qt/qwhisper/whisper.go')
-rw-r--r-- | ui/qt/qwhisper/whisper.go | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go deleted file mode 100644 index 4ab6d2e5a..000000000 --- a/ui/qt/qwhisper/whisper.go +++ /dev/null @@ -1,113 +0,0 @@ -// QWhisper package. This package is temporarily on hold until QML DApp dev will reemerge. -package qwhisper - -import ( - "time" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/whisper" - "github.com/obscuren/qml" -) - -var qlogger = logger.NewLogger("QSHH") - -type Whisper struct { - *whisper.Whisper - view qml.Object - - watches map[int]*Watch -} - -func New(w *whisper.Whisper) *Whisper { - return &Whisper{w, nil, make(map[int]*Watch)} -} - -func (self *Whisper) SetView(view qml.Object) { - self.view = view -} - -func (self *Whisper) Post(payload []string, to, from string, topics []string, priority, ttl uint32) { - var data []byte - for _, d := range payload { - data = append(data, common.FromHex(d)...) - } - - pk := crypto.ToECDSAPub(common.FromHex(from)) - if key := self.Whisper.GetIdentity(pk); key != nil { - msg := whisper.NewMessage(data) - envelope, err := msg.Wrap(time.Duration(priority*100000), whisper.Options{ - TTL: time.Duration(ttl) * time.Second, - To: crypto.ToECDSAPub(common.FromHex(to)), - From: key, - Topics: whisper.NewTopicsFromStrings(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 { - key := self.Whisper.NewIdentity() - - return common.ToHex(crypto.FromECDSAPub(&key.PublicKey)) -} - -func (self *Whisper) HasIdentity(key string) bool { - return self.Whisper.HasIdentity(crypto.ToECDSAPub(common.FromHex(key))) -} - -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("onShhMessage", ToQMessage(msg), i) - } - } - - i = self.Whisper.Watch(filter) - self.watches[i] = &Watch{} - - return i -} - -func (self *Whisper) Messages(id int) (messages *common.List) { - msgs := self.Whisper.Messages(id) - messages = common.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.ToECDSAPub(common.FromHex(to)) - } - if from, ok := opts["from"].(string); ok { - f.From = crypto.ToECDSAPub(common.FromHex(from)) - } - if topicList, ok := opts["topics"].(*qml.List); ok { - var topics []string - topicList.Convert(&topics) - f.Topics = whisper.NewFilterTopicsFromStringsFlat(topics...) - } - - return -} |