-
Notifications
You must be signed in to change notification settings - Fork 2
/
neume.ts
180 lines (176 loc) · 4.86 KB
/
neume.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env node
//@ts-nocheck
import "dotenv/config";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import path from "path";
import crawl from "./commands/crawl.js";
import dump from "./commands/dump.js";
import filterContracts from "./commands/filter_contracts.js";
import { getLatestBlockNumber, getStrategies } from "./src/utils.js";
import daemon from "./commands/daemon.js";
import sync from "./commands/sync.js";
import init from "./commands/init.js";
import { db } from "./database/index.js";
import runMigration from "./database/runMigration.js";
const argv = yargs(hideBin(process.argv))
.usage("Usage: $0 <command> <options>")
.env("NEUME")
.command(
"runMigration",
"Run migrations on the database",
{
type: {
type: "string",
describe: "Up or Down?",
demandOption: true,
choices: ["up", "down"],
},
},
async (argv) => {
await runMigration(argv.type);
},
)
.command(
"crawl",
"Find new NFTs from the list of already known contracts",
{
from: {
type: "number",
describe: "From block number",
demandOption: true,
},
to: {
type: "number",
describe: "To block number",
},
recrawl: {
type: "boolean",
describe: "Re-crawl an NFT if they already exist",
default: false,
},
},
async (argv) => {
const { config, strategies: strategyNames } = await import(path.resolve("./config.js"));
const from = argv.from;
const to = argv.to ?? (await getLatestBlockNumber(config.rpc[0]));
await crawl(from, to, argv.recrawl, config, getStrategies(strategyNames, from, to));
process.exit(0);
},
)
.command(
"filter-contracts",
"Find new contracts",
{
from: {
type: "number",
describe: "From block number",
demandOption: true,
},
to: {
type: "number",
describe: "From block number",
},
recrawl: {
type: "boolean",
describe: "Re-crawl an NFT if they already exist",
default: false,
},
},
async (argv) => {
const { config, strategies: strategyNames } = await import(path.resolve("./config.js"));
const from = argv.from;
const to = argv.to ?? (await getLatestBlockNumber(config.rpc[0]));
await filterContracts(from, to, argv.recrawl, config, getStrategies(strategyNames, from, to));
process.exit(0);
},
)
.command(
"dump",
"Export database as JSON",
{
at: {
type: "number",
describe: "Export database as seen at the given block number",
demandOption: true,
},
},
async (argv) => {
const { config } = await import(path.resolve("./config.js"));
const at = argv.at ?? (await getLatestBlockNumber(config.rpc[0]));
return dump(at);
},
)
.command(
"daemon",
"Start neume-network daemon",
{
from: {
type: "number",
describe: "From block number",
defaultDescription: "Last crawled block number",
},
crawl: {
type: "boolean",
describe: "Flag for crawler",
default: true,
defaultDescription: "true",
},
recrawl: {
type: "boolean",
describe: "Re-crawl an NFT if they already exist",
default: false,
defaultDescription: "false",
},
port: {
type: "number",
describe: "Port for the daemon",
default: 8080,
defaultDescription: "8080",
},
},
async (argv) => {
const { config, strategies: strategyNames } = await import(path.resolve("./config.js"));
await daemon(argv.from, argv.crawl, argv.recrawl, argv.port, config, strategyNames);
},
)
.command(
"sync",
"Sync neume-network with another node",
{
url: {
type: "string",
describe: "An endpoint that is running the neume-network daemon",
demandOption: true,
},
from: {
type: "number",
describe: "From block number",
defaultDescription: "Uses the database to calculate the last synced block",
},
to: {
type: "number",
describe: "To block number",
defaultDescription: "Syncs to the latest block number",
},
},
async (argv) => {
const { config, strategies: strategyNames } = await import(path.resolve("./config.js"));
const to = argv.to ?? (await getLatestBlockNumber(config.rpc[0]));
// @ts-ignore
await sync(argv.from, to, argv.url, config);
process.exit(0);
},
)
.command("create-change-index", "Create change index from primary database", async (argv) => {
return db.createChangeIndex();
})
.command(
"init",
"Initialize files required by neume at the current working directory",
async (argv) => {
await init();
},
)
.help(true)
.parse();