forked from sascha1337/node-red-contrib-iota-lib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiota-search.js
73 lines (67 loc) · 2.67 KB
/
iota-search.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const IOTA = require('iota.lib.js');
const { isTag } = require('@iota/validators');
const TRAN = require('transliteration');
module.exports = function(RED) {
function iotasearch(config) {
RED.nodes.createNode(this,config);
var node = this;
node._sec = 2;
node._firstroot = '';
var iota_value = '';
this.iotaNode = RED.nodes.getNode(config.iotaNode);
const iota = new IOTA({'host': this.iotaNode.host, 'port': this.iotaNode.port});
node.readyIota = true;
node.on('input', function(msg) {
if (this.readyIota) {
console.log("Searching dataset via findTransactionObjects.")
this.readyIota = false;
var self = this;
this.status({fill:"red",shape:"ring",text:"connecting"});
iota_value = config.iotaValue;
var objeto;
switch (config.iotaSelect){
case 'addresses':
if (iota.valid.isAddress(msg.payload)) {
iota_value = msg.payload;
//console.log("searching address: "+iota_value);
}
objeto = {addresses:[iota_value]};
break;
case 'bundles':
if (iota.utils.isBundle(msg.payload)) {
iota_value = msg.payload;
//console.log("searching bundle... : "+iota_value);
}
objeto = {bundles:[iota_value]};
break;
case 'tags':
if (isTag(msg.payload)) {
iota_value = msg.payload;
//console.log("searching tag: "+iota_value);
}
objeto = {tags:[iota_value]};
break;
case 'approvees':
objeto = {approvees:[iota_value]};
break;
}
console.log(objeto);
iota.api.findTransactionObjects(objeto, (error, success) => {
//console.log("Report from iota node:");
this.status({});
if (error) {
console.log(error);
msg.payload=error;
self.send(msg);
} else {
console.log(success);
msg.payload=success;
self.send(msg);
}
self.readyIota = true;
});
}
});
}
RED.nodes.registerType("iotasearch",iotasearch);
}