Mailserver request uses enum or string for topics

This commit is contained in:
Richard Ramos 2018-12-06 11:55:18 -04:00
parent 575f72a6c5
commit 2265d95a84
4 changed files with 15 additions and 8 deletions

View File

@ -1,3 +1,7 @@
enum Topics {
CONTACT_DISCOVERY_TOPIC = '0xf8946aac'
}
module.exports = {
post: {
POW_TIME: 1,
@ -12,10 +16,10 @@ module.exports = {
message: "~#c4",
chatRequest: "~#c2"
},
topics: {
CONTACT_DISCOVERY_TOPIC: '0xf8946aac'
},
topics: Topics,
regExp: {
CONTACT_CODE_REGEXP: /^(0x)?[0-9a-f]{130}$/i
}
};

View File

@ -1,7 +1,7 @@
const Web3 = require("web3");
import utils from "./utils.js";
import mailservers from "./mailservers.js";
const constants = require("./constants");
import constants from "./constants.js";
const { utils: { asciiToHex, hexToAscii } } = Web3;

View File

@ -1,4 +1,7 @@
import mailserverList from "./data/mailservers.json";
import constants from "./constants.js";
const Topics = constants.topics;
class MailServers {
private web3: any;
@ -60,7 +63,7 @@ class MailServers {
});
}
public async requestMessages(topic: string, options: any, cb?: any) {
public async requestMessages(topic: string|Topics, options: any, cb?: any) {
if (this.mailserver === "") {
if (!cb) {
return;
@ -68,7 +71,7 @@ class MailServers {
return cb("Mailserver is not set", false);
}
const topics = [this.web3.utils.sha3(topic).slice(0, 10)];
const topics = [(topic in Topics) ? Topics[topic] : this.web3.utils.sha3(topic).slice(0, 10)];
const mailserverPeer = this.mailserver;
const timeout = options.timeout || 30; // seconds

View File

@ -1,4 +1,4 @@
var StatusJS = require('./src/index.js');
var StatusJS = require('./dist/index.js');
(async () => {
var status = new StatusJS();
@ -19,4 +19,4 @@ var status = new StatusJS();
});
setInterval(() => { }, 3000);
})()
})();