-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.js
92 lines (78 loc) · 2.38 KB
/
runner.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
const eosjs = require('eosjs')
const fetch = require('node-fetch')
const util = require('util')
const config = require('./config')
const JsSignatureProvider = require('eosjs/dist/eosjs-jssig').JsSignatureProvider
const axios = require('axios')
const JsonRpc = eosjs.JsonRpc
const Api = eosjs.Api
const nodeUrl = config.nodeUrl
const keys = config.keys
const mainnetSignatureProvider = new JsSignatureProvider(config.mainnet.keys);
const testnetSignatureProvider = new JsSignatureProvider(config.testnet.keys);
const mainnetRpc = new JsonRpc(config.mainnet.nodeUrl, { fetch })
const testnetRpc = new JsonRpc(config.testnet.nodeUrl, { fetch })
const mainnet = new Api({
rpc: mainnetRpc,
signatureProvider: mainnetSignatureProvider,
textDecoder: new util.TextDecoder(),
textEncoder: new util.TextEncoder()
});
const testnet = new Api({
rpc: testnetRpc,
signatureProvider: testnetSignatureProvider,
textDecoder: new util.TextDecoder(),
textEncoder: new util.TextEncoder()
});
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
function random(min, max) {
return Math.floor(
Math.random() * (max - min) + min
)
}
(async (mainnet, testnet) => {
while (true) {
console.log("MAINNET=======");
api = mainnet;
await doMechanics();
await doEosioPay();
console.log("TESTNET=======");
api = testnet;
await doMechanics();
await doEosioPay();
await sleep(random(40000, 60000));
}
})(mainnet, testnet)
async function doMechanics() {
console.log("sending CPU eosmechanics");
const result = await sendActions([{
account: 'eosmechanics',
name: 'cpu',
authorization: [{
actor: 'eosmechanics',
permission: 'active',
}],
data: {}
}])
console.log("sent CPU eosmechanics");
}
async function doEosioPay() {
console.log("sending eosio::pay");
const result = await sendActions([{
account: 'eosio',
name: 'pay',
authorization: [{
actor: 'eosmechanics',
permission: 'active',
}],
data: {}
}])
console.log("sent eosio::pay");
}
async function sendActions(actions, catchError) {
try {
return await api.transact({ actions: actions }, { blocksBehind: 3, expireSeconds: 30 });
} catch (e) {
console.log(e.message);
}
}