-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
90 lines (70 loc) · 2.16 KB
/
index.ts
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
import minimist from 'minimist';
import * as fs from 'fs';
import { Keys, CLPublicKey, DeployUtil, CasperClient } from 'casper-js-sdk';
const sleep = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
const params = minimist(process.argv.slice(2));
const {
_: args
} = params;
const [list, privateKeyPath, networkName, nodeUrl, timeout] = args;
if (!list) {
throw new Error('Missing list argument');
}
if (!privateKeyPath) {
throw new Error('Missing private keys argument');
}
if (!networkName) {
throw new Error('Missing networkName argument');
}
if (!nodeUrl) {
throw new Error('Missing nodeUrl argument');
}
if (!timeout) {
throw new Error('Missing timeout argument');
}
const readJSON = (path: string) => {
try {
const result = fs.readFileSync(path).toString();
return JSON.parse(result);
} catch {
console.log("Something break when reading JSON...");
}
};
const run = async () => {
let json;
try {
const data = fs.readFileSync(list, 'utf8');
json = readJSON(list);
} catch (err) {
console.error(err);
console.error('Error reading the JSON file');
}
const privateKeyBytes = Keys.Ed25519.parsePrivateKeyFile(privateKeyPath)
const publicKeyBytes = Keys.Ed25519.privateToPublicKey(privateKeyBytes)
const keyPair = Keys.Ed25519.parseKeyPair(publicKeyBytes, privateKeyBytes);
const paymentAmount = 100000000;
for await (const [i, entry] of json.entries()) {
const { publickey, amount } = entry;
const recipientKey = CLPublicKey.fromHex(publickey);
const transferId = i;
const deployParams = new DeployUtil.DeployParams(
keyPair.publicKey,
networkName
);
const session = DeployUtil.ExecutableDeployItem.newTransfer(
amount,
recipientKey,
undefined,
transferId
);
const payment = DeployUtil.standardPayment(paymentAmount);
let deploy = DeployUtil.makeDeploy(deployParams, session, payment);
deploy = DeployUtil.signDeploy(deploy, keyPair);
const hash = await deploy.send(nodeUrl);
console.log(`Sent deploy ${hash} for account ${publickey} - ${amount} cspr motes`);
await sleep(Number(timeout) * 1000);
}
}
run();