This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtx0Publish.js
55 lines (49 loc) · 1.82 KB
/
tx0Publish.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
const IOTA = require('iota.lib.js');
const TRAN = require('transliteration');
module.exports = function(RED) {
function tx0Publish(config) {
RED.nodes.createNode(this,config);
var node = this;
node._sec = 2;
node._firstroot = '';
console.log("Publish 0-value tx on iota node: " + config.iotaNode);
const iota = new IOTA({ provider: config.iotaNode })
node.readyIota = true;
node.on('input', function(msg) {
if (this.readyIota) {
let txt = JSON.stringify(msg.payload);
let ascii = TRAN.transliterate(txt)
let trytes = iota.utils.toTrytes(ascii)
console.log("message payload: "+msg.payload)
console.log("transliterated: "+ascii)
console.log("trytes: "+trytes)
console.log("Uploading dataset via sendTransfer - please wait")
const iota_addr = config.iotaAddr; //'HELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDD'
const iota_seed = config.iotaSeed; //'HELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDD'
const transfers = [
{
value: 0,
address: iota_addr,
message: trytes
}
]
this.readyIota = false;
var self = this;
iota.api.sendTransfer(iota_seed, 14, 14, transfers, (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;
self.send(msg);
}
self.readyIota = true;
});
}
});
}
RED.nodes.registerType("tx0Publish",tx0Publish);
}