forked from zeroxbt/payout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (54 loc) · 2.19 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
const fs = require("fs");
const getOffers = require("./src/offers");
const Blockchain = require("./src/blockchain");
const config = JSON.parse(fs.readFileSync("./config.json"));
const wallets = JSON.parse(fs.readFileSync("./wallets.json"));
(async () => {
for (const wallet of wallets) {
try {
console.log(`Starting payout process for node ${wallet.nodeId}`);
const offers = await getOffers(wallet.nodeId);
for (const blockchainName of Object.keys(offers)) {
const totalOffers = offers[blockchainName].offers.length;
console.log(
`${totalOffers} offers found on ${blockchainName} blockchain`
);
if (totalOffers <= 0) continue;
const blockchain = new Blockchain({
chainId: offers[blockchainName].chainId,
blockchainName,
rpc: config.blockchain[blockchainName].rpc,
publicKey: wallet.publicKey,
privateKey: Buffer.from(wallet.privateKey, "hex"),
hubContractAddress:
config.blockchain[blockchainName].hubContractAddress,
gasStation: config.blockchain[blockchainName].gasStation,
});
console.log(
"--------------------------------------------------------------------"
);
for (const offerIndex in offers[blockchainName].offers) {
const offer = offers[blockchainName].offers[offerIndex];
console.log(
`${blockchainName} offer ${Number(offerIndex) + 1} / ${totalOffers}`
);
console.log(
"--------------------------------------------------------------------"
);
const serializedTx = await blockchain.prepareTransaction(offer);
const receipt = await blockchain.sendSignedTransaction(serializedTx);
console.log(`payout transaction successfull : ${receipt.status}`);
console.log(`payout transaction hash : ${receipt.transactionHash}`);
console.log(
"--------------------------------------------------------------------"
);
}
}
} catch (e) {
console.log(
`there was an error processing payouts for node ${wallet.nodeId} : ${e}`
);
}
}
process.exit();
})();