-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.js
executable file
·122 lines (114 loc) · 2.49 KB
/
scraper.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
#!/usr/bin/env node
const commandLineArgs = require("command-line-args");
const eventScraper = require("./src/lib/eventScraper");
const { migrateEvents, migrateContracts } = require("./src/migrateEvents");
const pkg = require("./package.json");
const Sql = require("./src/db/Sql");
const optionDefinitions = [
{
name: "help",
alias: "h",
type: Boolean,
},
{
name: "verbose",
alias: "v",
type: Boolean,
},
{
name: "types",
alias: "t",
type: String,
defaultValue: "Staked,Unstaked,YieldClaimed",
},
{
name: "contract",
alias: "c",
type: String,
},
{
name: "event",
alias: "e",
type: String,
},
{
name: "force",
alias: "f",
type: Boolean,
},
{
name: "blocks",
alias: "b",
type: Number,
},
{
name: "limit",
alias: "l",
type: Number,
},
{
name: "starting-block",
alias: "s",
type: Number,
},
{
name: "drop-table",
type: String,
},
];
function error(message) {
if (!Array.isArray(message)) {
message = [message];
}
console.error(message[0]);
if (message[1]) {
console.info(message[1]);
}
/*eslint-disable-next-line*/
process.exit(1);
}
let options = {};
try {
options = commandLineArgs(optionDefinitions, {
camelCase: true,
});
} catch (e) {
error(e.message);
}
if (options.help) {
console.info(`
Event Scraper V${pkg.version}
Options:
-h, --help This help.
-v, --verbose Shows all the console logs. Default TRUE
-t, --types A comma seperated string o type of event to get (for example "Staked, Unstaked, YieldClaimed")
-c, --contract The contract to get events from
-e, --event The event to retrieve
-f, --force Force the retrieve of all the events from deployment time
-b, --blocks It retrieves the events with "fromBlock = latest blocks - blocks"
-l, --limit The number of events to retrieve at any request
`);
// eslint-disable-next-line no-process-exit
process.exit(0);
}
async function main() {
if (options.dropTable) {
const sql = new Sql();
const dbw = await sql.sql();
console.log("Dropping", options.dropTable);
await dbw.schema.dropTableIfExists(options.dropTable);
}
await migrateContracts();
await migrateEvents();
if (typeof options.verbose === "undefined") {
options.verbose = true;
}
options.scope = "historical";
await eventScraper(options);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});