forked from LynxLine/node-red-contrib-iota-tx0
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiota-transactions.js
56 lines (53 loc) · 2.11 KB
/
iota-transactions.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
const IOTA = require('iota.lib.js');
const TRAN = require('transliteration');
module.exports = function(RED) {
function iotatransactions(config) {
RED.nodes.createNode(this,config);
var node = this;
node._sec = 2;
node._firstroot = '';
var iota_hash = '';
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 getTransactionsObjects.")
this.readyIota = false;
var self = this;
this.status({fill:"red",shape:"ring",text:"connecting"});
if (iota.valid.isHash(msg.payload)) {
iota_hash = msg.payload;
} else {
iota_hash = config.iotaHash;
}
console.log("Input HASH: "+iota_hash);
iota.api.getTransactionsObjects([iota_hash], (error, success) => {
//console.log("Report from iota node:")
if (error) {
console.log(error);
msg.payload=error;
self.send(msg);
} else {
console.log(success);
msg.payload=success;
iota.api.getLatestInclusion([iota_hash], function(err,suc) {
if (err) {
console.error(err);
msg.payload=err;
self.send(msg);
} else {
console.log(suc);
msg.payload[0].confirmed=suc[0];
self.send(msg);
}
});
}
this.status({});
self.readyIota = true;
});
}
});
}
RED.nodes.registerType("iotatransactions",iotatransactions);
}