@socket.tech/dl-common 1.0.3-test.1 → 1.0.3-test.3
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.
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Contract, Event, EventFilter, providers } from "ethers";
|
|
2
|
+
import { StaticJsonRpcProvider } from "@ethersproject/providers";
|
|
3
|
+
export declare const getEvents: (contract: Contract, filter: EventFilter | string, fromBlock: number, toBlock: number, eventBlockRange?: number) => Promise<Event[]>;
|
|
4
|
+
export declare const getLogs: (provider: StaticJsonRpcProvider, address: string[], topics: string[], fromBlock: number, toBlock: number, eventBlockRange?: number) => Promise<providers.Log[]>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogs = exports.getEvents = void 0;
|
|
4
|
+
const getEvents = async (contract, filter, fromBlock, toBlock, eventBlockRange = 5000) => {
|
|
5
|
+
const allEvents = [];
|
|
6
|
+
try {
|
|
7
|
+
let from = fromBlock;
|
|
8
|
+
let to = from + eventBlockRange - 1;
|
|
9
|
+
to = to < toBlock ? to : toBlock;
|
|
10
|
+
while (from <= toBlock) {
|
|
11
|
+
const events = await contract.queryFilter(filter, from, to);
|
|
12
|
+
allEvents.push(...events);
|
|
13
|
+
from = to + 1;
|
|
14
|
+
to = from + eventBlockRange - 1;
|
|
15
|
+
to = to < toBlock ? to : toBlock;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
return allEvents;
|
|
22
|
+
};
|
|
23
|
+
exports.getEvents = getEvents;
|
|
24
|
+
const getLogs = async (provider, address, topics, fromBlock, toBlock, eventBlockRange = 5000) => {
|
|
25
|
+
const allLogs = [];
|
|
26
|
+
try {
|
|
27
|
+
let from = fromBlock;
|
|
28
|
+
let to = from + eventBlockRange - 1;
|
|
29
|
+
to = to < toBlock ? to : toBlock;
|
|
30
|
+
while (from <= toBlock) {
|
|
31
|
+
const logs = await provider.send("eth_getLogs", [
|
|
32
|
+
{
|
|
33
|
+
address,
|
|
34
|
+
topics,
|
|
35
|
+
fromBlock: `0x${from.toString(16)}`,
|
|
36
|
+
toBlock: `0x${to.toString(16)}`,
|
|
37
|
+
},
|
|
38
|
+
]);
|
|
39
|
+
allLogs.push(...logs);
|
|
40
|
+
from = to + 1;
|
|
41
|
+
to = from + eventBlockRange - 1;
|
|
42
|
+
to = to < toBlock ? to : toBlock;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
return allLogs;
|
|
49
|
+
};
|
|
50
|
+
exports.getLogs = getLogs;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -23,3 +23,5 @@ __exportStar(require("./dataStructHelper"), exports);
|
|
|
23
23
|
__exportStar(require("./extraUtils"), exports);
|
|
24
24
|
__exportStar(require("./time"), exports);
|
|
25
25
|
__exportStar(require("./ethersAwsKmsSigner"), exports);
|
|
26
|
+
__exportStar(require("./secretManagerService"), exports);
|
|
27
|
+
__exportStar(require("./eventGetter"), exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSecret = exports.getAllSecrets = void 0;
|
|
4
|
+
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
|
|
5
|
+
const defaultRegion = "us-east-1";
|
|
6
|
+
const getAllSecrets = async (secretName, region = defaultRegion) => {
|
|
7
|
+
try {
|
|
8
|
+
const client = new client_secrets_manager_1.SecretsManagerClient({
|
|
9
|
+
region,
|
|
10
|
+
});
|
|
11
|
+
let response = await client.send(new client_secrets_manager_1.GetSecretValueCommand({
|
|
12
|
+
SecretId: secretName,
|
|
13
|
+
VersionStage: "AWSCURRENT", // VersionStage defaults to AWSCURRENT if unspecified
|
|
14
|
+
}));
|
|
15
|
+
if (!(response === null || response === void 0 ? void 0 : response.SecretString))
|
|
16
|
+
throw new Error("No secret found");
|
|
17
|
+
return JSON.parse(response.SecretString);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.getAllSecrets = getAllSecrets;
|
|
24
|
+
const getSecret = async (secretName, secretKey, region = defaultRegion) => {
|
|
25
|
+
try {
|
|
26
|
+
let secrets = await (0, exports.getAllSecrets)(secretName, region);
|
|
27
|
+
return secrets === null || secrets === void 0 ? void 0 : secrets[secretKey];
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.getSecret = getSecret;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socket.tech/dl-common",
|
|
3
|
-
"version": "1.0.3-test.
|
|
3
|
+
"version": "1.0.3-test.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"description": "common utilities for socket data layer.",
|
|
@@ -30,11 +30,14 @@
|
|
|
30
30
|
"prettier:fix": "npx prettier src dl-common --write ./**/*.{ts,js,json,yml,md}",
|
|
31
31
|
"format": "prettier \"./**\" --write --ignore-unknown",
|
|
32
32
|
"format:check": "prettier \"./**\" --ignore-unknown --check",
|
|
33
|
-
"prepare": "husky install"
|
|
33
|
+
"prepare": "husky install",
|
|
34
|
+
"publishp": "yarn lint && yarn build"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
37
|
+
"@aws-sdk/client-secrets-manager": "^3.433.0",
|
|
36
38
|
"@aws-sdk/client-sqs": "^3.421.0",
|
|
37
39
|
"@aws-sdk/smithy-client": "^3.329.0",
|
|
40
|
+
"@ethersproject/providers": "^5.7.2",
|
|
38
41
|
"@socket.tech/dl-core": "2.4.8-test.1",
|
|
39
42
|
"@socket.tech/ll-common": "^0.0.19",
|
|
40
43
|
"async-redis": "^2.0.0",
|