fix unneeded ascii conversion for topics

This commit is contained in:
Iuri Matias 2017-01-07 09:32:10 -05:00
parent 8f434df926
commit 6389884851
2 changed files with 14 additions and 14 deletions

View File

@ -293,21 +293,21 @@ var EmbarkJS =
// do fromAscii to each topics unless it's already a string // do fromAscii to each topics unless it's already a string
if (typeof topics === 'string') { if (typeof topics === 'string') {
topics = topics; _topics = [web3.fromAscii(topics)];
} else { } else {
// TODO: replace with es6 + babel; // TODO: replace with es6 + babel;
var _topics = []; var _topics = [];
for (var i = 0; i < topics.length; i++) { for (var i = 0; i < topics.length; i++) {
_topics.push(web3.fromAscii(topics[i])); _topics.push(web3.fromAscii(topics[i]));
} }
topics = _topics;
} }
topics = _topics;
var payload = JSON.stringify(data); var payload = JSON.stringify(data);
var message = { var message = {
from: identity, from: identity,
topics: [web3.fromAscii(topics)], topics: topics,
payload: web3.fromAscii(payload), payload: web3.fromAscii(payload),
ttl: ttl, ttl: ttl,
priority: priority priority: priority
@ -320,15 +320,15 @@ var EmbarkJS =
var topics = options.topic || options.topics; var topics = options.topic || options.topics;
if (typeof topics === 'string') { if (typeof topics === 'string') {
topics = [web3.fromAscii(topics)]; _topics = [topics];
} else { } else {
// TODO: replace with es6 + babel; // TODO: replace with es6 + babel;
var _topics = []; var _topics = [];
for (var i = 0; i < topics.length; i++) { for (var i = 0; i < topics.length; i++) {
_topics.push(web3.fromAscii(topics[i])); _topics.push(topics[i]);
} }
topics = _topics;
} }
topics = _topics;
var filterOptions = { var filterOptions = {
topics: topics topics: topics
@ -355,7 +355,7 @@ var EmbarkJS =
promise.error(err); promise.error(err);
} else { } else {
data = { data = {
topic: topics.map((t) => web3.toAscii(t)), topic: topics,
data: payload, data: payload,
from: result.from, from: result.from,
time: (new Date(result.sent * 1000)) time: (new Date(result.sent * 1000))

View File

@ -246,21 +246,21 @@ EmbarkJS.Messages.Whisper.sendMessage = function(options) {
// do fromAscii to each topics unless it's already a string // do fromAscii to each topics unless it's already a string
if (typeof topics === 'string') { if (typeof topics === 'string') {
topics = topics; _topics = [web3.fromAscii(topics)];
} else { } else {
// TODO: replace with es6 + babel; // TODO: replace with es6 + babel;
var _topics = []; var _topics = [];
for (var i = 0; i < topics.length; i++) { for (var i = 0; i < topics.length; i++) {
_topics.push(web3.fromAscii(topics[i])); _topics.push(web3.fromAscii(topics[i]));
} }
topics = _topics;
} }
topics = _topics;
var payload = JSON.stringify(data); var payload = JSON.stringify(data);
var message = { var message = {
from: identity, from: identity,
topics: [web3.fromAscii(topics)], topics: topics,
payload: web3.fromAscii(payload), payload: web3.fromAscii(payload),
ttl: ttl, ttl: ttl,
priority: priority priority: priority
@ -273,15 +273,15 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
var topics = options.topic || options.topics; var topics = options.topic || options.topics;
if (typeof topics === 'string') { if (typeof topics === 'string') {
topics = [web3.fromAscii(topics)]; _topics = [topics];
} else { } else {
// TODO: replace with es6 + babel; // TODO: replace with es6 + babel;
var _topics = []; var _topics = [];
for (var i = 0; i < topics.length; i++) { for (var i = 0; i < topics.length; i++) {
_topics.push(web3.fromAscii(topics[i])); _topics.push(topics[i]);
} }
topics = _topics;
} }
topics = _topics;
var filterOptions = { var filterOptions = {
topics: topics topics: topics
@ -308,7 +308,7 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
promise.error(err); promise.error(err);
} else { } else {
data = { data = {
topic: topics.map((t) => web3.toAscii(t)), topic: topics,
data: payload, data: payload,
from: result.from, from: result.from,
time: (new Date(result.sent * 1000)) time: (new Date(result.sent * 1000))