@dashevo/dapi-client 0.25.0-dev.31 → 0.25.0-dev.33
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/lib/DAPIClient.js
CHANGED
|
@@ -14,6 +14,8 @@ const createJsonTransportError = require('./transport/JsonRpcTransport/createJso
|
|
|
14
14
|
const BlockHeadersProvider = require('./BlockHeadersProvider/BlockHeadersProvider');
|
|
15
15
|
const createBlockHeadersProviderFromOptions = require('./BlockHeadersProvider/createBlockHeadersProviderFromOptions');
|
|
16
16
|
|
|
17
|
+
const logger = require('./logger');
|
|
18
|
+
|
|
17
19
|
const EVENTS = {
|
|
18
20
|
ERROR: 'error',
|
|
19
21
|
};
|
|
@@ -30,6 +32,9 @@ class DAPIClient extends EventEmitter {
|
|
|
30
32
|
timeout: 10000,
|
|
31
33
|
retries: 5,
|
|
32
34
|
blockHeadersProviderOptions: BlockHeadersProvider.defaultOptions,
|
|
35
|
+
loggerOptions: {
|
|
36
|
+
identifier: '',
|
|
37
|
+
},
|
|
33
38
|
...options,
|
|
34
39
|
};
|
|
35
40
|
|
|
@@ -52,6 +57,7 @@ class DAPIClient extends EventEmitter {
|
|
|
52
57
|
|
|
53
58
|
this.core = new CoreMethodsFacade(jsonRpcTransport, grpcTransport);
|
|
54
59
|
this.platform = new PlatformMethodsFacade(grpcTransport);
|
|
60
|
+
this.logger = logger.getForId(this.options.loggerOptions.identifier);
|
|
55
61
|
|
|
56
62
|
this.initBlockHeadersProvider();
|
|
57
63
|
}
|
|
@@ -81,6 +87,8 @@ DAPIClient.EVENTS = EVENTS;
|
|
|
81
87
|
* @property {number} [retries=3]
|
|
82
88
|
* @property {number} [baseBanTime=60000]
|
|
83
89
|
* @property {boolean} [throwDeadlineExceeded]
|
|
90
|
+
* @property {object} [loggerOptions]
|
|
91
|
+
* @property {string} [loggerOptions.identifier]
|
|
84
92
|
* @property {BlockHeadersProvider} [blockHeadersProvider]
|
|
85
93
|
* @property {BlockHeadersProviderOptions} [blockHeadersProviderOptions]
|
|
86
94
|
*/
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const util = require('util');
|
|
2
|
+
const winston = require('winston');
|
|
3
|
+
|
|
4
|
+
const LOG_LEVEL = process.env.LOG_LEVEL || 'info';
|
|
5
|
+
const LOG_TO_FILE = process.env.LOG_WALLET_TO_FILE || 'false';
|
|
6
|
+
|
|
7
|
+
// Log levels:
|
|
8
|
+
// error 0
|
|
9
|
+
// warn 1
|
|
10
|
+
// info 2 (default)
|
|
11
|
+
// verbose 3
|
|
12
|
+
// debug 4
|
|
13
|
+
// silly 5
|
|
14
|
+
|
|
15
|
+
const loggers = {};
|
|
16
|
+
|
|
17
|
+
const createLogger = (formats = [], id = '') => {
|
|
18
|
+
const format = winston.format.combine(
|
|
19
|
+
{
|
|
20
|
+
transform: (info) => {
|
|
21
|
+
const args = info[Symbol.for('splat')];
|
|
22
|
+
const result = { ...info };
|
|
23
|
+
if (args) {
|
|
24
|
+
result.message = util.format(info.message, ...args);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
...formats,
|
|
30
|
+
winston.format.colorize(),
|
|
31
|
+
winston.format.printf(({
|
|
32
|
+
level, message,
|
|
33
|
+
}) => `${level}: ${message}`),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const transports = [
|
|
37
|
+
new winston.transports.Console({
|
|
38
|
+
format,
|
|
39
|
+
}),
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
if (LOG_TO_FILE === 'true' && typeof window === 'undefined') {
|
|
43
|
+
transports.push(
|
|
44
|
+
new winston.transports.File({
|
|
45
|
+
filename: `wallet${id !== '' ? `_${id}` : ''}`,
|
|
46
|
+
format,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return winston.createLogger({
|
|
52
|
+
level: LOG_LEVEL,
|
|
53
|
+
transports,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const logger = createLogger();
|
|
58
|
+
|
|
59
|
+
logger.getForId = (id) => {
|
|
60
|
+
if (!loggers[id]) {
|
|
61
|
+
const format = {
|
|
62
|
+
transform: (info) => {
|
|
63
|
+
const message = `[DAPIClient: ${id}] ${info.message}`;
|
|
64
|
+
return { ...info, message };
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
loggers[id] = createLogger([format], id);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return loggers[id];
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
logger.verbose(`Logger uses "${LOG_LEVEL}" level`, { level: LOG_LEVEL });
|
|
75
|
+
|
|
76
|
+
module.exports = logger;
|
package/lib/test/bootstrap.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const logger = require('../../logger');
|
|
2
|
+
|
|
1
3
|
const MaxRetriesReachedError = require('../errors/response/MaxRetriesReachedError');
|
|
2
4
|
const NoAvailableAddressesForRetryError = require('../errors/response/NoAvailableAddressesForRetryError');
|
|
3
5
|
const NoAvailableAddressesError = require('../errors/NoAvailableAddressesError');
|
|
@@ -27,6 +29,7 @@ class GrpcTransport {
|
|
|
27
29
|
this.globalOptions = globalOptions;
|
|
28
30
|
|
|
29
31
|
this.lastUsedAddress = null;
|
|
32
|
+
this.logger = logger.getForId(globalOptions.loggerOptions.identifier);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
/**
|
|
@@ -67,6 +70,8 @@ class GrpcTransport {
|
|
|
67
70
|
);
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
this.logger.debug(`GRPC Request ${method} to ${address.toString()}`, { options });
|
|
74
|
+
|
|
70
75
|
try {
|
|
71
76
|
const result = await client[method](requestMessage, {}, requestOptions);
|
|
72
77
|
|
|
@@ -78,6 +83,8 @@ class GrpcTransport {
|
|
|
78
83
|
} catch (error) {
|
|
79
84
|
this.lastUsedAddress = address;
|
|
80
85
|
|
|
86
|
+
this.logger.error(`GRPC Request ${method} to ${address.toString()} failed with error: ${error.message}`);
|
|
87
|
+
|
|
81
88
|
// for unknown errors
|
|
82
89
|
if (error.code === undefined) {
|
|
83
90
|
throw error;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const logger = require('../../logger');
|
|
2
|
+
|
|
1
3
|
const MaxRetriesReachedError = require('../errors/response/MaxRetriesReachedError');
|
|
2
4
|
const NoAvailableAddressesForRetryError = require('../errors/response/NoAvailableAddressesForRetryError');
|
|
3
5
|
const NoAvailableAddressesError = require('../errors/NoAvailableAddressesError');
|
|
@@ -29,6 +31,8 @@ class JsonRpcTransport {
|
|
|
29
31
|
|
|
30
32
|
this.createJsonTransportError = createJsonTransportError;
|
|
31
33
|
|
|
34
|
+
this.logger = logger.getForId(globalOptions.loggerOptions.identifier);
|
|
35
|
+
|
|
32
36
|
this.lastUsedAddress = null;
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -63,6 +67,8 @@ class JsonRpcTransport {
|
|
|
63
67
|
requestOptions.timeout = options.timeout;
|
|
64
68
|
}
|
|
65
69
|
|
|
70
|
+
this.logger.debug(`JSON-RPC Request ${method} to ${address.toString()}`, { options });
|
|
71
|
+
|
|
66
72
|
try {
|
|
67
73
|
const result = await this.requestJsonRpc(
|
|
68
74
|
address.getProtocol(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "0.25.0-dev.
|
|
3
|
+
"version": "0.25.0-dev.33",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,24 +26,26 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "0.25.0-dev.
|
|
30
|
-
"@dashevo/dash-spv": "0.25.0-dev.
|
|
29
|
+
"@dashevo/dapi-grpc": "0.25.0-dev.33",
|
|
30
|
+
"@dashevo/dash-spv": "0.25.0-dev.33",
|
|
31
31
|
"@dashevo/dashcore-lib": "~0.20.9",
|
|
32
|
-
"@dashevo/dpp": "0.25.0-dev.
|
|
33
|
-
"@dashevo/grpc-common": "0.25.0-dev.
|
|
34
|
-
"@dashevo/wasm-dpp": "0.25.0-dev.
|
|
32
|
+
"@dashevo/dpp": "0.25.0-dev.33",
|
|
33
|
+
"@dashevo/grpc-common": "0.25.0-dev.33",
|
|
34
|
+
"@dashevo/wasm-dpp": "0.25.0-dev.33",
|
|
35
35
|
"bs58": "^4.0.1",
|
|
36
36
|
"cbor": "^8.0.0",
|
|
37
37
|
"google-protobuf": "^3.12.2",
|
|
38
38
|
"lodash": "^4.17.21",
|
|
39
39
|
"node-fetch": "^2.6.7",
|
|
40
40
|
"node-inspect-extracted": "^1.0.8",
|
|
41
|
-
"wasm-x11-hash": "~0.0.2"
|
|
41
|
+
"wasm-x11-hash": "~0.0.2",
|
|
42
|
+
"winston": "^3.2.1"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@babel/core": "^7.15.5",
|
|
45
46
|
"assert-browserify": "^2.0.0",
|
|
46
47
|
"babel-loader": "^8.2.2",
|
|
48
|
+
"browserify-zlib": "^0.2.0",
|
|
47
49
|
"buffer": "^6.0.3",
|
|
48
50
|
"chai": "^4.3.9",
|
|
49
51
|
"chai-as-promised": "^7.1.1",
|
|
@@ -65,8 +67,10 @@
|
|
|
65
67
|
"karma-webpack": "^5.0.0",
|
|
66
68
|
"mocha": "^9.1.2",
|
|
67
69
|
"nyc": "^15.1.0",
|
|
70
|
+
"os-browserify": "^0.3.0",
|
|
68
71
|
"path-browserify": "^1.0.1",
|
|
69
72
|
"process": "^0.11.10",
|
|
73
|
+
"setimmediate": "^1.0.5",
|
|
70
74
|
"sinon": "^11.1.2",
|
|
71
75
|
"sinon-chai": "^3.7.0",
|
|
72
76
|
"stream-browserify": "^3.0.0",
|