@dashevo/dapi-client 0.25.0-dev.9 → 0.25.0
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/BlockHeadersProvider/BlockHeadersProvider.js +14 -16
- package/lib/DAPIClient.js +8 -0
- package/lib/logger/index.js +76 -0
- package/lib/methods/platform/PlatformMethodsFacade.js +2 -0
- package/lib/methods/platform/getDataContractHistory/GetDataContractHistoryResponse.js +55 -0
- package/lib/methods/platform/getDataContractHistory/getDataContractHistoryFactory.js +82 -0
- package/lib/methods/platform/getDocuments/GetDocumentsResponse.js +4 -1
- package/lib/methods/platform/getIdentitiesByPublicKeyHashes/GetIdentitiesByPublicKeyHashesResponse.js +4 -1
- package/lib/methods/platform/response/Proof.js +3 -3
- package/lib/methods/platform/waitForStateTransitionResult/waitForStateTransitionResultFactory.js +1 -1
- package/lib/networkConfigs.js +38 -129
- package/lib/test/bootstrap.js +1 -0
- package/lib/transport/GrpcTransport/GrpcTransport.js +7 -0
- package/lib/transport/GrpcTransport/errors/InternalServerError.js +2 -2
- package/lib/transport/JsonRpcTransport/JsonRpcTransport.js +6 -0
- package/lib/transport/JsonRpcTransport/requestJsonRpc.js +2 -3
- package/package.json +14 -10
- package/polyfills/fetch-polyfill.js +1 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
const EventEmitter = require('events');
|
|
2
|
-
const { configure: configureDashcore } = require('@dashevo/dashcore-lib');
|
|
3
|
-
const X11 = require('wasm-x11-hash');
|
|
4
2
|
const { SpvChain, SPVError } = require('@dashevo/dash-spv');
|
|
5
3
|
|
|
6
4
|
const BlockHeadersReader = require('./BlockHeadersReader');
|
|
@@ -51,7 +49,6 @@ class BlockHeadersProvider extends EventEmitter {
|
|
|
51
49
|
this.spvChain = new SpvChain(this.options.network, 100);
|
|
52
50
|
|
|
53
51
|
this.state = STATES.IDLE;
|
|
54
|
-
this.wasmX11Ready = false;
|
|
55
52
|
|
|
56
53
|
this.errorHandler = this.errorHandler.bind(this);
|
|
57
54
|
this.headersHandler = this.headersHandler.bind(this);
|
|
@@ -79,13 +76,7 @@ class BlockHeadersProvider extends EventEmitter {
|
|
|
79
76
|
* @private
|
|
80
77
|
*/
|
|
81
78
|
async init() {
|
|
82
|
-
|
|
83
|
-
const x11Hash = await X11();
|
|
84
|
-
configureDashcore({
|
|
85
|
-
x11hash: x11Hash,
|
|
86
|
-
});
|
|
87
|
-
this.wasmX11Ready = true;
|
|
88
|
-
}
|
|
79
|
+
await SpvChain.wasmX11Ready();
|
|
89
80
|
|
|
90
81
|
if (!this.blockHeadersReader) {
|
|
91
82
|
this.blockHeadersReader = new BlockHeadersReader(
|
|
@@ -113,12 +104,18 @@ class BlockHeadersProvider extends EventEmitter {
|
|
|
113
104
|
* Initializes SPV chain with a list of headers and a known lastSyncedHeaderHeight
|
|
114
105
|
*
|
|
115
106
|
* @param headers
|
|
116
|
-
* @param
|
|
107
|
+
* @param firstHeaderHeight
|
|
117
108
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
109
|
+
async initializeChainWith(headers, firstHeaderHeight) {
|
|
110
|
+
await SpvChain.wasmX11Ready();
|
|
111
|
+
|
|
112
|
+
if (headers.length === 0) {
|
|
113
|
+
// If there are no headers, initialize chain from genesis
|
|
114
|
+
this.spvChain.initialize();
|
|
115
|
+
} else {
|
|
116
|
+
this.spvChain.initialize(headers[0], firstHeaderHeight);
|
|
117
|
+
this.spvChain.addHeaders(headers);
|
|
118
|
+
}
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
/**
|
|
@@ -130,7 +127,8 @@ class BlockHeadersProvider extends EventEmitter {
|
|
|
130
127
|
ensureChainRoot(height) {
|
|
131
128
|
// Flush spv chain in case header at specified height was not found
|
|
132
129
|
if (!this.spvChain.hashesByHeight.has(height - 1)) {
|
|
133
|
-
this.spvChain.reset(
|
|
130
|
+
this.spvChain.reset();
|
|
131
|
+
this.spvChain.pendingStartBlockHeight = height;
|
|
134
132
|
}
|
|
135
133
|
}
|
|
136
134
|
|
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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const broadcastStateTransitionFactory = require('./broadcastStateTransition/broadcastStateTransitionFactory');
|
|
2
2
|
const getDataContractFactory = require('./getDataContract/getDataContractFactory');
|
|
3
|
+
const getDataContractHistoryFactory = require('./getDataContractHistory/getDataContractHistoryFactory');
|
|
3
4
|
const getDocumentsFactory = require('./getDocuments/getDocumentsFactory');
|
|
4
5
|
const getIdentityFactory = require('./getIdentity/getIdentityFactory');
|
|
5
6
|
const getIdentitiesByPublicKeyHashesFactory = require('./getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory');
|
|
@@ -13,6 +14,7 @@ class PlatformMethodsFacade {
|
|
|
13
14
|
constructor(grpcTransport) {
|
|
14
15
|
this.broadcastStateTransition = broadcastStateTransitionFactory(grpcTransport);
|
|
15
16
|
this.getDataContract = getDataContractFactory(grpcTransport);
|
|
17
|
+
this.getDataContractHistory = getDataContractHistoryFactory(grpcTransport);
|
|
16
18
|
this.getDocuments = getDocumentsFactory(grpcTransport);
|
|
17
19
|
this.getIdentity = getIdentityFactory(grpcTransport);
|
|
18
20
|
this.getIdentitiesByPublicKeyHashes = getIdentitiesByPublicKeyHashesFactory(grpcTransport);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
3
|
+
|
|
4
|
+
class GetDataContractHistoryResponse extends AbstractResponse {
|
|
5
|
+
/**
|
|
6
|
+
* @param {object.<number, Buffer>} dataContractHistory
|
|
7
|
+
* @param {Metadata} metadata
|
|
8
|
+
* @param {Proof} [proof]
|
|
9
|
+
*/
|
|
10
|
+
constructor(dataContractHistory, metadata, proof = undefined) {
|
|
11
|
+
super(metadata, proof);
|
|
12
|
+
|
|
13
|
+
this.dataContractHistory = dataContractHistory;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @returns {object.<number, Buffer>}
|
|
18
|
+
*/
|
|
19
|
+
getDataContractHistory() {
|
|
20
|
+
return this.dataContractHistory;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param proto
|
|
25
|
+
* @returns {GetDataContractHistoryResponse}
|
|
26
|
+
*/
|
|
27
|
+
static createFromProto(proto) {
|
|
28
|
+
// History is something that we need to call a method to get a list of entries on
|
|
29
|
+
const dataContractHistory = proto.getDataContractHistory();
|
|
30
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
31
|
+
|
|
32
|
+
if (!dataContractHistory && !proof) {
|
|
33
|
+
throw new InvalidResponseError('DataContract is not defined');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const history = {};
|
|
37
|
+
|
|
38
|
+
if (dataContractHistory) {
|
|
39
|
+
const dataContractHistoryEntries = dataContractHistory.getDataContractEntriesList();
|
|
40
|
+
|
|
41
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
42
|
+
for (const historyEntry of dataContractHistoryEntries) {
|
|
43
|
+
history[historyEntry.getDate()] = historyEntry.getValue();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new GetDataContractHistoryResponse(
|
|
48
|
+
history,
|
|
49
|
+
metadata,
|
|
50
|
+
proof,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = GetDataContractHistoryResponse;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetDataContractHistoryRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
|
|
8
|
+
const { UInt32Value } = require('google-protobuf/google/protobuf/wrappers_pb');
|
|
9
|
+
|
|
10
|
+
const GetDataContractHistoryResponse = require('./GetDataContractHistoryResponse');
|
|
11
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
12
|
+
/**
|
|
13
|
+
* @param {GrpcTransport} grpcTransport
|
|
14
|
+
* @returns {getDataContractHistory}
|
|
15
|
+
*/
|
|
16
|
+
function getDataContractHistoryFactory(grpcTransport) {
|
|
17
|
+
/**
|
|
18
|
+
* Fetch Data Contract by id
|
|
19
|
+
*
|
|
20
|
+
* @typedef {getDataContractHistory}
|
|
21
|
+
* @param {Buffer} contractId
|
|
22
|
+
* @param {number} [startAtMs]
|
|
23
|
+
* @param {number} [limit]
|
|
24
|
+
* @param {number} [offset]
|
|
25
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
26
|
+
* @returns {Promise<GetDataContractHistoryResponse>}
|
|
27
|
+
*/
|
|
28
|
+
async function getDataContractHistory(
|
|
29
|
+
contractId,
|
|
30
|
+
startAtMs = 0,
|
|
31
|
+
limit = 10,
|
|
32
|
+
offset = 0,
|
|
33
|
+
options = {},
|
|
34
|
+
) {
|
|
35
|
+
const getDataContractHistoryRequest = new GetDataContractHistoryRequest();
|
|
36
|
+
|
|
37
|
+
// need to convert objects inherited from Buffer to pure buffer as google protobuf
|
|
38
|
+
// doesn't support extended buffers
|
|
39
|
+
// https://github.com/protocolbuffers/protobuf/blob/master/js/binary/utils.js#L1049
|
|
40
|
+
if (Buffer.isBuffer(contractId)) {
|
|
41
|
+
// eslint-disable-next-line no-param-reassign
|
|
42
|
+
contractId = Buffer.from(contractId);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getDataContractHistoryRequest.setId(contractId);
|
|
46
|
+
getDataContractHistoryRequest.setStartAtMs(startAtMs);
|
|
47
|
+
getDataContractHistoryRequest.setLimit(new UInt32Value([limit]));
|
|
48
|
+
getDataContractHistoryRequest.setOffset(new UInt32Value([offset]));
|
|
49
|
+
getDataContractHistoryRequest.setProve(!!options.prove);
|
|
50
|
+
|
|
51
|
+
let lastError;
|
|
52
|
+
|
|
53
|
+
// TODO: simple retry before the dapi versioning is properly implemented
|
|
54
|
+
for (let i = 0; i < 3; i += 1) {
|
|
55
|
+
try {
|
|
56
|
+
// eslint-disable-next-line no-await-in-loop
|
|
57
|
+
const getDataContractHistoryResponse = await grpcTransport.request(
|
|
58
|
+
PlatformPromiseClient,
|
|
59
|
+
'getDataContractHistory',
|
|
60
|
+
getDataContractHistoryRequest,
|
|
61
|
+
options,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return GetDataContractHistoryResponse.createFromProto(getDataContractHistoryResponse);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (e instanceof InvalidResponseError) {
|
|
67
|
+
lastError = e;
|
|
68
|
+
} else {
|
|
69
|
+
throw e;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// If we made it past the cycle it means that the retry didn't work,
|
|
75
|
+
// and we're throwing the last error encountered
|
|
76
|
+
throw lastError;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return getDataContractHistory;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = getDataContractHistoryFactory;
|
|
@@ -26,8 +26,11 @@ class GetDocumentsResponse extends AbstractResponse {
|
|
|
26
26
|
static createFromProto(proto) {
|
|
27
27
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
28
28
|
|
|
29
|
+
const documents = proto.getDocuments();
|
|
30
|
+
|
|
29
31
|
return new GetDocumentsResponse(
|
|
30
|
-
|
|
32
|
+
documents !== undefined
|
|
33
|
+
? documents.getDocumentsList().map((document) => Buffer.from(document)) : [],
|
|
31
34
|
metadata,
|
|
32
35
|
proof,
|
|
33
36
|
);
|
|
@@ -26,8 +26,11 @@ class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
|
|
|
26
26
|
static createFromProto(proto) {
|
|
27
27
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
28
28
|
|
|
29
|
+
const identitiesList = proto.getIdentities();
|
|
30
|
+
|
|
29
31
|
return new GetIdentitiesByPublicKeyHashesResponse(
|
|
30
|
-
|
|
32
|
+
identitiesList !== undefined
|
|
33
|
+
? identitiesList.getIdentitiesList_asU8().map((identity) => Buffer.from(identity)) : [],
|
|
31
34
|
metadata,
|
|
32
35
|
proof,
|
|
33
36
|
);
|
|
@@ -16,7 +16,7 @@ class Proof {
|
|
|
16
16
|
/**
|
|
17
17
|
* @returns {Buffer}
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
getGrovedbProof() {
|
|
20
20
|
return this.merkleProof;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -43,13 +43,13 @@ class Proof {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {object} proofProto
|
|
47
47
|
*
|
|
48
48
|
* @returns {Proof}
|
|
49
49
|
*/
|
|
50
50
|
static createFromProto(proofProto) {
|
|
51
51
|
return new Proof({
|
|
52
|
-
merkleProof: Buffer.from(proofProto.
|
|
52
|
+
merkleProof: Buffer.from(proofProto.getGrovedbProof()),
|
|
53
53
|
quorumHash: Buffer.from(proofProto.getQuorumHash()),
|
|
54
54
|
signature: Buffer.from(proofProto.getSignature()),
|
|
55
55
|
round: proofProto.getRound(),
|
package/lib/networkConfigs.js
CHANGED
|
@@ -1,143 +1,52 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
testnet: {
|
|
3
3
|
seeds: [
|
|
4
|
-
'seed-1.testnet.networks.dash.org',
|
|
5
|
-
'seed-2.testnet.networks.dash.org',
|
|
6
|
-
'seed-3.testnet.networks.dash.org',
|
|
7
|
-
'seed-4.testnet.networks.dash.org',
|
|
8
|
-
'seed-5.testnet.networks.dash.org',
|
|
4
|
+
'seed-1.testnet.networks.dash.org:1443',
|
|
5
|
+
'seed-2.testnet.networks.dash.org:1443',
|
|
6
|
+
'seed-3.testnet.networks.dash.org:1443',
|
|
7
|
+
'seed-4.testnet.networks.dash.org:1443',
|
|
8
|
+
'seed-5.testnet.networks.dash.org:1443',
|
|
9
9
|
],
|
|
10
10
|
network: 'testnet',
|
|
11
11
|
// Since we don't have PoSe atm, 3rd party masternodes sometimes provide wrong data
|
|
12
12
|
// that breaks test suite and application logic. Temporary solution is to hardcode
|
|
13
13
|
// reliable DCG testnet masternodes to connect. Should be removed when PoSe is introduced.
|
|
14
14
|
dapiAddressesWhiteList: [
|
|
15
|
-
'34.
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'35.
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'54.
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'52.
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
43
|
-
'
|
|
44
|
-
'35.
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'54.186.161.236',
|
|
49
|
-
'52.13.63.7',
|
|
50
|
-
'18.236.233.225',
|
|
51
|
-
'54.191.138.72',
|
|
52
|
-
'54.191.59.75',
|
|
53
|
-
'18.237.160.84',
|
|
54
|
-
'54.218.236.193',
|
|
55
|
-
'54.148.178.140',
|
|
56
|
-
'35.161.168.136',
|
|
57
|
-
'35.161.33.22',
|
|
58
|
-
'35.160.130.44',
|
|
59
|
-
'34.212.104.247',
|
|
60
|
-
'52.13.29.83',
|
|
61
|
-
'54.149.39.172',
|
|
62
|
-
'35.89.93.255',
|
|
63
|
-
'35.85.46.137',
|
|
64
|
-
'54.188.154.252',
|
|
65
|
-
'54.218.11.172',
|
|
66
|
-
'54.186.47.235',
|
|
67
|
-
'54.244.145.48',
|
|
68
|
-
'18.236.232.153',
|
|
69
|
-
'34.220.226.135',
|
|
70
|
-
'34.220.30.59',
|
|
71
|
-
'18.237.160.97',
|
|
72
|
-
'18.236.146.99',
|
|
73
|
-
'35.88.169.18',
|
|
74
|
-
'35.164.17.198',
|
|
75
|
-
'54.218.80.158',
|
|
76
|
-
'34.220.102.107',
|
|
77
|
-
'35.165.60.113',
|
|
78
|
-
'34.215.234.63',
|
|
79
|
-
'35.89.146.226',
|
|
80
|
-
'35.89.86.26',
|
|
81
|
-
'35.88.160.231',
|
|
82
|
-
'54.245.8.155',
|
|
83
|
-
'52.36.221.94',
|
|
84
|
-
'52.35.46.188',
|
|
85
|
-
'34.221.153.67',
|
|
86
|
-
'54.212.153.15',
|
|
87
|
-
'35.85.55.192',
|
|
88
|
-
'35.89.105.90',
|
|
89
|
-
'52.24.22.52',
|
|
90
|
-
'54.212.33.96',
|
|
91
|
-
'52.10.19.238',
|
|
92
|
-
'35.160.190.165',
|
|
93
|
-
'34.219.3.61',
|
|
94
|
-
'54.187.32.187',
|
|
95
|
-
'35.162.221.77',
|
|
96
|
-
'35.91.64.183',
|
|
97
|
-
'18.236.189.15',
|
|
98
|
-
'35.91.145.195',
|
|
99
|
-
'54.186.251.30',
|
|
100
|
-
'54.245.9.46',
|
|
101
|
-
'35.91.48.128',
|
|
102
|
-
'54.244.75.85',
|
|
103
|
-
'34.221.159.53',
|
|
104
|
-
'35.89.88.166',
|
|
105
|
-
'54.185.249.165',
|
|
106
|
-
'54.245.9.209',
|
|
107
|
-
'34.222.167.162',
|
|
108
|
-
'54.191.88.232',
|
|
109
|
-
'54.191.111.112',
|
|
110
|
-
'18.237.146.37',
|
|
111
|
-
'35.89.148.27',
|
|
112
|
-
'35.91.8.48',
|
|
113
|
-
'18.236.208.138',
|
|
114
|
-
'54.213.60.60',
|
|
115
|
-
'35.92.151.94',
|
|
116
|
-
'18.237.241.37',
|
|
117
|
-
'54.202.209.229',
|
|
118
|
-
'34.221.9.70',
|
|
119
|
-
'35.89.38.62',
|
|
120
|
-
'54.218.81.193',
|
|
121
|
-
'34.221.158.21',
|
|
122
|
-
'35.88.97.57',
|
|
123
|
-
'54.68.247.40',
|
|
124
|
-
'35.88.168.176',
|
|
125
|
-
'35.89.202.171',
|
|
126
|
-
'34.220.106.205',
|
|
127
|
-
'34.210.86.23',
|
|
128
|
-
'44.230.40.184',
|
|
15
|
+
'34.214.48.68:1443',
|
|
16
|
+
'35.166.18.166:1443',
|
|
17
|
+
'35.165.50.126:1443',
|
|
18
|
+
'52.42.202.128:1443',
|
|
19
|
+
'52.12.176.90:1443',
|
|
20
|
+
'44.233.44.95:1443',
|
|
21
|
+
'35.167.145.149:1443',
|
|
22
|
+
'52.34.144.50:1443',
|
|
23
|
+
'44.240.98.102:1443',
|
|
24
|
+
'54.201.32.131:1443',
|
|
25
|
+
'52.10.229.11:1443',
|
|
26
|
+
'52.13.132.146:1443',
|
|
27
|
+
'44.228.242.181:1443',
|
|
28
|
+
'35.82.197.197:1443',
|
|
29
|
+
'52.40.219.41:1443',
|
|
30
|
+
'44.239.39.153:1443',
|
|
31
|
+
'54.149.33.167:1443',
|
|
32
|
+
'35.164.23.245:1443',
|
|
33
|
+
'52.33.28.47:1443',
|
|
34
|
+
'52.43.86.231:1443',
|
|
35
|
+
'52.43.13.92:1443',
|
|
36
|
+
'35.163.144.230:1443',
|
|
37
|
+
'52.89.154.48:1443',
|
|
38
|
+
'52.24.124.162:1443',
|
|
39
|
+
'44.227.137.77:1443',
|
|
40
|
+
'35.85.21.179:1443',
|
|
41
|
+
'54.187.14.232:1443',
|
|
42
|
+
'54.68.235.201:1443',
|
|
43
|
+
'52.13.250.182:1443',
|
|
44
|
+
'35.82.49.196:1443',
|
|
45
|
+
'44.232.196.6:1443',
|
|
46
|
+
'54.189.164.39:1443',
|
|
47
|
+
'54.213.204.85:1443',
|
|
129
48
|
],
|
|
130
49
|
},
|
|
131
|
-
evonet: {
|
|
132
|
-
seeds: [
|
|
133
|
-
'seed-1.evonet.networks.dash.org',
|
|
134
|
-
'seed-2.evonet.networks.dash.org',
|
|
135
|
-
'seed-3.evonet.networks.dash.org',
|
|
136
|
-
'seed-4.evonet.networks.dash.org',
|
|
137
|
-
'seed-5.evonet.networks.dash.org',
|
|
138
|
-
],
|
|
139
|
-
network: 'evonet',
|
|
140
|
-
},
|
|
141
50
|
local: {
|
|
142
51
|
dapiAddresses: ['127.0.0.1'],
|
|
143
52
|
network: 'regtest',
|
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,6 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const RetriableResponseError = require('../../errors/response/RetriableResponseError');
|
|
2
2
|
|
|
3
|
-
class InternalServerError extends
|
|
3
|
+
class InternalServerError extends RetriableResponseError {
|
|
4
4
|
/**
|
|
5
5
|
* @param {number} code
|
|
6
6
|
* @param {string} message
|
|
@@ -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(),
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const https = require('https');
|
|
2
2
|
const JsonRpcError = require('./errors/JsonRpcError');
|
|
3
3
|
const WrongHttpCodeError = require('./errors/WrongHttpCodeError');
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* @typedef {requestJsonRpc}
|
|
7
6
|
* @param {string} protocol
|
|
@@ -58,19 +57,19 @@ async function requestJsonRpc(protocol, host, port, selfSigned, method, params,
|
|
|
58
57
|
rejectUnauthorized: false,
|
|
59
58
|
});
|
|
60
59
|
}
|
|
61
|
-
|
|
62
60
|
// eslint-disable-next-line
|
|
63
61
|
const response = await fetch(url, requestOptions);
|
|
64
62
|
|
|
65
63
|
if (typeof requestTimeoutId !== 'undefined') {
|
|
66
64
|
clearTimeout(requestTimeoutId);
|
|
67
65
|
}
|
|
68
|
-
const data = await response.json();
|
|
69
66
|
|
|
70
67
|
if (!response.ok) {
|
|
71
68
|
throw new WrongHttpCodeError(requestInfo, response.status, response.statusText);
|
|
72
69
|
}
|
|
73
70
|
|
|
71
|
+
const data = await response.json();
|
|
72
|
+
|
|
74
73
|
if (data.error) {
|
|
75
74
|
throw new JsonRpcError(requestInfo, data.error);
|
|
76
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "0.25.0
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,25 +26,28 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "0.25.0
|
|
30
|
-
"@dashevo/dash-spv": "0.25.0
|
|
31
|
-
"@dashevo/dashcore-lib": "~0.20.
|
|
32
|
-
"@dashevo/dpp": "0.25.0
|
|
33
|
-
"@dashevo/grpc-common": "0.25.0
|
|
34
|
-
"@dashevo/wasm-dpp": "0.25.0
|
|
29
|
+
"@dashevo/dapi-grpc": "0.25.0",
|
|
30
|
+
"@dashevo/dash-spv": "0.25.0",
|
|
31
|
+
"@dashevo/dashcore-lib": "~0.20.9",
|
|
32
|
+
"@dashevo/dpp": "0.25.0",
|
|
33
|
+
"@dashevo/grpc-common": "0.25.0",
|
|
34
|
+
"@dashevo/wasm-dpp": "0.25.0",
|
|
35
35
|
"bs58": "^4.0.1",
|
|
36
36
|
"cbor": "^8.0.0",
|
|
37
|
+
"google-protobuf": "^3.12.2",
|
|
37
38
|
"lodash": "^4.17.21",
|
|
38
39
|
"node-fetch": "^2.6.7",
|
|
39
40
|
"node-inspect-extracted": "^1.0.8",
|
|
40
|
-
"wasm-x11-hash": "~0.0.2"
|
|
41
|
+
"wasm-x11-hash": "~0.0.2",
|
|
42
|
+
"winston": "^3.2.1"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@babel/core": "^7.15.5",
|
|
44
46
|
"assert-browserify": "^2.0.0",
|
|
45
47
|
"babel-loader": "^8.2.2",
|
|
48
|
+
"browserify-zlib": "^0.2.0",
|
|
46
49
|
"buffer": "^6.0.3",
|
|
47
|
-
"chai": "^4.3.
|
|
50
|
+
"chai": "^4.3.9",
|
|
48
51
|
"chai-as-promised": "^7.1.1",
|
|
49
52
|
"comment-parser": "^0.7.6",
|
|
50
53
|
"core-js": "^3.17.2",
|
|
@@ -55,7 +58,6 @@
|
|
|
55
58
|
"eslint-plugin-import": "^2.24.2",
|
|
56
59
|
"eslint-plugin-jsdoc": "^27.0.0",
|
|
57
60
|
"events": "^3.3.0",
|
|
58
|
-
"google-protobuf": "^3.12.2",
|
|
59
61
|
"karma": "^6.4.1",
|
|
60
62
|
"karma-chai": "^0.1.0",
|
|
61
63
|
"karma-chrome-launcher": "^3.1.0",
|
|
@@ -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",
|