-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
337 lines (315 loc) · 11.8 KB
/
index.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
const dhive = require('@hiveio/dhive');
const request = require("request");
const axios = require('axios');
const config = require('./config.js');
const {creators, privateKeys, authCodes, delegate, premiumAccounts, walletAccounts} = config;
//connect to rpc
const client = new dhive.Client(['https://anyx.io','https://api.hive.blog','https://rpc.ecency.com','https://api.deathwing.me'], {
timeout: 4000,
failoverThreshold: 20,
consoleOnFailover: true,
});
isEmpty = (obj) => {
return Object.keys(obj).length === 0;
}
sleep = (ms) => {
return new Promise(resolve=>{
setTimeout(resolve,ms)
});
}
let confirmAccounts = [];
const getPendingAccounts = (creator) =>
axios.get(`https://api.esteem.app/api/#/pending-accounts?creator=${creator}`).then(resp => resp.data);
const getPremiumAccounts = (creator) =>
axios.get(`https://api.esteem.app/api/#/pending-paid-accounts?creator=${creator}`).then(resp => resp.data);
const getWalletAccounts = (creator) =>
axios.get(`https://api.esteem.app/api/#/pending-wallet-accounts?creator=${creator}`).then(resp => resp.data);
const updPremiumExist = (data) => axios.put(`https://api.esteem.app/api/#/paid-account-exist`, data);
const updWalletExist = (data) => axios.put(`https://api.esteem.app/api/#/pending-paid-accounts`, data);
const updAccountExist = (data) => axios.put(`https://api.esteem.app/api/#/account-exist`, data);
pendingPremium = async () => {
console.log('Premium, UTC: ', new Date().toUTCString());
let pracs = await getPremiumAccounts(authCodes[0]);
if (pracs && pracs.length>0) {
for (let index = 0; index < pracs.length; index++) {
const accSearch = pracs[index].username;
let valid = await validateAccount(pracs[index], true);
if (accSearch.length > 2) {
console.log(`checking:`, accSearch);
if (valid) {
await createAccount(pracs[index], true);
await sleep(3000);
}
else {
//await updPremiumExist({username: accSearch, creator: authCodes[0]});
console.log(`error happened premium, ${accSearch} exist`);
}
}
}
} else {
console.log(new Date().toUTCString(), ' exiting, no pending #s');
if (confirmAccounts.length == 0) {
await sleep(3000);
process.exit()
}
}
}
pendingWallet = async () => {
console.log('Wallet, UTC: ', new Date().toUTCString());
let walacs = await getWalletAccounts(authCodes[0]);
if (walacs && walacs.length>0) {
for (let index = 0; index < walacs.length; index++) {
const accSearch = walacs[index].username;
let valid = await validateAccount(walacs[index], false, true);
if (accSearch.length > 2) {
console.log(`checking:`, accSearch);
if (valid) {
await createAccount(walacs[index], false, true);
await sleep(3000);
}
else {
//await updPremiumExist({username: accSearch, creator: authCodes[0]});
console.log(`error happened wallet, ${accSearch} exist`);
}
}
}
} else {
console.log(new Date().toUTCString(), ' exiting, no pending #s');
if (confirmAccounts.length == 0) {
await sleep(3000);
process.exit()
}
}
}
pendingFree = async () => {
console.log('Free, UTC: ', new Date().toUTCString());
let pacs = await getPendingAccounts(authCodes[0]);
//console.log('pending accounts', pacs);
if (pacs && pacs.length>0) {
for (let index = 0; index < pacs.length; index++) {
const accSearch = pacs[index].username;
let valid = await validateAccount(pacs[index]);
if (accSearch.length > 2) {
console.log(`checking:`, accSearch);
if (valid) {
await createAccount(pacs[index]);
await sleep(3000);
}
else {
//await updAccountExist({username: accSearch, creator: authCodes[0]});
console.log(`error happened, ${accSearch} exist`);
}
}
}
} else {
console.log(new Date().toUTCString(), ' exiting, no pending #s');
if (confirmAccounts.length == 0) {
await sleep(3000);
process.exit()
}
}
};
//create with RC function
createAccount = async (user, premium=false, wallet = false) => {
let creator = "";
let ind = -1;
let PKey = "";
let acode = "";
const creatorsStat = await client.database.call('get_accounts', [
creators
]);
for (let index = 0; index < creatorsStat.length; index++) {
const element = creatorsStat[index];
if (element.pending_claimed_accounts > 0) {
ind = index;
break;
}
}
if (ind !== -1) {
creator = creators[ind];
PKey = privateKeys[ind];
acode = authCodes[ind];
const username = user.username;
//pub keys
if (wallet) {
user.update_code = user.id;
user.owner = user.meta.ownerPublicKey;
user.active = user.meta.activePublicKey;
user.posting = user.meta.postingPublicKey;
user.memo = user.meta.memoPublicKey;
}
const update_code = user.update_code;
const memoKey = user.memo;
const ownerAuth = {
weight_threshold: 1,
account_auths: [],
key_auths: [[user.owner, 1]],
};
const activeAuth = {
weight_threshold: 1,
account_auths: [],
key_auths: [[user.active, 1]],
};
const postingAuth = {
weight_threshold: 1,
account_auths: [['ecency.app', 1]],
key_auths: [[user.posting, 1]],
};
//private active key of creator account
const privateKey = dhive.PrivateKey.fromString(
PKey
);
let ops = [];
//create operation to transmit
const create_op = [
'create_claimed_account',
{
creator: creator,
new_account_name: username,
owner: ownerAuth,
active: activeAuth,
posting: postingAuth,
memo_key: memoKey,
json_metadata: '',
extensions: [],
},
];
ops.push(create_op);
if (parseFloat(delegate) > 0) {
const delegate_op = [
'delegate_vesting_shares',
{
delegator: creator,
delegatee: username,
vesting_shares: delegate //9500.123456 VESTS ~5HP or 19000.246912 VESTS ~10HP
},
];
ops.push(delegate_op);
}
if (premium) {
const point_transfer = {
id: "ecency_point_transfer",
required_auths: [creator],
required_posting_auths: [],
json: JSON.stringify({"sender":creator,"receiver":username,"amount":"300.000 POINT","memo":"Premium bonus"})
};
ops.push(["custom_json", point_transfer]);
}
console.log(`attempting to create account: ${username} with ${creator}`);
//broadcast operation to blockchain
try {
let result = await client.broadcast.sendOperations(ops, privateKey);
if (result && result.id) {
confirmAccounts.push(username);
if (premium) {
const params = {
id: "rc",
required_auths: [],
required_posting_auths: [creator],
json: JSON.stringify(["delegate_rc",{"from":creator,"delegatees":[username],"max_rc":15000000000}])
};
client.broadcast.sendOperations([['custom_json', params]], privateKey).then(
function(result) {
if (result && result.id) {
console.log('RC delegated');
} else {
console.log(JSON.stringify(result))
}
});
}
if (wallet) {
axios.put(`https://api.esteem.app/api/#/pending-wallet-accounts`,
{
id: update_code,
creator: acode
}
)
.then(resp => {
if (isEmpty(resp.data)) {
console.log(`verified creation: ${username}`);
}
}).catch(e => {
console.log('axios update',e);
});
} else {
axios.put(premium?`https://api.esteem.app/api/#/pending-paid-accounts`:`https://api.esteem.app/api/#/pending-accounts`,
{
update_code: update_code,
creator: acode
}
)
.then(resp => {
if (isEmpty(resp.data)) {
console.log(`verified creation: ${username}`);
}
}).catch(e => {
console.log('axios update',e);
});
}
}
} catch (error) {
console.log(`error happened with ${username}`, error);
if (premium){
await updPremiumExist({username: username, creator: acode});
} else {
if (wallet) {
await updWalletExist({username: username, creator: acode});
} else {
await updAccountExist({username: username, creator: acode});
}
}
}
}
};
validateAccount = async(user, premium=false, wallet = false) => {
const [account] = await client.database.call('get_accounts', [
[user.username]
]);
if (account) {
// account already exist
let inx = creators.indexOf(account.recovery_account);
if (inx !== -1) {
if (wallet) {
axios.put('https://api.esteem.app/api/#/pending-wallet-accounts',
{
id: user._id,
creator: authCodes[inx]
}
)
.then(resp => {
if (isEmpty(resp.data)) {
console.log(`validated account: ${user.username}`);
}
}).catch(e => {
console.log(e);
});
} else {
let cuurl = premium?`https://api.esteem.app/api/#/pending-paid-accounts`:`https://api.esteem.app/api/#/pending-accounts`;
axios.put(cuurl,
{
update_code: user.update_code,
creator: authCodes[inx]
}
)
.then(resp => {
if (isEmpty(resp.data)) {
console.log(`validated account: ${user.username}`);
}
}).catch(e => {
console.log(e);
});
}
}
return false;
} else {
return true;
}
}
if (walletAccounts) {
pendingWallet();
}
if (premiumAccounts) {
pendingPremium();
} else {
pendingFree();
}