Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
changed values
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Jentzsch committed Nov 21, 2015
1 parent 02111a6 commit 1edfbec
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions modules/shh.js
@@ -1,20 +1,28 @@
module.exports = function () {

// we use the events and config from the prototype, because the
// "watchContract"-event
// may be triggered before the init-methode is called
var events = this.events;
events.on("watchContract", function (contract) {

// get the wisper-object
var web3 = contract.web3;

// watch for incoming messages
web3.shh.watch({
'topic': [ web3.fromAscii(contract.config.adr) ]
}).arrived(function(m) {
events.emit("message", { to: contract.config.adr, msg: web3.toAscii(m.payload[0]), from:web3.toAscii(m.payload[1])});
});

});
};
function normalizeAdr(a) {
if (!a) return a;
if (a.length>2 && a[1]=='x') a=a.substring(2);
while (a.length<40) a="0"+a;
return "0x"+a;
}


module.exports = function () {

// we use the events and config from the prototype, because the
// "watchContract"-event
// may be triggered before the init-methode is called
var events = this.events;
events.on("watchContract", function (contract) {

// get the wisper-object
var web3 = contract.web3;

// watch for incoming messages
web3.shh.watch({
'topic': [ normalizeAdr(contract.config.adr) ]
}).arrived(function(m) {
events.emit("message", { to: normalizeAdr(contract.config.adr), msg: web3.toAscii(m.payload[0]), from:m.payload[1] });
});

});
};

0 comments on commit 1edfbec

Please sign in to comment.