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.provider = new ProviderManager();
|
||||||
|
|
||||||
web3.setProvider = function(provider) {
|
web3.setProvider = function(provider) {
|
||||||
|
console.log("setprovider", provider)
|
||||||
provider.onmessage = messageHandler;
|
provider.onmessage = messageHandler;
|
||||||
web3.provider.set(provider);
|
web3.provider.set(provider);
|
||||||
web3.provider.sendQueued();
|
web3.provider.sendQueued();
|
||||||
|
@ -59,7 +59,7 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
webview.url = "/Users/jeffrey/test.html"
|
webview.url = "http://etherian.io"
|
||||||
}
|
}
|
||||||
|
|
||||||
signal messages(var messages, int id);
|
signal messages(var messages, int id);
|
||||||
@ -153,7 +153,9 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function injectJs(js) {
|
function injectJs(js) {
|
||||||
experimental.evaluateJavaScript(js)
|
//webview.experimental.navigatorQtObjectEnabled = true;
|
||||||
|
//webview.experimental.evaluateJavaScript(js)
|
||||||
|
//webview.experimental.javascriptEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMessage(data) {
|
function sendMessage(data) {
|
||||||
@ -164,7 +166,7 @@ Rectangle {
|
|||||||
experimental.preferences.javascriptEnabled: true
|
experimental.preferences.javascriptEnabled: true
|
||||||
experimental.preferences.navigatorQtObjectEnabled: true
|
experimental.preferences.navigatorQtObjectEnabled: true
|
||||||
experimental.preferences.developerExtrasEnabled: 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: {
|
experimental.onMessageReceived: {
|
||||||
console.log("[onMessageReceived]: ", message.data)
|
console.log("[onMessageReceived]: ", message.data)
|
||||||
// TODO move to messaging.js
|
// TODO move to messaging.js
|
||||||
@ -344,11 +346,15 @@ Rectangle {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "newIdentity":
|
case "newIdentity":
|
||||||
postData(data._id, shh.newIdentity())
|
var id = shh.newIdentity()
|
||||||
|
console.log("newIdentity", id)
|
||||||
|
postData(data._id, id)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case "post":
|
case "post":
|
||||||
require(1);
|
require(1);
|
||||||
|
|
||||||
var params = data.args[0];
|
var params = data.args[0];
|
||||||
var fields = ["payload", "to", "from"];
|
var fields = ["payload", "to", "from"];
|
||||||
for(var i = 0; i < fields.length; i++) {
|
for(var i = 0; i < fields.length; i++) {
|
||||||
@ -359,8 +365,8 @@ Rectangle {
|
|||||||
params.priority = params.priority || 1000;
|
params.priority = params.priority || 1000;
|
||||||
params.ttl = params.ttl || 100;
|
params.ttl = params.ttl || 100;
|
||||||
|
|
||||||
console.log(JSON.stringify(params))
|
|
||||||
shh.post(params.payload, params.to, params.from, params.topics, params.priority, params.ttl);
|
shh.post(params.payload, params.to, params.from, params.topics, params.priority, params.ttl);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
@ -6,10 +6,13 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/whisper"
|
"github.com/ethereum/go-ethereum/whisper"
|
||||||
"gopkg.in/qml.v1"
|
"gopkg.in/qml.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var qlogger = logger.NewLogger("QSHH")
|
||||||
|
|
||||||
func fromHex(s string) []byte {
|
func fromHex(s string) []byte {
|
||||||
if len(s) > 1 {
|
if len(s) > 1 {
|
||||||
return ethutil.Hex2Bytes(s[2:])
|
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) {
|
func (self *Whisper) Post(payload []string, to, from string, topics []string, priority, ttl uint32) {
|
||||||
var data []byte
|
var data []byte
|
||||||
for _, d := range payload {
|
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)
|
msg := whisper.NewMessage(data)
|
||||||
envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{
|
envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{
|
||||||
Ttl: time.Duration(ttl),
|
Ttl: time.Duration(ttl),
|
||||||
@ -47,13 +51,13 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr
|
|||||||
Topics: whisper.TopicsFromString(topics...),
|
Topics: whisper.TopicsFromString(topics...),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
qlogger.Infoln(err)
|
||||||
// handle error
|
// handle error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := self.Whisper.Send(envelope); err != nil {
|
if err := self.Whisper.Send(envelope); err != nil {
|
||||||
fmt.Println(err)
|
qlogger.Infoln(err)
|
||||||
// handle error
|
// handle error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package whisper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
@ -53,6 +54,7 @@ type Opts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Message) Seal(pow time.Duration, opts Opts) (*Envelope, error) {
|
func (self *Message) Seal(pow time.Duration, opts Opts) (*Envelope, error) {
|
||||||
|
fmt.Println(opts)
|
||||||
if opts.From != nil {
|
if opts.From != nil {
|
||||||
err := self.sign(opts.From)
|
err := self.sign(opts.From)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,7 +55,7 @@ out:
|
|||||||
case <-relay.C:
|
case <-relay.C:
|
||||||
err := self.broadcast(self.host.envelopes())
|
err := self.broadcast(self.host.envelopes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
self.peer.Infoln(err)
|
self.peer.Infoln("broadcast err:", err)
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,11 +229,11 @@ func (self *Whisper) envelopes() (envelopes []*Envelope) {
|
|||||||
func (self *Whisper) postEvent(envelope *Envelope) {
|
func (self *Whisper) postEvent(envelope *Envelope) {
|
||||||
for _, key := range self.keys {
|
for _, key := range self.keys {
|
||||||
if message, err := envelope.Open(key); err == nil || (err != nil && err == ecies.ErrInvalidPublicKey) {
|
if message, err := envelope.Open(key); err == nil || (err != nil && err == ecies.ErrInvalidPublicKey) {
|
||||||
// Create a custom filter?
|
|
||||||
self.filters.Notify(filter.Generic{
|
self.filters.Notify(filter.Generic{
|
||||||
Str1: string(crypto.FromECDSA(key)), Str2: string(crypto.FromECDSAPub(message.Recover())),
|
Str1: string(crypto.FromECDSA(key)), Str2: string(crypto.FromECDSAPub(message.Recover())),
|
||||||
Data: bytesToMap(envelope.Topics),
|
Data: bytesToMap(envelope.Topics),
|
||||||
}, message)
|
}, message)
|
||||||
|
break
|
||||||
} else {
|
} else {
|
||||||
wlogger.Infoln(err)
|
wlogger.Infoln(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user