forked from bitshares/bitshares-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scamParser.js
39 lines (38 loc) · 1.32 KB
/
scamParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const scamAccounts = "./app/lib/common/scamAccounts.js";
const fs = require("fs");
const path = require("path");
const util = require("util");
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
const {ChainStore} = require("bitsharesjs");
readFile(path.resolve(scamAccounts), "utf8")
.then(str => {
let matches = [].concat
.apply(
[],
str.split('"').map((v, i) => {
return i % 2 ? '"' + v + '"' : v.split(" ");
})
)
.filter(Boolean);
let result = matches.map((o, i) => {
if (o.includes('"')) {
let obj = o.substring(1, o.length - 1);
let db = ChainStore.getAccount(obj);
if (db) {
let id = db.get("id");
let nextElement = matches[i + 3];
if (nextElement && id !== +nextElement.replace(/\"/g, "")) {
return [" ", o, ', \n "', id, '"'].join("");
} else {
matches[i + 3] = id;
}
}
}
return o;
});
return result.join(" ");
})
.then(result => {
writeFile(path.resolve(scamAccounts) + "x", result);
});