@dignetwork/dig-sdk 0.0.1-alpha.167 → 0.0.1-alpha.169

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...`).start();
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;;;;OAIG;WACiB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5C;;;;;;OA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AGpB;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;;;;OAIG;WACiB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5C;;;;;;OAMG;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 peers = Array.from(FullNodePeer.peerWeights.keys()).filter((ip) => !FullNodePeer.cooldownCache.has(ip));
240
- if (peers.length === 0) {
241
- throw new Error("All fullnode peers are in cooldown.");
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
- // Round-robin selection
244
- const selectedPeer = peers[FullNodePeer.roundRobinIndex % peers.length];
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,15 +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
- try {
409
- await peer.waitForCoinToBeSpent(parentCoinInfo, config_1.MIN_HEIGHT, Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
410
- spinner.success({ text: "Coin confirmed!" });
411
- return true;
412
- }
413
- catch (error) {
414
- spinner.error({ text: "Error while waiting for confirmation." });
415
- console.error(`waitForConfirmation error: ${error.message}`);
416
- throw error;
412
+ while (true) {
413
+ try {
414
+ await peer.waitForCoinToBeSpent(parentCoinInfo, config_1.MIN_HEIGHT, Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
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
+ }
427
+ }
417
428
  }
418
429
  }
419
430
  }
@@ -1 +1 @@
1
- {"version":3,"file":"StoreMonitorRegistry.d.ts","sourceRoot":"","sources":["../../src/blockchain/StoreMonitorRegistry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAK5D;;GAEG;AACH,UAAU,eAAe;IACvB,WAAW,EAAE,UAAU,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1D,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,KAAK,mBAAmB,GAAG,CACzB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,eAAe,KAC1B,IAAI,CAAC;AAEV;;;GAGG;AACH,qBAAa,oBAAoB;IAE/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAuB;IAG9C,OAAO,CAAC,cAAc,CAAmC;IAGzD,OAAO,CAAC,cAAc,CAA6B;IAGnD,OAAO,CAAC,uBAAuB,CAAwC;IAEvE;;OAEG;IACH,OAAO;IASP;;;OAGG;WACW,WAAW,IAAI,oBAAoB;IAOjD;;;;;OAKG;IACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QA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;;;;OAMG;YACW,YAAY;IA4B1B;;;;;OAKG;YACW,YAAY;IAuG1B;;;;OAIG;YACW,sBAAsB;IA2CpC;;;;OAIG;YACW,KAAK;IAInB;;;OAGG;IACI,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAS7C;;;OAGG;IACI,eAAe,IAAI,IAAI;CAI/B"}
@@ -185,17 +185,14 @@ class StoreMonitorRegistry {
185
185
  * @returns {Promise<StoreCacheEntry>} The latest store information.
186
186
  */
187
187
  async fetchAndCacheStoreInfo(storeId) {
188
- console.log(`Monitor: Fetching and caching latest store info for storeId: ${storeId}`);
189
188
  const peer = await FullNodePeer_1.FullNodePeer.connect();
190
189
  const dataStore = DataStore_1.DataStore.from(storeId);
191
190
  const { createdAtHeight, createdAtHash } = await dataStore.getCreationHeight();
192
191
  // Sync store from the peer using launcher ID
193
- console.log(`Monitor: Syncing store from launcher ID for storeId: ${storeId}`);
194
192
  const { latestStore, latestHeight } = await peer.syncStoreFromLauncherId(Buffer.from(storeId, "hex"), createdAtHeight, createdAtHash, false);
195
193
  const latestHash = await peer.getHeaderHash(latestHeight);
196
194
  // Serialize and cache the new store info
197
195
  const serializedLatestStore = new DataStoreSerializer_1.DataStoreSerializer(latestStore, latestHeight, latestHash).serialize();
198
- console.log(`Monitor: Caching new store info for storeId: ${storeId}`);
199
196
  this.storeCoinCache.set(storeId, {
200
197
  latestStore: serializedLatestStore,
201
198
  latestHeight,
@@ -6,4 +6,20 @@ export declare const addDirectory: (datalayer: DataIntegrityTree, dirPath: strin
6
6
  * @returns The total size of the folder in bytes.
7
7
  */
8
8
  export declare const calculateFolderSize: (folderPath: string) => bigint;
9
+ /**
10
+ * Represents the result of listing files.
11
+ * - If `groupSize` is not provided, returns an array of relative file paths.
12
+ * - If `groupSize` is provided, returns an array of arrays, each containing up to `groupSize` file paths.
13
+ */
14
+ type ListFilesResult = string[] | string[][];
15
+ /**
16
+ * Recursively lists all files in a directory, excluding specified folders and respecting `.gitignore` rules.
17
+ * Optionally groups the list into batches of a specified size.
18
+ *
19
+ * @param {string} baseDir - The base directory path to start listing files from.
20
+ * @param {number} [groupSize] - Optional. The number of files per group. If provided, the result will be an array of arrays.
21
+ * @returns {ListFilesResult} - A flat list of relative file paths or grouped lists based on `groupSize`.
22
+ */
23
+ export declare function listFilesRecursively(baseDir: string, groupSize?: number): ListFilesResult;
24
+ export {};
9
25
  //# sourceMappingURL=directoryUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA+BzD,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CA4Cd,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC"}
1
+ {"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA+BzD,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CA4Cd,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC;AAEF;;;;GAIG;AACH,KAAK,eAAe,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC;AAE7C;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,eAAe,CAiEjB"}
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.calculateFolderSize = exports.addDirectory = void 0;
30
+ exports.listFilesRecursively = listFilesRecursively;
30
31
  const path = __importStar(require("path"));
31
32
  const fs = __importStar(require("fs"));
32
33
  const ignore_1 = __importDefault(require("ignore"));
@@ -108,3 +109,68 @@ const calculateFolderSize = (folderPath) => {
108
109
  return totalSize;
109
110
  };
110
111
  exports.calculateFolderSize = calculateFolderSize;
112
+ /**
113
+ * Recursively lists all files in a directory, excluding specified folders and respecting `.gitignore` rules.
114
+ * Optionally groups the list into batches of a specified size.
115
+ *
116
+ * @param {string} baseDir - The base directory path to start listing files from.
117
+ * @param {number} [groupSize] - Optional. The number of files per group. If provided, the result will be an array of arrays.
118
+ * @returns {ListFilesResult} - A flat list of relative file paths or grouped lists based on `groupSize`.
119
+ */
120
+ function listFilesRecursively(baseDir, groupSize) {
121
+ // Initialize the ignore instance
122
+ const ig = (0, ignore_1.default)();
123
+ // Path to .gitignore
124
+ const gitignorePath = path.join(baseDir, ".gitignore");
125
+ // Load and parse .gitignore if it exists
126
+ if (fs.existsSync(gitignorePath)) {
127
+ const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
128
+ ig.add(gitignoreContent);
129
+ }
130
+ // Initialize result containers
131
+ const allFiles = [];
132
+ let groupedFiles = [];
133
+ /**
134
+ * Recursively traverses directories to collect files.
135
+ *
136
+ * @param {string} currentDir - The current directory path being traversed.
137
+ */
138
+ function traverseDirectory(currentDir) {
139
+ let entries;
140
+ try {
141
+ entries = fs.readdirSync(currentDir, { withFileTypes: true });
142
+ }
143
+ catch (err) {
144
+ console.error(`Failed to read directory: ${currentDir}. Error: ${err.message}`);
145
+ return;
146
+ }
147
+ for (const entry of entries) {
148
+ const entryName = entry.name;
149
+ const fullPath = path.join(currentDir, entryName);
150
+ const relativePath = path.relative(baseDir, fullPath).replace(/\\/g, "/"); // Normalize to forward slashes
151
+ // Skip .git and .dig directories and any ignored paths
152
+ if (entryName === ".git" || entryName === ".dig" || ig.ignores(relativePath)) {
153
+ continue;
154
+ }
155
+ if (entry.isDirectory()) {
156
+ traverseDirectory(fullPath); // Recurse into subdirectory
157
+ }
158
+ else if (entry.isFile()) {
159
+ allFiles.push(relativePath);
160
+ }
161
+ // Optionally handle symbolic links or other types if needed
162
+ }
163
+ }
164
+ // Start traversal from the base directory
165
+ traverseDirectory(baseDir);
166
+ // If groupSize is provided and valid, group the files accordingly
167
+ if (groupSize && Number.isInteger(groupSize) && groupSize > 0) {
168
+ groupedFiles = [];
169
+ for (let i = 0; i < allFiles.length; i += groupSize) {
170
+ groupedFiles.push(allFiles.slice(i, i + groupSize));
171
+ }
172
+ return groupedFiles;
173
+ }
174
+ // Return the flat list of files if grouping is not required
175
+ return allFiles;
176
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.167",
3
+ "version": "0.0.1-alpha.169",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",