forked from nannal/airdropper
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwatcher.js
86 lines (81 loc) · 2.76 KB
/
watcher.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
var steem = require('steem')
const javalon = require('javalon')
const wif = process.env.PRIVATE_KEY
const creator = 'dtube'
const prefix = ''
const give_bw = 50000
const give_vt = 1000
const give_dtc = 10000
steem.api.streamBlock(function(err, res) {
if (err) throw err;
for (let i = 0; i < res.transactions.length; i++) {
const tx = res.transactions[i]
for (let y = 0; y < tx.operations.length; y++) {
const op = tx.operations[y];
if (op[0] == 'account_update') {
var username = op[1].account
try {
var json = JSON.parse(op[1].json_metadata)
} catch (error) {
return
}
createAccAndFeed(username, json)
}
}
}
})
function createAccAndFeed(username, json) {
if (json && json.profile && json.profile.dtube_pub) {
var pubKey = json.profile.dtube_pub
console.log('Creating '+username+' '+pubKey)
var txData = {
pub: pubKey,
name: prefix+username
}
var newTx = {
type: 0,
data: txData
}
newTx = javalon.sign(wif, creator, newTx)
javalon.sendTransaction(newTx, function(err, res) {
if (err) return
console.log('Feeding '+username)
setTimeout(function() {
if (give_vt) {
var newTx = {
type: 14,
data: {
amount: give_vt,
receiver: prefix+username
}
}
newTx = javalon.sign(wif, creator, newTx)
javalon.sendTransaction(newTx, function(err, res) {})
}
if (give_bw) {
var newTx = {
type: 15,
data: {
amount: give_bw,
receiver: prefix+username
}
}
newTx = javalon.sign(wif, creator, newTx)
javalon.sendTransaction(newTx, function(err, res) {})
}
if (give_dtc) {
var newTx = {
type: 3,
data: {
amount: give_dtc,
receiver: prefix+username,
memo: 'Welcome to DTube chain!'
}
}
newTx = javalon.sign(wif, creator, newTx)
javalon.sendTransaction(newTx, function(err, res) {})
}
}, 6000)
})
}
}