@dignetwork/dig-sdk 0.0.1-alpha.166 → 0.0.1-alpha.168
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.
|
@@ -199,7 +199,7 @@ class PropagationServer {
|
|
|
199
199
|
return cachedResult;
|
|
200
200
|
}
|
|
201
201
|
// If not cached, proceed with the HTTP request
|
|
202
|
-
const spinner = (0, nanospinner_1.createSpinner)(`Checking if store ${this.storeId} exists
|
|
202
|
+
const spinner = (0, nanospinner_1.createSpinner)(`Checking if store ${this.storeId} exists on peer: ${this.ipAddress}`).start();
|
|
203
203
|
try {
|
|
204
204
|
const config = {
|
|
205
205
|
httpsAgent: this.createHttpsAgent(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAO,MAAM,8BAA8B,CAAC;AAgCzD;;GAEG;AACH,qBAAa,YAAY;IAqCH,OAAO,CAAC,IAAI;IAnChC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA6B;IAGpD,OAAO,CAAC,MAAM,CAAC,aAAa,CAEzB;IAGH,OAAO,CAAC,MAAM,CAAC,cAAc,CAAoC;IAGjE,OAAO,CAAC,MAAM,CAAC,WAAW,CAAkC;IAG5D,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAgB;IAG/C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAoC;IAG5D,OAAO,CAAC,MAAM,CAAC,WAAW,CAAoD;IAG9E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAGpB;IAGH,OAAO,CAAC,MAAM,CAAC,YAAY,CAAsC;IAGjE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAa;IAG3C,OAAO;IAEP;;;OAGG;WACW,WAAW,IAAI,YAAY;IAOzC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxC;;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AMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAuB9B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAM/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IASjC;;;;OAIG;mBACkB,eAAe;IAkGpC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAS3B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAYpC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAwBnC;;;OAGG;mBACkB,UAAU;IAK/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAIzB;;;OAGG;YACW,WAAW;IAuEzB,OAAO,CAAC,eAAe;IAsDvB;;;OAGG;WACW,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAmB3D;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAS5B;;;;OAIG;WACiB,mBAAmB,CACrC,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC;CAwBpB"}
|
|
@@ -236,12 +236,17 @@ class FullNodePeer {
|
|
|
236
236
|
* @returns {string} The selected peer IP.
|
|
237
237
|
*/
|
|
238
238
|
static selectPeerRoundRobin() {
|
|
239
|
-
const
|
|
240
|
-
if (
|
|
241
|
-
|
|
239
|
+
const availablePrioritizedPeers = FullNodePeer.prioritizedPeers.filter((ip) => !FullNodePeer.cooldownCache.has(ip) && FullNodePeer.peerWeights.has(ip));
|
|
240
|
+
if (availablePrioritizedPeers.length > 0) {
|
|
241
|
+
// Select the first available prioritized peer
|
|
242
|
+
return availablePrioritizedPeers[0];
|
|
242
243
|
}
|
|
243
|
-
//
|
|
244
|
-
const
|
|
244
|
+
// If no prioritized peers are available, proceed with round-robin among other peers
|
|
245
|
+
const regularPeers = Array.from(FullNodePeer.peerWeights.keys()).filter((ip) => !FullNodePeer.prioritizedPeers.includes(ip) && !FullNodePeer.cooldownCache.has(ip));
|
|
246
|
+
if (regularPeers.length === 0) {
|
|
247
|
+
throw new Error("No available peers to connect.");
|
|
248
|
+
}
|
|
249
|
+
const selectedPeer = regularPeers[FullNodePeer.roundRobinIndex % regularPeers.length];
|
|
245
250
|
FullNodePeer.roundRobinIndex += 1;
|
|
246
251
|
return selectedPeer;
|
|
247
252
|
}
|
|
@@ -348,10 +353,10 @@ class FullNodePeer {
|
|
|
348
353
|
return result;
|
|
349
354
|
}
|
|
350
355
|
catch (error) {
|
|
356
|
+
FullNodePeer.handlePeerDisconnection(peerIP);
|
|
351
357
|
// If the error is WebSocket-related or timeout, reset the peer
|
|
352
358
|
if (error.message.includes("WebSocket") ||
|
|
353
359
|
error.message.includes("Operation timed out")) {
|
|
354
|
-
FullNodePeer.handlePeerDisconnection(peerIP);
|
|
355
360
|
const newPeer = await this.getBestPeer();
|
|
356
361
|
return newPeer[prop](...args);
|
|
357
362
|
}
|
|
@@ -382,7 +387,6 @@ class FullNodePeer {
|
|
|
382
387
|
FullNodePeer.peerInfos.delete(peerIP);
|
|
383
388
|
// Remove the limiter
|
|
384
389
|
FullNodePeer.peerLimiters.delete(peerIP);
|
|
385
|
-
console.warn(`Fullnode Peer ${peerIP} has been marked as disconnected and is in cooldown.`);
|
|
386
390
|
}
|
|
387
391
|
/**
|
|
388
392
|
* Extracts the IP address from a Peer instance.
|
|
@@ -405,17 +409,22 @@ class FullNodePeer {
|
|
|
405
409
|
static async waitForConfirmation(parentCoinInfo) {
|
|
406
410
|
const spinner = (0, nanospinner_1.createSpinner)("Waiting for confirmation...").start();
|
|
407
411
|
const peer = await FullNodePeer.connect();
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
// Schedule the isCoinSpent method call through the limiter
|
|
412
|
+
while (true) {
|
|
413
|
+
try {
|
|
411
414
|
await peer.waitForCoinToBeSpent(parentCoinInfo, config_1.MIN_HEIGHT, Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
|
|
412
415
|
spinner.success({ text: "Coin confirmed!" });
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
if (error.message.includes("UnknownCoin")) {
|
|
420
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
spinner.error({ text: "Error while waiting for confirmation." });
|
|
424
|
+
console.error(`waitForConfirmation error: ${error.message}`);
|
|
425
|
+
throw error;
|
|
426
|
+
}
|
|
413
427
|
}
|
|
414
|
-
}
|
|
415
|
-
catch (error) {
|
|
416
|
-
spinner.error({ text: "Error while waiting for confirmation." });
|
|
417
|
-
console.error(`waitForConfirmation error: ${error.message}`);
|
|
418
|
-
throw error;
|
|
419
428
|
}
|
|
420
429
|
}
|
|
421
430
|
}
|
|
@@ -108,3 +108,68 @@ const calculateFolderSize = (folderPath) => {
|
|
|
108
108
|
return totalSize;
|
|
109
109
|
};
|
|
110
110
|
exports.calculateFolderSize = calculateFolderSize;
|
|
111
|
+
/**
|
|
112
|
+
* Recursively lists all files in a directory, excluding specified folders and respecting `.gitignore` rules.
|
|
113
|
+
* Optionally groups the list into batches of a specified size.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} baseDir - The base directory path to start listing files from.
|
|
116
|
+
* @param {number} [groupSize] - Optional. The number of files per group. If provided, the result will be an array of arrays.
|
|
117
|
+
* @returns {ListFilesResult} - A flat list of relative file paths or grouped lists based on `groupSize`.
|
|
118
|
+
*/
|
|
119
|
+
function listFilesRecursively(baseDir, groupSize) {
|
|
120
|
+
// Initialize the ignore instance
|
|
121
|
+
const ig = (0, ignore_1.default)();
|
|
122
|
+
// Path to .gitignore
|
|
123
|
+
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
124
|
+
// Load and parse .gitignore if it exists
|
|
125
|
+
if (fs.existsSync(gitignorePath)) {
|
|
126
|
+
const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
|
|
127
|
+
ig.add(gitignoreContent);
|
|
128
|
+
}
|
|
129
|
+
// Initialize result containers
|
|
130
|
+
const allFiles = [];
|
|
131
|
+
let groupedFiles = [];
|
|
132
|
+
/**
|
|
133
|
+
* Recursively traverses directories to collect files.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} currentDir - The current directory path being traversed.
|
|
136
|
+
*/
|
|
137
|
+
function traverseDirectory(currentDir) {
|
|
138
|
+
let entries;
|
|
139
|
+
try {
|
|
140
|
+
entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
console.error(`Failed to read directory: ${currentDir}. Error: ${err.message}`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
for (const entry of entries) {
|
|
147
|
+
const entryName = entry.name;
|
|
148
|
+
const fullPath = path.join(currentDir, entryName);
|
|
149
|
+
const relativePath = path.relative(baseDir, fullPath).replace(/\\/g, "/"); // Normalize to forward slashes
|
|
150
|
+
// Skip .git and .dig directories and any ignored paths
|
|
151
|
+
if (entryName === ".git" || entryName === ".dig" || ig.ignores(relativePath)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (entry.isDirectory()) {
|
|
155
|
+
traverseDirectory(fullPath); // Recurse into subdirectory
|
|
156
|
+
}
|
|
157
|
+
else if (entry.isFile()) {
|
|
158
|
+
allFiles.push(relativePath);
|
|
159
|
+
}
|
|
160
|
+
// Optionally handle symbolic links or other types if needed
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Start traversal from the base directory
|
|
164
|
+
traverseDirectory(baseDir);
|
|
165
|
+
// If groupSize is provided and valid, group the files accordingly
|
|
166
|
+
if (groupSize && Number.isInteger(groupSize) && groupSize > 0) {
|
|
167
|
+
groupedFiles = [];
|
|
168
|
+
for (let i = 0; i < allFiles.length; i += groupSize) {
|
|
169
|
+
groupedFiles.push(allFiles.slice(i, i + groupSize));
|
|
170
|
+
}
|
|
171
|
+
return groupedFiles;
|
|
172
|
+
}
|
|
173
|
+
// Return the flat list of files if grouping is not required
|
|
174
|
+
return allFiles;
|
|
175
|
+
}
|