forked from cerc-io/plugeth
Fixed some whisper issues
This commit is contained in:
parent
5f958a582d
commit
4a0ade4788
@ -352,6 +352,7 @@
|
||||
web3.provider = new ProviderManager();
|
||||
|
||||
web3.setProvider = function(provider) {
|
||||
console.log("setprovider", provider)
|
||||
provider.onmessage = messageHandler;
|
||||
web3.provider.set(provider);
|
||||
web3.provider.sendQueued();
|
||||
|
@ -59,7 +59,7 @@ Rectangle {
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
webview.url = "/Users/jeffrey/test.html"
|
||||
webview.url = "http://etherian.io"
|
||||
}
|
||||
|
||||
signal messages(var messages, int id);
|
||||
@ -153,7 +153,9 @@ Rectangle {
|
||||
}
|
||||
|
||||
function injectJs(js) {
|
||||
experimental.evaluateJavaScript(js)
|
||||
//webview.experimental.navigatorQtObjectEnabled = true;
|
||||
//webview.experimental.evaluateJavaScript(js)
|
||||
//webview.experimental.javascriptEnabled = true;
|
||||
}
|
||||
|
||||
function sendMessage(data) {
|
||||
@ -164,7 +166,7 @@ Rectangle {
|
||||
experimental.preferences.javascriptEnabled: true
|
||||
experimental.preferences.navigatorQtObjectEnabled: true
|
||||
experimental.preferences.developerExtrasEnabled: true
|
||||
//experimental.userScripts: ["../ext/q.js", "../ext/eth.js/main.js", "../ext/eth.js/qt.js", "../ext/setup.js"]
|
||||
experimental.userScripts: ["../ext/q.js", "../ext/eth.js/main.js", "../ext/eth.js/qt.js", "../ext/setup.js"]
|
||||
experimental.onMessageReceived: {
|
||||
console.log("[onMessageReceived]: ", message.data)
|
||||
// TODO move to messaging.js
|
||||
@ -344,24 +346,28 @@ Rectangle {
|
||||
break;
|
||||
|
||||
case "newIdentity":
|
||||
postData(data._id, shh.newIdentity())
|
||||
break
|
||||
var id = shh.newIdentity()
|
||||
console.log("newIdentity", id)
|
||||
postData(data._id, id)
|
||||
|
||||
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]; } //params.payload = params.payload.join(""); }
|
||||
params.topics = params.topics || [];
|
||||
params.priority = params.priority || 1000;
|
||||
params.ttl = params.ttl || 100;
|
||||
require(1);
|
||||
|
||||
console.log(JSON.stringify(params))
|
||||
shh.post(params.payload, params.to, params.from, params.topics, params.priority, params.ttl);
|
||||
break;
|
||||
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]; } //params.payload = params.payload.join(""); }
|
||||
params.topics = params.topics || [];
|
||||
params.priority = params.priority || 1000;
|
||||
params.ttl = params.ttl || 100;
|
||||
|
||||
shh.post(params.payload, params.to, params.from, params.topics, params.priority, params.ttl);
|
||||
|
||||
break;
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(data.call + ": " + e)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package whisper
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
@ -53,6 +54,7 @@ type Opts struct {
|
||||
}
|
||||
|
||||
func (self *Message) Seal(pow time.Duration, opts Opts) (*Envelope, error) {
|
||||
fmt.Println(opts)
|
||||
if opts.From != nil {
|
||||
err := self.sign(opts.From)
|
||||
if err != nil {
|
||||
|
@ -55,7 +55,7 @@ out:
|
||||
case <-relay.C:
|
||||
err := self.broadcast(self.host.envelopes())
|
||||
if err != nil {
|
||||
self.peer.Infoln(err)
|
||||
self.peer.Infoln("broadcast err:", err)
|
||||
break out
|
||||
}
|
||||
|
||||
|
@ -229,11 +229,11 @@ func (self *Whisper) envelopes() (envelopes []*Envelope) {
|
||||
func (self *Whisper) postEvent(envelope *Envelope) {
|
||||
for _, key := range self.keys {
|
||||
if message, err := envelope.Open(key); err == nil || (err != nil && err == ecies.ErrInvalidPublicKey) {
|
||||
// Create a custom filter?
|
||||
self.filters.Notify(filter.Generic{
|
||||
Str1: string(crypto.FromECDSA(key)), Str2: string(crypto.FromECDSAPub(message.Recover())),
|
||||
Data: bytesToMap(envelope.Topics),
|
||||
}, message)
|
||||
break
|
||||
} else {
|
||||
wlogger.Infoln(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user