-
Notifications
You must be signed in to change notification settings - Fork 0
/
getRedstonePayload.js
48 lines (33 loc) · 1.35 KB
/
getRedstonePayload.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
const { appendFileSync } = require('fs');
const { DataPackage, NumericDataPoint, RedstonePayload } = require('./lib/redstone-oracles-monorepo/packages/protocol/dist/src/index');
const args = process.argv.slice(2);
const exit = (code, message) => {
process.stderr.write(message);
appendFileSync("./getRedstonePayload.log.txt", message);
process.exit(code);
}
if (args.length === 0) {
exit(1, "You have to provide at least on dataFeed");
}
const dataFeeds = args[0].split(',');
if (dataFeeds.length === 0) {
exit(2, "You have to provide at least on dataFeed");
}
const timestampMilliseconds = Date.now();
const PRIVATE_KEY_1 = '0x548e7c2fae09cc353ffe54ed40609d88a99fab24acfc81bfbf5cd9c11741643d';
const dataPoints = dataFeeds.map(arg => {
const [dataFeedId, value, decimals] = arg.split(':');
if (!dataFeedId || !value || !decimals) {
exit(3, "Input should have format: dataFeedId:value:decimals (example: BTC:120:8)");
}
return new NumericDataPoint({ dataFeedId, value: parseInt(value), decimals: parseInt(decimals) })
});
// Prepare unsigned data package
const dataPackage = new DataPackage(dataPoints, timestampMilliseconds);
// Prepare signed data packages
const signedDataPackages = [
dataPackage.sign(PRIVATE_KEY_1),
];
const payload = RedstonePayload.prepare(signedDataPackages, "");
process.stdout.write("0x" + payload)
process.exit(0);