-
Notifications
You must be signed in to change notification settings - Fork 4
/
publish.js
88 lines (74 loc) · 2.97 KB
/
publish.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const DKGClient = require('dkg-client');
const OT_NODE_HOSTNAME = '0.0.0.0';
const OT_NODE_PORT = '8900';
function randomWord(length) {
let result = "";
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; ++i) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
function randomWordArray() {
let result = [];
for (let i = 0; i < Math.floor(Math.random() * 10) + 3; ++i) {
result.push(randomWord(Math.floor(Math.random() * 25) + 5));
}
return result;
}
const publish = async () => {
// initialize connection to your DKG Node
let options = { endpoint: OT_NODE_HOSTNAME, port: OT_NODE_PORT, useSSL: false, loglevel: 'info', maxNumberOfRetries: 100 };
const dkg = new DKGClient(options);
// get info about endpoint that you are connected to
await dkg.nodeInfo().then((result) => {
console.log('\x1b[35mDisable SSL as self signed certs cannot be used with V6 Beta.')
console.log('\x1b[35mCurrently running OT Node version: \x1b[32m'+result.version)
console.log(' ')
});
const keywords = randomWordArray();
publish_options = {
filepath: '/root/ODNPublish/Product.json',
assets: ['0x123456789123456789123456789'],
keywords: keywords,
visibility: "public"
};
console.log('\x1b[35mPublishing Product.json found in this directory...')
console.log('\x1b[35mPublishing data with random keywords: \x1b[32m'+keywords)
await dkg.publish(publish_options).then((result) => {
if(result.status == 'FAILED'){
console.log('\x1b[31mPublish Failed!')
console.log('\x1b[35m',result.error)
return;
}
assertion_id = result.data.id
console.log('\x1b[32mPublish Completed!')
console.log(' ')
console.log('\x1b[35mThe assertion id used for this publish is: \x1b[32m'+assertion_id)
assertion_options = {
ids: [
assertion_id
]
};
console.log('\x1b[35mWaiting for Assertion to complete...')
dkg.resolve(assertion_options).then((result) => {
if(result.status == 'FAILED'){
console.log('\x1b[31mAssertion Failed!')
console.log('\x1b[35m',result.error)
return;
}
data = result.data
console.log('\x1b[32mAssertion Completed!')
console.log(' ')
console.log('\x1b[35mHeres a string of the data!')
console.log('\x1b[32m',JSON.stringify(data));
console.log(' ')
console.log('\x1b[35mCheck out your node logs to see your node working!')
});
});
};
publish().catch((error) => console.log(`\x1b[35m${error}`));