@dignetwork/dig-sdk 0.0.1-alpha.90 → 0.0.1-alpha.92
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/dist/DigNetwork/ContentServer.d.ts +1 -1
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +34 -5
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
- package/dist/DigNetwork/DigPeer.js +3 -0
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +9 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ export declare class ContentServer {
|
|
|
8
8
|
private static readonly port;
|
|
9
9
|
constructor(ipAddress: string, storeId: string);
|
|
10
10
|
getKey(key: string, rootHash: string, challengeHex?: string): Promise<string>;
|
|
11
|
-
getPaymentAddress(): Promise<string>;
|
|
11
|
+
getPaymentAddress(): Promise<string | null>;
|
|
12
12
|
getWellKnown(): Promise<any>;
|
|
13
13
|
getKnownStores(): Promise<any>;
|
|
14
14
|
getStoresIndex(): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/ContentServer.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,qBAAa,aAAa;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;gBAExB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAYjC,MAAM,CACjB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EA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AAC;QACjB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;KACpC,CAAC;IAUW,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUrD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;YAgDrD,IAAI;YA0EJ,SAAS;YAMT,gBAAgB;YAiChB,KAAK;CA6GpB"}
|
|
@@ -37,7 +37,7 @@ class ContentServer {
|
|
|
37
37
|
}
|
|
38
38
|
catch (error) {
|
|
39
39
|
console.error(`Failed to fetch payment address from ${this.ipAddress}: ${error.message}`);
|
|
40
|
-
|
|
40
|
+
return null;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
// Method to get the .well-known information
|
|
@@ -201,7 +201,7 @@ class ContentServer {
|
|
|
201
201
|
// Helper method to fetch content with retries and redirection handling
|
|
202
202
|
async fetchWithRetries(url) {
|
|
203
203
|
let attempt = 0;
|
|
204
|
-
const maxRetries =
|
|
204
|
+
const maxRetries = 1;
|
|
205
205
|
const initialDelay = 2000; // 2 seconds
|
|
206
206
|
const maxDelay = 10000; // 10 seconds
|
|
207
207
|
const delayMultiplier = 1.5;
|
|
@@ -225,10 +225,12 @@ class ContentServer {
|
|
|
225
225
|
}
|
|
226
226
|
throw new Error(`Failed to retrieve data from ${url} after ${maxRetries} attempts.`);
|
|
227
227
|
}
|
|
228
|
-
// Core method to fetch content from a URL
|
|
228
|
+
// Core method to fetch content from a URL with a 5-second inactivity timeout
|
|
229
229
|
async fetch(url, maxRedirects = 5) {
|
|
230
230
|
return new Promise((resolve, reject) => {
|
|
231
231
|
const urlObj = new url_1.URL(url);
|
|
232
|
+
const timeoutDuration = 5000; // 5 seconds
|
|
233
|
+
let timeout = null; // Initialize timeout
|
|
232
234
|
const requestOptions = {
|
|
233
235
|
hostname: urlObj.hostname,
|
|
234
236
|
port: urlObj.port || ContentServer.port,
|
|
@@ -240,11 +242,31 @@ class ContentServer {
|
|
|
240
242
|
};
|
|
241
243
|
const request = http_1.default.request(requestOptions, (response) => {
|
|
242
244
|
let data = "";
|
|
245
|
+
// Set timeout for inactivity
|
|
246
|
+
timeout = setTimeout(() => {
|
|
247
|
+
console.error(`Request timeout: No data received for ${timeoutDuration / 1000} seconds.`);
|
|
248
|
+
request.destroy(); // Use destroy instead of abort
|
|
249
|
+
reject(new Error(`Request timed out after ${timeoutDuration / 1000} seconds of inactivity`));
|
|
250
|
+
}, timeoutDuration);
|
|
251
|
+
const resetTimeout = () => {
|
|
252
|
+
if (timeout) {
|
|
253
|
+
clearTimeout(timeout);
|
|
254
|
+
}
|
|
255
|
+
timeout = setTimeout(() => {
|
|
256
|
+
console.error(`Request timeout: No data received for ${timeoutDuration / 1000} seconds.`);
|
|
257
|
+
request.destroy(); // Use destroy instead of abort
|
|
258
|
+
reject(new Error(`Request timed out after ${timeoutDuration / 1000} seconds of inactivity`));
|
|
259
|
+
}, timeoutDuration);
|
|
260
|
+
};
|
|
243
261
|
if (response.statusCode === 200) {
|
|
244
262
|
response.on("data", (chunk) => {
|
|
245
263
|
data += chunk;
|
|
264
|
+
resetTimeout(); // Reset the timeout every time data is received
|
|
246
265
|
});
|
|
247
266
|
response.on("end", () => {
|
|
267
|
+
if (timeout) {
|
|
268
|
+
clearTimeout(timeout);
|
|
269
|
+
}
|
|
248
270
|
resolve(data);
|
|
249
271
|
});
|
|
250
272
|
}
|
|
@@ -253,8 +275,9 @@ class ContentServer {
|
|
|
253
275
|
// Handle redirects
|
|
254
276
|
if (maxRedirects > 0) {
|
|
255
277
|
const redirectUrl = new url_1.URL(response.headers.location, url); // Resolve relative URLs based on the original URL
|
|
256
|
-
|
|
257
|
-
|
|
278
|
+
if (timeout) {
|
|
279
|
+
clearTimeout(timeout);
|
|
280
|
+
}
|
|
258
281
|
this.fetch(redirectUrl.toString(), maxRedirects - 1)
|
|
259
282
|
.then(resolve)
|
|
260
283
|
.catch(reject);
|
|
@@ -264,10 +287,16 @@ class ContentServer {
|
|
|
264
287
|
}
|
|
265
288
|
}
|
|
266
289
|
else {
|
|
290
|
+
if (timeout) {
|
|
291
|
+
clearTimeout(timeout);
|
|
292
|
+
}
|
|
267
293
|
reject(new Error(`Failed to retrieve data from ${url}. Status code: ${response.statusCode}`));
|
|
268
294
|
}
|
|
269
295
|
});
|
|
270
296
|
request.on("error", (error) => {
|
|
297
|
+
if (timeout) {
|
|
298
|
+
clearTimeout(timeout);
|
|
299
|
+
}
|
|
271
300
|
console.error(`GET ${url}:`, error.message);
|
|
272
301
|
reject(error);
|
|
273
302
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DigPeer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigPeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAKpD,OAAO,EAKL,MAAM,EACP,MAAM,8BAA8B,CAAC;AAKtC,qBAAa,OAAO;IAClB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,gBAAgB,CAAkB;gBAE9B,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAS9C,IAAW,aAAa,IAAI,aAAa,CAExC;IAGD,IAAW,iBAAiB,IAAI,iBAAiB,CAEhD;IAGD,IAAW,eAAe,IAAI,eAAe,CAE5C;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;WAEa,qBAAqB,CACjC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EAAE,EACnB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EAAE,GACd,OAAO,CA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ACd,KAAK,GAAE,MAAM,EAAO,GACnB,OAAO,CAAC,IAAI,CAAC;WAiBF,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAqBlC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAc1B,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOhE"}
|
|
@@ -70,6 +70,9 @@ class DigPeer {
|
|
|
70
70
|
}
|
|
71
71
|
async sendPayment(walletName, amount, memos = []) {
|
|
72
72
|
const paymentAddress = await this.contentServer.getPaymentAddress();
|
|
73
|
+
if (!paymentAddress) {
|
|
74
|
+
throw new Error("Payment address not found.");
|
|
75
|
+
}
|
|
73
76
|
const paymentAddressPuzzleHash = (0, datalayer_driver_1.addressToPuzzleHash)(paymentAddress);
|
|
74
77
|
const output = {
|
|
75
78
|
puzzleHash: paymentAddressPuzzleHash,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAoBpD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAkD;IAC3E,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAA0B;IAChE,OAAO,CAAC,IAAI,CAAO;IACnB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA0B;IAMzD,OAAO;WAIa,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5C,OAAO,CAAC,MAAM,CAAC,eAAe;IAiB9B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAM/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;mBASZ,eAAe;mBA2Df,UAAU;IA2B/B,OAAO,CAAC,MAAM,CAAC,eAAe;mBAkDT,WAAW;
|
|
1
|
+
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAoBpD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAkD;IAC3E,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAA0B;IAChE,OAAO,CAAC,IAAI,CAAO;IACnB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA0B;IAMzD,OAAO;WAIa,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5C,OAAO,CAAC,MAAM,CAAC,eAAe;IAiB9B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAM/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;mBASZ,eAAe;mBA2Df,UAAU;IA2B/B,OAAO,CAAC,MAAM,CAAC,eAAe;mBAkDT,WAAW;IAuGzB,OAAO,IAAI,IAAI;WAIF,mBAAmB,CACrC,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC;CAwBpB"}
|
|
@@ -191,8 +191,16 @@ class FullNodePeer {
|
|
|
191
191
|
const trustedNodeIp = process.env.TRUSTED_FULLNODE || null;
|
|
192
192
|
const peers = await Promise.all(peerIPs.map(async (ip) => {
|
|
193
193
|
if (ip) {
|
|
194
|
+
// Allow override of the trusted fullnode port if the override exists
|
|
195
|
+
let port = FULLNODE_PORT;
|
|
196
|
+
if (trustedNodeIp && ip === trustedNodeIp) {
|
|
197
|
+
const trustedFullNodePort = process.env.TRUSTED_FULLNODE_PORT;
|
|
198
|
+
if (trustedFullNodePort) {
|
|
199
|
+
port = parseInt(trustedFullNodePort);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
194
202
|
try {
|
|
195
|
-
const peer = await datalayer_driver_1.Peer.new(`${ip}:${
|
|
203
|
+
const peer = await datalayer_driver_1.Peer.new(`${ip}:${port}`, false, certFile, keyFile);
|
|
196
204
|
return FullNodePeer.createPeerProxy(peer);
|
|
197
205
|
}
|
|
198
206
|
catch (error) {
|