@certik/skynet 0.7.10 → 0.7.14
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 +6 -0
- package/.eslintrc.js +13 -13
- package/CHANGELOG.md +18 -0
- package/README.md +23 -23
- package/abi.js +227 -227
- package/address.js +18 -18
- package/block.js +83 -83
- package/dynamodb.js +456 -456
- package/examples/deploy-consumer +0 -0
- package/examples/deploy-indexer +0 -0
- package/examples/deploy-mode-indexer +0 -0
- package/examples/deploy-producer +0 -0
- package/examples/indexer +0 -0
- package/examples/kafka-consumer +0 -0
- package/examples/kafka-producer +1 -1
- package/examples/mode-indexer +0 -0
- package/inquiry.js +14 -14
- package/kafka.js +129 -113
- package/labelling.js +40 -4
- package/metric.js +65 -65
- package/package.json +2 -2
- package/price.js +48 -48
- package/primitive.js +77 -77
- package/rateLimit.js +21 -21
- package/s3.js +93 -93
- package/scan.js +67 -67
- package/sqs.js +12 -12
- package/token.js +44 -44
- package/transaction.js +47 -47
- package/util.js +58 -58
package/block.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
const { getEnvironment } = require("./env");
|
|
2
|
-
const { PROTOCOLS } = require("./const");
|
|
3
|
-
const { readFile } = require("./s3");
|
|
4
|
-
const { getRecordByKey } = require("./dynamodb");
|
|
5
|
-
const fetch = require("node-fetch");
|
|
6
|
-
const Web3 = require("web3");
|
|
7
|
-
|
|
8
|
-
const S3_BUCKET_NAME =
|
|
9
|
-
getEnvironment() === "prd" ? "certik-skynet" : "certik-skynet-dev";
|
|
10
|
-
const INDEXER_STATE_TABLE = `skynet-${getEnvironment()}-indexer-state`;
|
|
11
|
-
|
|
12
|
-
function leftPad3(num) {
|
|
13
|
-
if (num === 0) {
|
|
14
|
-
return "000";
|
|
15
|
-
} else if (num < 10) {
|
|
16
|
-
return "00" + String(num);
|
|
17
|
-
} else if (num < 100) {
|
|
18
|
-
return "0" + String(num);
|
|
19
|
-
} else {
|
|
20
|
-
return String(num);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getBlockS3Path(protocol, height) {
|
|
25
|
-
return `chaindata/${protocol}/${Math.floor(height / 1_000_000)}/${leftPad3(
|
|
26
|
-
Math.floor(height / 1_000) % 1000
|
|
27
|
-
)}/${leftPad3(height % 1000)}.json`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// We use this function instead of web3 because the gas limits on bsc exceed
|
|
31
|
-
// the size supported by javascript numbers, and web3 does not support this
|
|
32
|
-
async function getBlock(protocol, height) {
|
|
33
|
-
const body = {
|
|
34
|
-
jsonrpc: "2.0",
|
|
35
|
-
method: "eth_getBlockByNumber",
|
|
36
|
-
params: [`0x${height.toString(16)}`, true],
|
|
37
|
-
id: 1
|
|
38
|
-
};
|
|
39
|
-
const response = await fetch(PROTOCOLS[protocol].endpoint, {
|
|
40
|
-
method: "POST",
|
|
41
|
-
headers: {
|
|
42
|
-
"Content-Type": "application/json"
|
|
43
|
-
},
|
|
44
|
-
body: JSON.stringify(body)
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const { result: block } = await response.json();
|
|
48
|
-
|
|
49
|
-
return block;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function getLatestBlockHeight(protocol) {
|
|
53
|
-
const web3 = new Web3(PROTOCOLS[protocol].endpoint);
|
|
54
|
-
const isSyncing = await web3.eth.isSyncing();
|
|
55
|
-
|
|
56
|
-
if (isSyncing) {
|
|
57
|
-
return isSyncing.currentBlock;
|
|
58
|
-
} else {
|
|
59
|
-
const latestBlock = await web3.eth.getBlock("latest");
|
|
60
|
-
|
|
61
|
-
return latestBlock.number;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function getLatestS3BlockHeight(protocol) {
|
|
66
|
-
const name = `AMLBlockIndexerSince(protocol=${protocol})`;
|
|
67
|
-
const { value: height } = await getRecordByKey(INDEXER_STATE_TABLE, { name });
|
|
68
|
-
return height;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function getBlockFromS3(protocol, height) {
|
|
72
|
-
const body = await readFile(S3_BUCKET_NAME, getBlockS3Path(protocol, height));
|
|
73
|
-
|
|
74
|
-
return JSON.parse(body);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = {
|
|
78
|
-
getLatestBlockHeight,
|
|
79
|
-
getBlock,
|
|
80
|
-
getBlockS3Path,
|
|
81
|
-
getLatestS3BlockHeight,
|
|
82
|
-
getBlockFromS3
|
|
83
|
-
};
|
|
1
|
+
const { getEnvironment } = require("./env");
|
|
2
|
+
const { PROTOCOLS } = require("./const");
|
|
3
|
+
const { readFile } = require("./s3");
|
|
4
|
+
const { getRecordByKey } = require("./dynamodb");
|
|
5
|
+
const fetch = require("node-fetch");
|
|
6
|
+
const Web3 = require("web3");
|
|
7
|
+
|
|
8
|
+
const S3_BUCKET_NAME =
|
|
9
|
+
getEnvironment() === "prd" ? "certik-skynet" : "certik-skynet-dev";
|
|
10
|
+
const INDEXER_STATE_TABLE = `skynet-${getEnvironment()}-indexer-state`;
|
|
11
|
+
|
|
12
|
+
function leftPad3(num) {
|
|
13
|
+
if (num === 0) {
|
|
14
|
+
return "000";
|
|
15
|
+
} else if (num < 10) {
|
|
16
|
+
return "00" + String(num);
|
|
17
|
+
} else if (num < 100) {
|
|
18
|
+
return "0" + String(num);
|
|
19
|
+
} else {
|
|
20
|
+
return String(num);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getBlockS3Path(protocol, height) {
|
|
25
|
+
return `chaindata/${protocol}/${Math.floor(height / 1_000_000)}/${leftPad3(
|
|
26
|
+
Math.floor(height / 1_000) % 1000
|
|
27
|
+
)}/${leftPad3(height % 1000)}.json`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// We use this function instead of web3 because the gas limits on bsc exceed
|
|
31
|
+
// the size supported by javascript numbers, and web3 does not support this
|
|
32
|
+
async function getBlock(protocol, height) {
|
|
33
|
+
const body = {
|
|
34
|
+
jsonrpc: "2.0",
|
|
35
|
+
method: "eth_getBlockByNumber",
|
|
36
|
+
params: [`0x${height.toString(16)}`, true],
|
|
37
|
+
id: 1
|
|
38
|
+
};
|
|
39
|
+
const response = await fetch(PROTOCOLS[protocol].endpoint, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json"
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify(body)
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const { result: block } = await response.json();
|
|
48
|
+
|
|
49
|
+
return block;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function getLatestBlockHeight(protocol) {
|
|
53
|
+
const web3 = new Web3(PROTOCOLS[protocol].endpoint);
|
|
54
|
+
const isSyncing = await web3.eth.isSyncing();
|
|
55
|
+
|
|
56
|
+
if (isSyncing) {
|
|
57
|
+
return isSyncing.currentBlock;
|
|
58
|
+
} else {
|
|
59
|
+
const latestBlock = await web3.eth.getBlock("latest");
|
|
60
|
+
|
|
61
|
+
return latestBlock.number;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function getLatestS3BlockHeight(protocol) {
|
|
66
|
+
const name = `AMLBlockIndexerSince(protocol=${protocol})`;
|
|
67
|
+
const { value: height } = await getRecordByKey(INDEXER_STATE_TABLE, { name });
|
|
68
|
+
return height;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function getBlockFromS3(protocol, height) {
|
|
72
|
+
const body = await readFile(S3_BUCKET_NAME, getBlockS3Path(protocol, height));
|
|
73
|
+
|
|
74
|
+
return JSON.parse(body);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = {
|
|
78
|
+
getLatestBlockHeight,
|
|
79
|
+
getBlock,
|
|
80
|
+
getBlockS3Path,
|
|
81
|
+
getLatestS3BlockHeight,
|
|
82
|
+
getBlockFromS3
|
|
83
|
+
};
|