@certik/skynet 0.10.4 → 0.10.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +5 -5
- package/.eslintrc.js +13 -13
- package/.prettierrc.js +3 -3
- package/CHANGELOG.md +372 -364
- package/README.md +23 -23
- package/abi.js +353 -353
- package/ably.js +29 -0
- package/address.js +18 -18
- package/api.js +105 -105
- package/app.js +709 -695
- package/availability.js +58 -58
- package/block.js +83 -83
- package/cli.js +53 -53
- package/const.js +92 -92
- package/deploy.js +676 -673
- package/dynamodb.js +444 -444
- package/env.js +90 -90
- package/examples/api +73 -73
- package/examples/consumer +47 -47
- package/examples/indexer +65 -65
- package/examples/mode-indexer +82 -82
- package/examples/producer +80 -80
- package/indexer.js +595 -595
- package/inquiry.js +14 -14
- package/kafka.js +443 -442
- package/labelling.js +90 -90
- package/log.js +29 -29
- package/metric.js +65 -65
- package/monitor.js +191 -192
- package/opsgenie.js +55 -60
- package/package.json +37 -34
- package/price.js +48 -48
- package/primitive.js +77 -77
- package/proxy.js +157 -157
- package/rateLimit.js +21 -21
- package/s3.js +122 -122
- package/scan.js +74 -74
- package/selector.js +53 -53
- package/slack.js +87 -87
- package/snowflake.js +36 -36
- package/sqs.js +12 -12
- package/token.js +46 -46
- package/transaction.js +41 -41
- package/util.js +67 -67
- package/web3.js +117 -117
package/env.js
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
function getAWSAccessKeyId() {
|
|
2
|
-
return ensureAndGet(["SKYNET_AWS_ACCESS_KEY_ID"], undefined);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function getAWSSecretAccessKey() {
|
|
6
|
-
return ensureAndGet(["SKYNET_AWS_SECRET_ACCESS_KEY"], undefined);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function getAWSRegion() {
|
|
10
|
-
return ensureAndGet(["SKYNET_AWS_REGION"], "us-east-1");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getEnvironment() {
|
|
14
|
-
return ensureAndGet("SKYNET_ENVIRONMENT", "dev");
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getEtherScanApiKey() {
|
|
18
|
-
return ensureAndGet("SKYNET_ETHER_SCAN_API_KEY");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getBscScanApiKey() {
|
|
22
|
-
return ensureAndGet("SKYNET_BSC_SCAN_API_KEY");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getPolygonScanApiKey() {
|
|
26
|
-
return ensureAndGet("SKYNET_POLYGON_SCAN_API_KEY");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getGetBlockApiKey() {
|
|
30
|
-
return ensureAndGet("SKYNET_GETBLOCK_API_KEY");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function getAlchemyApiKey(identifier) {
|
|
34
|
-
// Alchemy API keys are different for each alchemy app
|
|
35
|
-
return ensureAndGet(`SKYNET_ALCHEMY_API_${identifier.toUpperCase()}_KEY`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getNodeRealApiKey(identifier) {
|
|
39
|
-
// NodeReal API keys are different for each NodeReal app
|
|
40
|
-
return ensureAndGet(`SKYNET_NODEREAL_API_${identifier.toUpperCase()}_KEY`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function ensureAndGet(envName, defaultValue) {
|
|
44
|
-
if (Array.isArray(envName)) {
|
|
45
|
-
for (let name of envName) {
|
|
46
|
-
if (process.env[name]) {
|
|
47
|
-
return process.env[name];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return defaultValue;
|
|
51
|
-
} else {
|
|
52
|
-
if (process.env[envName]) {
|
|
53
|
-
return process.env[envName];
|
|
54
|
-
}
|
|
55
|
-
return defaultValue;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getEnvOrThrow(envName) {
|
|
60
|
-
if (!process.env[envName]) {
|
|
61
|
-
throw new Error(`Must set environment variable ${envName}`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return process.env[envName];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function isProduction() {
|
|
68
|
-
return getEnvironment() === "prd";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function isDev() {
|
|
72
|
-
return getEnvironment() === "dev";
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
module.exports = {
|
|
76
|
-
ensureAndGet,
|
|
77
|
-
getEnvOrThrow,
|
|
78
|
-
getAWSAccessKeyId,
|
|
79
|
-
getAWSSecretAccessKey,
|
|
80
|
-
getAWSRegion,
|
|
81
|
-
getEnvironment,
|
|
82
|
-
isProduction,
|
|
83
|
-
isDev,
|
|
84
|
-
getEtherScanApiKey,
|
|
85
|
-
getBscScanApiKey,
|
|
86
|
-
getPolygonScanApiKey,
|
|
87
|
-
getGetBlockApiKey,
|
|
88
|
-
getAlchemyApiKey,
|
|
89
|
-
getNodeRealApiKey,
|
|
90
|
-
};
|
|
1
|
+
function getAWSAccessKeyId() {
|
|
2
|
+
return ensureAndGet(["SKYNET_AWS_ACCESS_KEY_ID"], undefined);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function getAWSSecretAccessKey() {
|
|
6
|
+
return ensureAndGet(["SKYNET_AWS_SECRET_ACCESS_KEY"], undefined);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getAWSRegion() {
|
|
10
|
+
return ensureAndGet(["SKYNET_AWS_REGION"], "us-east-1");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getEnvironment() {
|
|
14
|
+
return ensureAndGet("SKYNET_ENVIRONMENT", "dev");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getEtherScanApiKey() {
|
|
18
|
+
return ensureAndGet("SKYNET_ETHER_SCAN_API_KEY");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getBscScanApiKey() {
|
|
22
|
+
return ensureAndGet("SKYNET_BSC_SCAN_API_KEY");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getPolygonScanApiKey() {
|
|
26
|
+
return ensureAndGet("SKYNET_POLYGON_SCAN_API_KEY");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getGetBlockApiKey() {
|
|
30
|
+
return ensureAndGet("SKYNET_GETBLOCK_API_KEY");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getAlchemyApiKey(identifier) {
|
|
34
|
+
// Alchemy API keys are different for each alchemy app
|
|
35
|
+
return ensureAndGet(`SKYNET_ALCHEMY_API_${identifier.toUpperCase()}_KEY`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getNodeRealApiKey(identifier) {
|
|
39
|
+
// NodeReal API keys are different for each NodeReal app
|
|
40
|
+
return ensureAndGet(`SKYNET_NODEREAL_API_${identifier.toUpperCase()}_KEY`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ensureAndGet(envName, defaultValue) {
|
|
44
|
+
if (Array.isArray(envName)) {
|
|
45
|
+
for (let name of envName) {
|
|
46
|
+
if (process.env[name]) {
|
|
47
|
+
return process.env[name];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return defaultValue;
|
|
51
|
+
} else {
|
|
52
|
+
if (process.env[envName]) {
|
|
53
|
+
return process.env[envName];
|
|
54
|
+
}
|
|
55
|
+
return defaultValue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getEnvOrThrow(envName) {
|
|
60
|
+
if (!process.env[envName]) {
|
|
61
|
+
throw new Error(`Must set environment variable ${envName}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return process.env[envName];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isProduction() {
|
|
68
|
+
return getEnvironment() === "prd";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isDev() {
|
|
72
|
+
return getEnvironment() === "dev";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = {
|
|
76
|
+
ensureAndGet,
|
|
77
|
+
getEnvOrThrow,
|
|
78
|
+
getAWSAccessKeyId,
|
|
79
|
+
getAWSSecretAccessKey,
|
|
80
|
+
getAWSRegion,
|
|
81
|
+
getEnvironment,
|
|
82
|
+
isProduction,
|
|
83
|
+
isDev,
|
|
84
|
+
getEtherScanApiKey,
|
|
85
|
+
getBscScanApiKey,
|
|
86
|
+
getPolygonScanApiKey,
|
|
87
|
+
getGetBlockApiKey,
|
|
88
|
+
getAlchemyApiKey,
|
|
89
|
+
getNodeRealApiKey,
|
|
90
|
+
};
|
package/examples/api
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// this file is executable and is for kafka producer testing
|
|
4
|
-
// a few test commands to try on
|
|
5
|
-
// $ examples/api run --verbose
|
|
6
|
-
// $ examples/api run
|
|
7
|
-
// $ examples/api check
|
|
8
|
-
// $ examples/api deploy
|
|
9
|
-
// $ examples/api --help
|
|
10
|
-
|
|
11
|
-
const { api, every, SENSITIVE_VALUE, ERROR_LEVEL } = require("../app");
|
|
12
|
-
|
|
13
|
-
// an example middleware
|
|
14
|
-
async function logRequest(req, res, next) {
|
|
15
|
-
const start = new Date();
|
|
16
|
-
next();
|
|
17
|
-
const end = new Date();
|
|
18
|
-
const logInfo = { start, end, elapsed: `${end - start}ms` };
|
|
19
|
-
console.log(logInfo);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function getProjectsHandler({ req, res, verbose }) {
|
|
23
|
-
console.log("receieved call", req.query, verbose);
|
|
24
|
-
|
|
25
|
-
const type = req.query.type;
|
|
26
|
-
|
|
27
|
-
if (!type) {
|
|
28
|
-
res.status(400).end("must provide type parameter");
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
res.json([{ id: "proj-1", name: "Test Project 1" }]);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function createProjectHandler({ req, res, verbose }) {
|
|
36
|
-
console.log("receieved call", req.body, verbose);
|
|
37
|
-
|
|
38
|
-
res.json({ success: true });
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const app = api({
|
|
42
|
-
name: "example-api",
|
|
43
|
-
|
|
44
|
-
env: {
|
|
45
|
-
EXAMPLE_API_KEY: SENSITIVE_VALUE,
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
routes: [
|
|
49
|
-
{
|
|
50
|
-
method: "GET",
|
|
51
|
-
path: "/projects",
|
|
52
|
-
handler: getProjectsHandler,
|
|
53
|
-
middlewares: [logRequest],
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
method: "POST",
|
|
57
|
-
path: "/projects",
|
|
58
|
-
handler: createProjectHandler,
|
|
59
|
-
protected: true,
|
|
60
|
-
middlewares: [logRequest],
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
|
|
64
|
-
serve: {
|
|
65
|
-
prefix: "/example-api", // deployed to a sub path
|
|
66
|
-
port: 12345,
|
|
67
|
-
apiKey: process.env.EXAMPLE_API_KEY,
|
|
68
|
-
cpu: 600,
|
|
69
|
-
mem: 200,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
app();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// this file is executable and is for kafka producer testing
|
|
4
|
+
// a few test commands to try on
|
|
5
|
+
// $ examples/api run --verbose
|
|
6
|
+
// $ examples/api run
|
|
7
|
+
// $ examples/api check
|
|
8
|
+
// $ examples/api deploy
|
|
9
|
+
// $ examples/api --help
|
|
10
|
+
|
|
11
|
+
const { api, every, SENSITIVE_VALUE, ERROR_LEVEL } = require("../app");
|
|
12
|
+
|
|
13
|
+
// an example middleware
|
|
14
|
+
async function logRequest(req, res, next) {
|
|
15
|
+
const start = new Date();
|
|
16
|
+
next();
|
|
17
|
+
const end = new Date();
|
|
18
|
+
const logInfo = { start, end, elapsed: `${end - start}ms` };
|
|
19
|
+
console.log(logInfo);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function getProjectsHandler({ req, res, verbose }) {
|
|
23
|
+
console.log("receieved call", req.query, verbose);
|
|
24
|
+
|
|
25
|
+
const type = req.query.type;
|
|
26
|
+
|
|
27
|
+
if (!type) {
|
|
28
|
+
res.status(400).end("must provide type parameter");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
res.json([{ id: "proj-1", name: "Test Project 1" }]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function createProjectHandler({ req, res, verbose }) {
|
|
36
|
+
console.log("receieved call", req.body, verbose);
|
|
37
|
+
|
|
38
|
+
res.json({ success: true });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const app = api({
|
|
42
|
+
name: "example-api",
|
|
43
|
+
|
|
44
|
+
env: {
|
|
45
|
+
EXAMPLE_API_KEY: SENSITIVE_VALUE,
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
routes: [
|
|
49
|
+
{
|
|
50
|
+
method: "GET",
|
|
51
|
+
path: "/projects",
|
|
52
|
+
handler: getProjectsHandler,
|
|
53
|
+
middlewares: [logRequest],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
method: "POST",
|
|
57
|
+
path: "/projects",
|
|
58
|
+
handler: createProjectHandler,
|
|
59
|
+
protected: true,
|
|
60
|
+
middlewares: [logRequest],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
|
|
64
|
+
serve: {
|
|
65
|
+
prefix: "/example-api", // deployed to a sub path
|
|
66
|
+
port: 12345,
|
|
67
|
+
apiKey: process.env.EXAMPLE_API_KEY,
|
|
68
|
+
cpu: 600,
|
|
69
|
+
mem: 200,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
app();
|
package/examples/consumer
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// this file is executable and is for kafka producer testing
|
|
4
|
-
// a few test commands to try on
|
|
5
|
-
// $ examples/consumer run --protocol bsc --verbose
|
|
6
|
-
// $ examples/consumer run --protocol eth
|
|
7
|
-
// $ examples/consumer check --protocol eth
|
|
8
|
-
// $ examples/consumer deploy --protocol eth
|
|
9
|
-
// $ examples/consumer --help
|
|
10
|
-
|
|
11
|
-
const { consumer, every, ERROR_LEVEL } = require("../app");
|
|
12
|
-
|
|
13
|
-
async function consume({ protocol, messages, verbose }) {
|
|
14
|
-
console.log("consume called with", protocol, messages, verbose);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function check({ protocol, state, verbose }) {
|
|
18
|
-
console.log("check called with", protocol, state, verbose);
|
|
19
|
-
|
|
20
|
-
const errors = [];
|
|
21
|
-
|
|
22
|
-
errors.push({ type: ERROR_LEVEL.CRITICAL, message: "processed height lagged behind" });
|
|
23
|
-
|
|
24
|
-
return errors;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const app = consumer({
|
|
28
|
-
name: "example-consumer",
|
|
29
|
-
selector: { protocol: { type: "string", description: "from which chain to consume data" } },
|
|
30
|
-
|
|
31
|
-
consume: {
|
|
32
|
-
func: consume,
|
|
33
|
-
topic: ({ protocol }) => `lib-skynet-test-kafka-${protocol}-dev`,
|
|
34
|
-
maxRetry: 1,
|
|
35
|
-
|
|
36
|
-
cpu: 600,
|
|
37
|
-
mem: 200,
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
check: {
|
|
41
|
-
func: check,
|
|
42
|
-
schedule: every(1).minute,
|
|
43
|
-
slackChannel: "skynet-notifications-local-dev",
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
app();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// this file is executable and is for kafka producer testing
|
|
4
|
+
// a few test commands to try on
|
|
5
|
+
// $ examples/consumer run --protocol bsc --verbose
|
|
6
|
+
// $ examples/consumer run --protocol eth
|
|
7
|
+
// $ examples/consumer check --protocol eth
|
|
8
|
+
// $ examples/consumer deploy --protocol eth
|
|
9
|
+
// $ examples/consumer --help
|
|
10
|
+
|
|
11
|
+
const { consumer, every, ERROR_LEVEL } = require("../app");
|
|
12
|
+
|
|
13
|
+
async function consume({ protocol, messages, verbose }) {
|
|
14
|
+
console.log("consume called with", protocol, messages, verbose);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function check({ protocol, state, verbose }) {
|
|
18
|
+
console.log("check called with", protocol, state, verbose);
|
|
19
|
+
|
|
20
|
+
const errors = [];
|
|
21
|
+
|
|
22
|
+
errors.push({ type: ERROR_LEVEL.CRITICAL, message: "processed height lagged behind" });
|
|
23
|
+
|
|
24
|
+
return errors;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const app = consumer({
|
|
28
|
+
name: "example-consumer",
|
|
29
|
+
selector: { protocol: { type: "string", description: "from which chain to consume data" } },
|
|
30
|
+
|
|
31
|
+
consume: {
|
|
32
|
+
func: consume,
|
|
33
|
+
topic: ({ protocol }) => `lib-skynet-test-kafka-${protocol}-dev`,
|
|
34
|
+
maxRetry: 1,
|
|
35
|
+
|
|
36
|
+
cpu: 600,
|
|
37
|
+
mem: 200,
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
check: {
|
|
41
|
+
func: check,
|
|
42
|
+
schedule: every(1).minute,
|
|
43
|
+
slackChannel: "skynet-notifications-local-dev",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
app();
|
package/examples/indexer
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// this file is executable and is for kafka producer testing
|
|
4
|
-
// a few test commands to try on
|
|
5
|
-
// $ examples/indexer run --protocol bsc --verbose
|
|
6
|
-
// $ examples/indexer run --protocol eth
|
|
7
|
-
// $ examples/indexer check --protocol eth
|
|
8
|
-
// $ examples/indexer deploy --protocol eth
|
|
9
|
-
// $ examples/indexer --help
|
|
10
|
-
|
|
11
|
-
const { indexer, every, ERROR_LEVEL } = require("../app");
|
|
12
|
-
|
|
13
|
-
async function build({ protocol, verbose }) {
|
|
14
|
-
console.log("build called with", protocol, verbose);
|
|
15
|
-
|
|
16
|
-
if (protocol === "eth") {
|
|
17
|
-
throw new Error("use eth to test error handling");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function check({ protocol, state, verbose }) {
|
|
22
|
-
console.log("check called with", protocol, state, verbose);
|
|
23
|
-
|
|
24
|
-
// latestId
|
|
25
|
-
// latestIdOnChain
|
|
26
|
-
|
|
27
|
-
const errors = [];
|
|
28
|
-
|
|
29
|
-
errors.push({
|
|
30
|
-
type: ERROR_LEVEL.WARNING,
|
|
31
|
-
message: "processed *height* lagged behind", // can be markdown
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return errors;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const app = indexer({
|
|
38
|
-
name: "example-indexer",
|
|
39
|
-
|
|
40
|
-
selector: {
|
|
41
|
-
// for more flags check meow documentation at https://github.com/sindresorhus/meow
|
|
42
|
-
protocol: {
|
|
43
|
-
type: "string",
|
|
44
|
-
description: "which chain to index"
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
env: {},
|
|
49
|
-
|
|
50
|
-
build: {
|
|
51
|
-
func: build,
|
|
52
|
-
schedule: every(1).minute,
|
|
53
|
-
cpu: 600,
|
|
54
|
-
mem: 200,
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
check: {
|
|
58
|
-
func: check,
|
|
59
|
-
schedule: every(2).minutes,
|
|
60
|
-
maxRetry: 0,
|
|
61
|
-
slackChannel: "skynet-notifications-local-dev",
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
app();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// this file is executable and is for kafka producer testing
|
|
4
|
+
// a few test commands to try on
|
|
5
|
+
// $ examples/indexer run --protocol bsc --verbose
|
|
6
|
+
// $ examples/indexer run --protocol eth
|
|
7
|
+
// $ examples/indexer check --protocol eth
|
|
8
|
+
// $ examples/indexer deploy --protocol eth
|
|
9
|
+
// $ examples/indexer --help
|
|
10
|
+
|
|
11
|
+
const { indexer, every, ERROR_LEVEL } = require("../app");
|
|
12
|
+
|
|
13
|
+
async function build({ protocol, verbose }) {
|
|
14
|
+
console.log("build called with", protocol, verbose);
|
|
15
|
+
|
|
16
|
+
if (protocol === "eth") {
|
|
17
|
+
throw new Error("use eth to test error handling");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function check({ protocol, state, verbose }) {
|
|
22
|
+
console.log("check called with", protocol, state, verbose);
|
|
23
|
+
|
|
24
|
+
// latestId
|
|
25
|
+
// latestIdOnChain
|
|
26
|
+
|
|
27
|
+
const errors = [];
|
|
28
|
+
|
|
29
|
+
errors.push({
|
|
30
|
+
type: ERROR_LEVEL.WARNING,
|
|
31
|
+
message: "processed *height* lagged behind", // can be markdown
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return errors;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const app = indexer({
|
|
38
|
+
name: "example-indexer",
|
|
39
|
+
|
|
40
|
+
selector: {
|
|
41
|
+
// for more flags check meow documentation at https://github.com/sindresorhus/meow
|
|
42
|
+
protocol: {
|
|
43
|
+
type: "string",
|
|
44
|
+
description: "which chain to index"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
env: {},
|
|
49
|
+
|
|
50
|
+
build: {
|
|
51
|
+
func: build,
|
|
52
|
+
schedule: every(1).minute,
|
|
53
|
+
cpu: 600,
|
|
54
|
+
mem: 200,
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
check: {
|
|
58
|
+
func: check,
|
|
59
|
+
schedule: every(2).minutes,
|
|
60
|
+
maxRetry: 0,
|
|
61
|
+
slackChannel: "skynet-notifications-local-dev",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
app();
|