@dignetwork/dig-sdk 0.0.1-alpha.3 → 0.0.1-alpha.30
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/DataIntegrityTree/DataIntegrityTree.d.ts +160 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.js +672 -0
- package/dist/DataIntegrityTree/DataLayerError.d.ts +6 -0
- package/dist/DataIntegrityTree/DataLayerError.d.ts.map +1 -0
- package/dist/DataIntegrityTree/DataLayerError.js +17 -0
- package/dist/DataIntegrityTree/index.d.ts +2 -0
- package/dist/DataIntegrityTree/index.d.ts.map +1 -0
- package/dist/DataIntegrityTree/index.js +17 -0
- package/dist/DigNetwork/ContentServer.d.ts +5 -1
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +26 -11
- package/dist/DigNetwork/DigNetwork.d.ts +3 -1
- package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
- package/dist/DigNetwork/DigNetwork.js +79 -9
- package/dist/DigNetwork/DigPeer.d.ts +5 -1
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
- package/dist/DigNetwork/DigPeer.js +51 -16
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +39 -42
- package/dist/blockchain/DataStore.d.ts +4 -2
- package/dist/blockchain/DataStore.d.ts.map +1 -1
- package/dist/blockchain/DataStore.js +32 -5
- package/dist/blockchain/DataStoreSerializer.d.ts +1 -1
- package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.d.ts +8 -1
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +39 -7
- package/dist/blockchain/ServerCoin.d.ts +11 -3
- package/dist/blockchain/ServerCoin.d.ts.map +1 -1
- package/dist/blockchain/ServerCoin.js +30 -17
- package/dist/blockchain/Wallet.d.ts +1 -1
- package/dist/blockchain/Wallet.d.ts.map +1 -1
- package/dist/blockchain/Wallet.js +1 -1
- package/dist/blockchain/coins.d.ts +1 -1
- package/dist/blockchain/coins.d.ts.map +1 -1
- package/dist/blockchain/coins.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +4 -9
- package/dist/utils/directoryUtils.d.ts +1 -7
- package/dist/utils/directoryUtils.d.ts.map +1 -1
- package/dist/utils/directoryUtils.js +30 -11
- package/package.json +3 -3
|
@@ -6,14 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.DataStore = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const datalayer_driver_1 = require("datalayer-driver");
|
|
9
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
10
10
|
const util_1 = require("util");
|
|
11
11
|
const FullNodePeer_1 = require("./FullNodePeer");
|
|
12
12
|
const Wallet_1 = require("./Wallet");
|
|
13
13
|
const config_1 = require("../utils/config");
|
|
14
14
|
const coins_1 = require("./coins");
|
|
15
15
|
const utils_1 = require("../utils");
|
|
16
|
-
const
|
|
16
|
+
const hashUtils_1 = require("../utils/hashUtils");
|
|
17
|
+
const DataIntegrityTree_1 = require("../DataIntegrityTree");
|
|
17
18
|
const prompts_1 = require("../prompts");
|
|
18
19
|
const FileCache_1 = require("../utils/FileCache");
|
|
19
20
|
const DataStoreSerializer_1 = require("./DataStoreSerializer");
|
|
@@ -32,7 +33,7 @@ class DataStore {
|
|
|
32
33
|
storeDir: config_1.STORE_PATH,
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
this.tree = new
|
|
36
|
+
this.tree = new DataIntegrityTree_1.DataIntegrityTree(storeId, _options);
|
|
36
37
|
}
|
|
37
38
|
get StoreId() {
|
|
38
39
|
return this.storeId;
|
|
@@ -335,6 +336,7 @@ class DataStore {
|
|
|
335
336
|
}
|
|
336
337
|
}
|
|
337
338
|
let filesIntegrityIntact = true;
|
|
339
|
+
// At this point we have verified that the root history and manifest file match
|
|
338
340
|
for (const rootHash of manifestHashes) {
|
|
339
341
|
const datFilePath = path_1.default.join(config_1.STORE_PATH, this.storeId, `${rootHash}.dat`);
|
|
340
342
|
if (!fs_1.default.existsSync(datFilePath)) {
|
|
@@ -347,8 +349,11 @@ class DataStore {
|
|
|
347
349
|
return false;
|
|
348
350
|
}
|
|
349
351
|
for (const [fileKey, fileData] of Object.entries(datFileContent.files)) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
+
// We are going to check if the sha256 belongs to the tree, and then we are going to make sure
|
|
353
|
+
// that the file is in the data folder and that the sha256 of the file matches the one in the dat file
|
|
354
|
+
const belongsInTree = await this.Tree.verifyKeyIntegrity(fileData.sha256, rootHash);
|
|
355
|
+
const fileIntegrityCheck = (0, utils_1.validateFileSha256)(fileData.sha256, path_1.default.join(config_1.STORE_PATH, this.storeId, "data"));
|
|
356
|
+
if (!fileIntegrityCheck || !belongsInTree) {
|
|
352
357
|
filesIntegrityIntact = false;
|
|
353
358
|
}
|
|
354
359
|
}
|
|
@@ -406,5 +411,27 @@ class DataStore {
|
|
|
406
411
|
}
|
|
407
412
|
return updateStoreResponse.newStore;
|
|
408
413
|
}
|
|
414
|
+
async getFileSetForRootHash(rootHash) {
|
|
415
|
+
const datFilePath = path_1.default.join(config_1.STORE_PATH, this.storeId, `${rootHash}.dat`);
|
|
416
|
+
const datFileContent = JSON.parse(fs_1.default.readFileSync(datFilePath, "utf-8"));
|
|
417
|
+
const heightDatFilePath = path_1.default.join(config_1.STORE_PATH, this.storeId, "height.json");
|
|
418
|
+
const manifestFilePath = path_1.default.join(config_1.STORE_PATH, this.storeId, "manifest.dat");
|
|
419
|
+
const filesInvolved = [];
|
|
420
|
+
filesInvolved.push(manifestFilePath);
|
|
421
|
+
filesInvolved.push(datFilePath);
|
|
422
|
+
filesInvolved.push(heightDatFilePath);
|
|
423
|
+
for (const [fileKey, fileData] of Object.entries(datFileContent.files)) {
|
|
424
|
+
const filepath = path_1.default.join(config_1.STORE_PATH, this.storeId, "data", fileKey);
|
|
425
|
+
const filePath = (0, hashUtils_1.getFilePathFromSha256)(datFileContent.files[fileKey].sha256, path_1.default.join(config_1.STORE_PATH, this.storeId, "data"));
|
|
426
|
+
filesInvolved.push(filePath);
|
|
427
|
+
}
|
|
428
|
+
return filesInvolved;
|
|
429
|
+
}
|
|
430
|
+
getManifestHashes() {
|
|
431
|
+
const manifestFilePath = path_1.default.join(config_1.STORE_PATH, this.storeId, "manifest.dat");
|
|
432
|
+
return fs_1.default.existsSync(manifestFilePath)
|
|
433
|
+
? fs_1.default.readFileSync(manifestFilePath, "utf-8").split("\n").filter(Boolean)
|
|
434
|
+
: [];
|
|
435
|
+
}
|
|
409
436
|
}
|
|
410
437
|
exports.DataStore = DataStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataStoreSerializer.d.ts","sourceRoot":"","sources":["../../src/blockchain/DataStoreSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAKV,MAAM,
|
|
1
|
+
{"version":3,"file":"DataStoreSerializer.d.ts","sourceRoot":"","sources":["../../src/blockchain/DataStoreSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAKV,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,UAAU,CAAS;gBAEf,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAOnE,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAgDF,WAAW,CACvB,IAAI,EAAE;QACJ,WAAW,EAAE,GAAG,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,GACA;QACD,WAAW,EAAE,SAAS,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB;CAuEF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Peer } from "datalayer-driver";
|
|
1
|
+
import { Peer } from "@dignetwork/datalayer-driver";
|
|
2
2
|
export declare class FullNodePeer {
|
|
3
3
|
private static cachedPeer;
|
|
4
4
|
private static memoizedFetchNewPeerIPs;
|
|
@@ -7,6 +7,13 @@ export declare class FullNodePeer {
|
|
|
7
7
|
static connect(): Promise<Peer>;
|
|
8
8
|
private static isPortReachable;
|
|
9
9
|
private static isValidIpAddress;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the TRUSTED_FULLNODE IP from the environment
|
|
12
|
+
* and verifies if it is a valid IP address.
|
|
13
|
+
*
|
|
14
|
+
* @returns {string | null} The valid IP address or null if invalid
|
|
15
|
+
*/
|
|
16
|
+
private static getTrustedFullNode;
|
|
10
17
|
private static fetchNewPeerIPs;
|
|
11
18
|
private static getPeerIPs;
|
|
12
19
|
private static createPeerProxy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAmBpD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAkD;IAC3E,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAA0B;IAChE,OAAO,CAAC,IAAI,CAAO;IAQnB,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;mBAiDf,UAAU;IAyB/B,OAAO,CAAC,MAAM,CAAC,eAAe;mBAgDT,WAAW;IAgGzB,OAAO,IAAI,IAAI;WAIF,mBAAmB,CACrC,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC;CAwBpB"}
|
|
@@ -7,7 +7,7 @@ exports.FullNodePeer = void 0;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const datalayer_driver_1 = require("datalayer-driver");
|
|
10
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
11
11
|
const chia_server_coin_1 = require("chia-server-coin");
|
|
12
12
|
const promises_1 = require("dns/promises");
|
|
13
13
|
const net_1 = __importDefault(require("net"));
|
|
@@ -48,12 +48,24 @@ class FullNodePeer {
|
|
|
48
48
|
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
49
49
|
return ipv4Regex.test(ip);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves the TRUSTED_FULLNODE IP from the environment
|
|
53
|
+
* and verifies if it is a valid IP address.
|
|
54
|
+
*
|
|
55
|
+
* @returns {string | null} The valid IP address or null if invalid
|
|
56
|
+
*/
|
|
57
|
+
static getTrustedFullNode() {
|
|
52
58
|
const trustedNodeIp = process.env.TRUSTED_FULLNODE || null;
|
|
59
|
+
if (trustedNodeIp && FullNodePeer.isValidIpAddress(trustedNodeIp)) {
|
|
60
|
+
return trustedNodeIp;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
static async fetchNewPeerIPs() {
|
|
65
|
+
const trustedNodeIp = FullNodePeer.getTrustedFullNode();
|
|
53
66
|
const priorityIps = [];
|
|
54
67
|
// Prioritize trustedNodeIp
|
|
55
68
|
if (trustedNodeIp &&
|
|
56
|
-
FullNodePeer.isValidIpAddress(trustedNodeIp) &&
|
|
57
69
|
(await FullNodePeer.isPortReachable(trustedNodeIp, FULLNODE_PORT))) {
|
|
58
70
|
priorityIps.push(trustedNodeIp);
|
|
59
71
|
}
|
|
@@ -107,18 +119,38 @@ class FullNodePeer {
|
|
|
107
119
|
}
|
|
108
120
|
return FullNodePeer.memoizedFetchNewPeerIPs();
|
|
109
121
|
}
|
|
110
|
-
static createPeerProxy(peer
|
|
122
|
+
static createPeerProxy(peer) {
|
|
111
123
|
return new Proxy(peer, {
|
|
112
124
|
get: (target, prop) => {
|
|
113
125
|
const originalMethod = target[prop];
|
|
114
126
|
if (typeof originalMethod === "function") {
|
|
115
127
|
return async (...args) => {
|
|
128
|
+
let timeoutId;
|
|
129
|
+
// Start the timeout to forget the peer after 1 minute
|
|
130
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
131
|
+
timeoutId = setTimeout(() => {
|
|
132
|
+
FullNodePeer.cachedPeer = null;
|
|
133
|
+
reject(new Error("Operation timed out. Reconnecting to a new peer."));
|
|
134
|
+
}, 60000); // 1 minute
|
|
135
|
+
});
|
|
116
136
|
try {
|
|
117
|
-
|
|
137
|
+
// Run the original method and race it against the timeout
|
|
138
|
+
const result = await Promise.race([
|
|
139
|
+
originalMethod.apply(target, args),
|
|
140
|
+
timeoutPromise,
|
|
141
|
+
]);
|
|
142
|
+
// Clear the timeout if the operation succeeded
|
|
143
|
+
if (timeoutId) {
|
|
144
|
+
clearTimeout(timeoutId);
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
118
147
|
}
|
|
119
148
|
catch (error) {
|
|
120
|
-
|
|
149
|
+
// If the error is WebSocket-related or timeout, reset the peer
|
|
150
|
+
if (error.message.includes("WebSocket") || error.message.includes("Operation timed out")) {
|
|
121
151
|
FullNodePeer.cachedPeer = null;
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
FullNodePeer.memoizedFetchNewPeerIPs.cache.clear();
|
|
122
154
|
const newPeer = await FullNodePeer.getBestPeer();
|
|
123
155
|
return newPeer[prop](...args);
|
|
124
156
|
}
|
|
@@ -149,7 +181,7 @@ class FullNodePeer {
|
|
|
149
181
|
if (ip) {
|
|
150
182
|
try {
|
|
151
183
|
const peer = await datalayer_driver_1.Peer.new(`${ip}:${FULLNODE_PORT}`, false, certFile, keyFile);
|
|
152
|
-
return FullNodePeer.createPeerProxy(peer
|
|
184
|
+
return FullNodePeer.createPeerProxy(peer);
|
|
153
185
|
}
|
|
154
186
|
catch (error) {
|
|
155
187
|
console.error(`Failed to create peer for IP ${ip}: ${error.message}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServerCoin as ServerCoinDriver } from "datalayer-driver";
|
|
1
|
+
import { ServerCoin as ServerCoinDriver } from "@dignetwork/datalayer-driver";
|
|
2
2
|
import { NconfManager } from "../utils/NconfManager";
|
|
3
3
|
export declare class ServerCoin {
|
|
4
4
|
private storeId;
|
|
@@ -8,14 +8,22 @@ export declare class ServerCoin {
|
|
|
8
8
|
saveServerCoinData(serverCoin: ServerCoinDriver, epoch: number, peerIp: string): Promise<void>;
|
|
9
9
|
melt(epoch: number, peerIp: string): Promise<void>;
|
|
10
10
|
private removeServerCoinData;
|
|
11
|
+
getAllEpochPeers(epoch: number, blacklist?: string[]): Promise<string[]>;
|
|
12
|
+
getActiveEpochPeers(blacklist?: string[]): Promise<string[]>;
|
|
11
13
|
sampleCurrentEpoch(sampleSize?: number, blacklist?: string[]): Promise<string[]>;
|
|
12
14
|
sampleServerCoinsByEpoch(epoch: number, sampleSize?: number, blacklist?: string[]): Promise<string[]>;
|
|
13
|
-
static getCurrentEpoch():
|
|
15
|
+
static getCurrentEpoch(): {
|
|
16
|
+
epoch: number;
|
|
17
|
+
round: number;
|
|
18
|
+
};
|
|
14
19
|
ensureServerCoinExists(peerIp: string): Promise<void>;
|
|
15
20
|
meltOutdatedEpochs(peerIp: string): Promise<void>;
|
|
16
21
|
static meltUntrackedStoreCoins(): Promise<void>;
|
|
17
22
|
private getServerCoinsForStore;
|
|
18
23
|
hasEpochCoinBeenCreated(currentEpoch: number, peerIp: string): Promise<boolean>;
|
|
19
|
-
static
|
|
24
|
+
static calculateEpochAndRound(currentTimestampUTC: Date): {
|
|
25
|
+
epoch: number;
|
|
26
|
+
round: number;
|
|
27
|
+
};
|
|
20
28
|
}
|
|
21
29
|
//# sourceMappingURL=ServerCoin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerCoin.d.ts","sourceRoot":"","sources":["../../src/blockchain/ServerCoin.ts"],"names":[],"mappings":"AACA,OAAO,EAML,UAAU,IAAI,gBAAgB,EAE/B,MAAM,
|
|
1
|
+
{"version":3,"file":"ServerCoin.d.ts","sourceRoot":"","sources":["../../src/blockchain/ServerCoin.ts"],"names":[],"mappings":"AACA,OAAO,EAML,UAAU,IAAI,gBAAgB,EAE/B,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAMrD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,gBAAuB,iBAAiB,eAEtC;gBAEU,OAAO,EAAE,MAAM;IAKd,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2DzD,kBAAkB,CAC7B,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAqBH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAoDjD,oBAAoB;IAerB,gBAAgB,CAC3B,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAoCP,mBAAmB,CAC9B,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAMP,kBAAkB,CAC7B,UAAU,GAAE,MAAU,EACtB,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAMP,wBAAwB,CACnC,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,MAAU,EACtB,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;WAMN,eAAe,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAKpD,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDrD,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WA+B1C,uBAAuB;YAkE7B,sBAAsB;IAWvB,uBAAuB,CAClC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;WAuBL,sBAAsB,CAAC,mBAAmB,EAAE,IAAI,GAAG;QAC/D,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf;CA2BF"}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ServerCoin = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const datalayer_driver_1 = require("datalayer-driver");
|
|
8
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
9
9
|
const FullNodePeer_1 = require("./FullNodePeer");
|
|
10
10
|
const coins_1 = require("./coins");
|
|
11
11
|
const Wallet_1 = require("./Wallet");
|
|
@@ -23,7 +23,7 @@ class ServerCoin {
|
|
|
23
23
|
const wallet = await Wallet_1.Wallet.load("default");
|
|
24
24
|
const publicSyntheticKey = await wallet.getPublicSyntheticKey();
|
|
25
25
|
const serverCoinCreationCoins = await (0, coins_1.selectUnspentCoins)(peer, BigInt(serverCoinCollateral), BigInt(1000000));
|
|
26
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
26
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
27
27
|
const epochBasedHint = (0, datalayer_driver_1.morphLauncherId)(Buffer.from(this.storeId, "hex"), BigInt(currentEpoch));
|
|
28
28
|
const newServerCoin = (0, datalayer_driver_1.createServerCoin)(publicSyntheticKey, serverCoinCreationCoins, epochBasedHint, [peerIp], BigInt(serverCoinCollateral), BigInt(1000000));
|
|
29
29
|
const combinedCoinSpends = [...newServerCoin.coinSpends];
|
|
@@ -94,13 +94,7 @@ class ServerCoin {
|
|
|
94
94
|
serverCoins = serverCoins.filter((coin) => coin.coin.parentCoinInfo !== serverCoin.parentCoinInfo);
|
|
95
95
|
await ServerCoin.serverCoinManager.setConfigValue(`${this.storeId}:${peerIp}`, serverCoins);
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
async sampleCurrentEpoch(sampleSize = 5, blacklist = []) {
|
|
99
|
-
const epoch = ServerCoin.getCurrentEpoch();
|
|
100
|
-
return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist);
|
|
101
|
-
}
|
|
102
|
-
// Sample server coins by epoch
|
|
103
|
-
async sampleServerCoinsByEpoch(epoch, sampleSize = 5, blacklist = []) {
|
|
97
|
+
async getAllEpochPeers(epoch, blacklist = []) {
|
|
104
98
|
const epochBasedHint = (0, datalayer_driver_1.morphLauncherId)(Buffer.from(this.storeId, "hex"), BigInt(epoch));
|
|
105
99
|
const peer = await FullNodePeer_1.FullNodePeer.connect();
|
|
106
100
|
const maxClvmCost = BigInt(11000000000);
|
|
@@ -118,18 +112,31 @@ class ServerCoin {
|
|
|
118
112
|
if (process.env.DIG_DEBUG === "1") {
|
|
119
113
|
console.log("Server Coin Peers: ", serverCoinPeers);
|
|
120
114
|
}
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
return Array.from(serverCoinPeers);
|
|
116
|
+
}
|
|
117
|
+
async getActiveEpochPeers(blacklist = []) {
|
|
118
|
+
const { epoch } = ServerCoin.getCurrentEpoch();
|
|
119
|
+
return this.getAllEpochPeers(epoch, blacklist);
|
|
120
|
+
}
|
|
121
|
+
// Sample server coins for the current epoch
|
|
122
|
+
async sampleCurrentEpoch(sampleSize = 5, blacklist = []) {
|
|
123
|
+
const { epoch } = ServerCoin.getCurrentEpoch();
|
|
124
|
+
return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist);
|
|
125
|
+
}
|
|
126
|
+
// Sample server coins by epoch
|
|
127
|
+
async sampleServerCoinsByEpoch(epoch, sampleSize = 5, blacklist = []) {
|
|
128
|
+
const serverCoinPeers = await this.getAllEpochPeers(epoch, blacklist);
|
|
129
|
+
return lodash_1.default.sampleSize(serverCoinPeers, sampleSize);
|
|
123
130
|
}
|
|
124
131
|
// Get the current epoch based on the current timestamp
|
|
125
132
|
static getCurrentEpoch() {
|
|
126
|
-
return ServerCoin.
|
|
133
|
+
return ServerCoin.calculateEpochAndRound(new Date());
|
|
127
134
|
}
|
|
128
135
|
// Ensure server coin exists for the current epoch
|
|
129
136
|
async ensureServerCoinExists(peerIp) {
|
|
130
137
|
try {
|
|
131
138
|
console.log(`Ensuring server coin exists for store ${this.storeId}...`);
|
|
132
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
139
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
133
140
|
const serverCoins = await this.getServerCoinsForStore(peerIp);
|
|
134
141
|
// Check if a server coin already exists for the current epoch
|
|
135
142
|
const existingCoin = serverCoins.find((coin) => coin.epoch === currentEpoch);
|
|
@@ -160,7 +167,7 @@ class ServerCoin {
|
|
|
160
167
|
// Melt outdated server coins
|
|
161
168
|
async meltOutdatedEpochs(peerIp) {
|
|
162
169
|
try {
|
|
163
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
170
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
164
171
|
let serverCoins = await this.getServerCoinsForStore(peerIp);
|
|
165
172
|
// Filter out coins that are not in the current epoch
|
|
166
173
|
const outdatedCoins = serverCoins.filter((coin) => coin.epoch < currentEpoch);
|
|
@@ -244,17 +251,23 @@ class ServerCoin {
|
|
|
244
251
|
}
|
|
245
252
|
}
|
|
246
253
|
// Static method to calculate the current epoch
|
|
247
|
-
static
|
|
254
|
+
static calculateEpochAndRound(currentTimestampUTC) {
|
|
248
255
|
const firstEpochStart = new Date(Date.UTC(2024, 8, 3, 0, 0)); // Sept 3, 2024, 00:00 UTC
|
|
249
256
|
// Convert the current timestamp to milliseconds
|
|
250
257
|
const currentTimestampMillis = currentTimestampUTC.getTime();
|
|
251
258
|
// Calculate the number of milliseconds in one epoch (7 days)
|
|
252
|
-
const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000;
|
|
259
|
+
const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
|
|
253
260
|
// Calculate the difference in milliseconds between the current timestamp and the first epoch start
|
|
254
261
|
const differenceMillis = currentTimestampMillis - firstEpochStart.getTime();
|
|
255
262
|
// Calculate the current epoch number
|
|
256
263
|
const epochNumber = Math.floor(differenceMillis / millisecondsInEpoch) + 1;
|
|
257
|
-
|
|
264
|
+
// Calculate the milliseconds elapsed since the start of the current epoch
|
|
265
|
+
const elapsedMillisInCurrentEpoch = differenceMillis % millisecondsInEpoch;
|
|
266
|
+
// Calculate the number of milliseconds in a round (10 minutes)
|
|
267
|
+
const millisecondsInRound = 10 * 60 * 1000; // 10 minutes in milliseconds
|
|
268
|
+
// Calculate the current round number
|
|
269
|
+
const roundNumber = Math.floor(elapsedMillisInCurrentEpoch / millisecondsInRound) + 1;
|
|
270
|
+
return { epoch: epochNumber, round: roundNumber };
|
|
258
271
|
}
|
|
259
272
|
}
|
|
260
273
|
exports.ServerCoin = ServerCoin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import { Peer, Coin, CoinSpend } from "datalayer-driver";
|
|
2
|
+
import { Peer, Coin, CoinSpend } from "@dignetwork/datalayer-driver";
|
|
3
3
|
export declare const DEFAULT_FEE_COIN_COST = 64000000;
|
|
4
4
|
export declare class Wallet {
|
|
5
5
|
private mnemonic;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wallet.d.ts","sourceRoot":"","sources":["../../src/blockchain/Wallet.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EASL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,
|
|
1
|
+
{"version":3,"file":"Wallet.d.ts","sourceRoot":"","sources":["../../src/blockchain/Wallet.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EASL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,8BAA8B,CAAC;AAMtC,eAAO,MAAM,qBAAqB,WAAa,CAAC;AAOhD,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO;WAKa,IAAI,CACtB,UAAU,GAAE,MAAkB,EAC9B,iBAAiB,GAAE,OAAc,GAChC,OAAO,CAAC,MAAM,CAAC;IAsBX,WAAW,IAAI,MAAM;WAOR,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;WAMpD,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;WAShE,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BhE,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKrC,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMxC,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKzC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMrC,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;WAK7B,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;WASlD,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;mBAU/B,oBAAoB;mBAWpB,mBAAmB;IAM3B,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO3D,2BAA2B,CACtC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IASN,kBAAkB,CAC7B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,GAAE,IAAI,EAAO,GACrB,OAAO,CAAC,IAAI,EAAE,CAAC;WAwCE,yBAAyB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;WAItF,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAOlF"}
|
|
@@ -38,7 +38,7 @@ const chia_root_resolver_1 = require("chia-root-resolver");
|
|
|
38
38
|
const chia_config_loader_1 = require("chia-config-loader");
|
|
39
39
|
const encryption_1 = require("../utils/encryption");
|
|
40
40
|
const buffer_1 = require("buffer");
|
|
41
|
-
const datalayer_driver_1 = require("datalayer-driver");
|
|
41
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
42
42
|
const config_1 = require("../utils/config");
|
|
43
43
|
const FileCache_1 = require("../utils/FileCache");
|
|
44
44
|
const KEYRING_FILE = "keyring.json";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Peer, Coin, CoinSpend } from "datalayer-driver";
|
|
1
|
+
import { Peer, Coin, CoinSpend } from "@dignetwork/datalayer-driver";
|
|
2
2
|
export declare const DEFAULT_FEE_COIN_COST = 64000000;
|
|
3
3
|
export declare const calculateFeeForCoinSpends: (peer: Peer, coinSpends: CoinSpend[] | null) => Promise<bigint>;
|
|
4
4
|
export declare const selectUnspentCoins: (peer: Peer, coinAmount: bigint, feeBigInt: bigint, omitCoins?: Coin[], walletName?: string) => Promise<Coin[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coins.d.ts","sourceRoot":"","sources":["../../src/blockchain/coins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,
|
|
1
|
+
{"version":3,"file":"coins.d.ts","sourceRoot":"","sources":["../../src/blockchain/coins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,8BAA8B,CAAC;AAKtC,eAAO,MAAM,qBAAqB,WAAa,CAAC;AAWhD,eAAO,MAAM,yBAAyB,SAC9B,IAAI,cACE,SAAS,EAAE,GAAG,IAAI,KAC7B,OAAO,CAAC,MAAM,CA4BhB,CAAC;AAEF,eAAO,MAAM,kBAAkB,SACvB,IAAI,cACE,MAAM,aACP,MAAM,cACN,IAAI,EAAE,eACL,MAAM,KACjB,OAAO,CAAC,IAAI,EAAE,CAoEhB,CAAC;AAGF,eAAO,MAAM,eAAe,SACpB,IAAI,UACF,MAAM,KACb,OAAO,CAAC,OAAO,CAWjB,CAAC"}
|
package/dist/blockchain/coins.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isCoinSpendable = exports.selectUnspentCoins = exports.calculateFeeForCoinSpends = exports.DEFAULT_FEE_COIN_COST = void 0;
|
|
4
|
-
const datalayer_driver_1 = require("datalayer-driver");
|
|
4
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
5
5
|
const Wallet_1 = require("./Wallet");
|
|
6
6
|
const config_1 = require("../utils/config");
|
|
7
7
|
const FileCache_1 = require("../utils/FileCache");
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,4 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./blockchain"), exports);
|
|
18
18
|
__exportStar(require("./DigNetwork"), exports);
|
|
19
19
|
__exportStar(require("./utils"), exports);
|
|
20
|
-
__exportStar(require("
|
|
20
|
+
__exportStar(require("./DataIntegrityTree"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAKrC,eAAO,MAAM,oBAAoB,qEACmC,CAAC;AAErE,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,eAAO,MAAM,sBAAsB,qEACiC,CAAC;AAErE,eAAO,MAAM,eAAe,QACqC,CAAC;AAElE,eAAO,MAAM,UAAU,QAAuC,CAAC;AAE/D,eAAO,MAAM,aAAa,QAAkC,CAAC;AAC7D,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MACN,CAAC;AAEjD,eAAO,MAAM,iBAAiB,YAAa,MAAM,KAAG,MACL,CAAC;AAEhD,eAAO,MAAM,mBAAmB,QAAO,IAItC,CAAC;AAEF,eAAO,MAAM,SAAS,WAAY,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAKrC,eAAO,MAAM,oBAAoB,qEACmC,CAAC;AAErE,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,eAAO,MAAM,sBAAsB,qEACiC,CAAC;AAErE,eAAO,MAAM,eAAe,QACqC,CAAC;AAElE,eAAO,MAAM,UAAU,QAAuC,CAAC;AAE/D,eAAO,MAAM,aAAa,QAAkC,CAAC;AAC7D,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MACN,CAAC;AAEjD,eAAO,MAAM,iBAAiB,YAAa,MAAM,KAAG,MACL,CAAC;AAEhD,eAAO,MAAM,mBAAmB,QAAO,IAItC,CAAC;AAEF,eAAO,MAAM,SAAS,WAAY,MAAM,KAAG,IAQ1C,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,MAAM,KAAG,IAQhD,CAAC;AAqBF,eAAO,MAAM,YAAY,YACd,MAAM,KACd;IACD,QAAQ,EAAE;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CAYH,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,QAAO,MAAM,EAOtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAa,OAAO,CAAC,MAAM,GAAG,IAAI,CAkC9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,SAS/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,YAAa,MAAM,KAAG,SAoBjD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,YACjB,MAAM,OACV,MAAM,SACJ,GAAG,KACT,IAMF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,YAAa,MAAM,OAAO,MAAM,KAAG,IAcjE,CAAC"}
|
package/dist/utils/config.js
CHANGED
|
@@ -49,9 +49,7 @@ const createInitialConfig = () => {
|
|
|
49
49
|
};
|
|
50
50
|
exports.createInitialConfig = createInitialConfig;
|
|
51
51
|
const setRemote = (remote) => {
|
|
52
|
-
|
|
53
|
-
throw new Error("Config file not found.");
|
|
54
|
-
}
|
|
52
|
+
(0, exports.ensureDigConfig)("");
|
|
55
53
|
const config = JSON.parse(fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8"));
|
|
56
54
|
config.remote = remote;
|
|
57
55
|
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4));
|
|
@@ -59,9 +57,7 @@ const setRemote = (remote) => {
|
|
|
59
57
|
};
|
|
60
58
|
exports.setRemote = setRemote;
|
|
61
59
|
const setActiveStore = (storeId) => {
|
|
62
|
-
|
|
63
|
-
throw new Error("Config file not found.");
|
|
64
|
-
}
|
|
60
|
+
(0, exports.ensureDigConfig)("");
|
|
65
61
|
const config = JSON.parse(fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8"));
|
|
66
62
|
config.active_store = storeId;
|
|
67
63
|
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4));
|
|
@@ -151,9 +147,7 @@ exports.getActiveStoreId = getActiveStoreId;
|
|
|
151
147
|
* @throws Will throw an error if the config file does not exist or cannot be parsed.
|
|
152
148
|
*/
|
|
153
149
|
const loadDigConfig = (baseDir) => {
|
|
154
|
-
|
|
155
|
-
throw new Error(`Configuration file not found at ${exports.CONFIG_FILE_PATH}`);
|
|
156
|
-
}
|
|
150
|
+
(0, exports.ensureDigConfig)("");
|
|
157
151
|
try {
|
|
158
152
|
const configContent = fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8");
|
|
159
153
|
const config = JSON.parse(configContent);
|
|
@@ -173,6 +167,7 @@ exports.loadDigConfig = loadDigConfig;
|
|
|
173
167
|
*/
|
|
174
168
|
const ensureDigConfig = (baseDir) => {
|
|
175
169
|
if (!fs.existsSync(exports.CONFIG_FILE_PATH)) {
|
|
170
|
+
fs.mkdirSync(exports.DIG_FOLDER_PATH, { recursive: true });
|
|
176
171
|
const defaultConfig = { deploy_dir: "./dist" };
|
|
177
172
|
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(defaultConfig, null, 4), "utf-8");
|
|
178
173
|
console.log(`Created new dig.config.json at ${exports.CONFIG_FILE_PATH}`);
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { DataIntegrityTree } from "
|
|
2
|
-
/**
|
|
3
|
-
* Recursively add all files in a directory to the Merkle tree, skipping the .dig, .git folders, and files in .gitignore.
|
|
4
|
-
* @param datalayer - The DataStoreManager instance.
|
|
5
|
-
* @param dirPath - The directory path.
|
|
6
|
-
* @param baseDir - The base directory for relative paths.
|
|
7
|
-
*/
|
|
1
|
+
import { DataIntegrityTree } from "../DataIntegrityTree";
|
|
8
2
|
export declare const addDirectory: (datalayer: DataIntegrityTree, dirPath: string, baseDir?: string) => Promise<void>;
|
|
9
3
|
/**
|
|
10
4
|
* Calculate the total size of the DIG_FOLDER_PATH
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,
|
|
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"}
|
|
@@ -27,15 +27,29 @@ 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
|
-
const fs = __importStar(require("fs"));
|
|
31
30
|
const path = __importStar(require("path"));
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
32
|
const ignore_1 = __importDefault(require("ignore"));
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
// Custom concurrency handler
|
|
34
|
+
const limitConcurrency = async (concurrencyLimit, tasks) => {
|
|
35
|
+
const executing = [];
|
|
36
|
+
for (const task of tasks) {
|
|
37
|
+
const p = task();
|
|
38
|
+
// Add the new task to the executing array
|
|
39
|
+
executing.push(p);
|
|
40
|
+
// When a task completes, remove it from the executing array
|
|
41
|
+
const cleanup = p.finally(() => {
|
|
42
|
+
executing.splice(executing.indexOf(cleanup), 1);
|
|
43
|
+
});
|
|
44
|
+
// Once the limit is reached, wait for one to complete
|
|
45
|
+
if (executing.length >= concurrencyLimit) {
|
|
46
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
47
|
+
await Promise.race(executing);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Wait for all remaining tasks to complete
|
|
51
|
+
return Promise.all(executing);
|
|
52
|
+
};
|
|
39
53
|
const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
40
54
|
const ig = (0, ignore_1.default)();
|
|
41
55
|
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
@@ -45,6 +59,7 @@ const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
|
45
59
|
ig.add(gitignoreContent);
|
|
46
60
|
}
|
|
47
61
|
const files = fs.readdirSync(dirPath);
|
|
62
|
+
const tasks = [];
|
|
48
63
|
for (const file of files) {
|
|
49
64
|
const filePath = path.join(dirPath, file);
|
|
50
65
|
const relativePath = path.relative(baseDir, filePath).replace(/\\/g, "/");
|
|
@@ -54,18 +69,22 @@ const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
|
54
69
|
}
|
|
55
70
|
const stat = fs.statSync(filePath);
|
|
56
71
|
if (stat.isDirectory()) {
|
|
57
|
-
|
|
72
|
+
// Recursively process the directory
|
|
73
|
+
tasks.push(() => (0, exports.addDirectory)(datalayer, filePath, baseDir));
|
|
58
74
|
}
|
|
59
75
|
else {
|
|
60
|
-
|
|
76
|
+
// Add a task for each file to be processed
|
|
77
|
+
tasks.push(() => new Promise((resolve, reject) => {
|
|
61
78
|
const stream = fs.createReadStream(filePath);
|
|
62
79
|
datalayer
|
|
63
80
|
.upsertKey(stream, Buffer.from(relativePath).toString("hex"))
|
|
64
|
-
.then(resolve)
|
|
81
|
+
.then(() => resolve())
|
|
65
82
|
.catch(reject);
|
|
66
|
-
});
|
|
83
|
+
}));
|
|
67
84
|
}
|
|
68
85
|
}
|
|
86
|
+
// Run tasks with limited concurrency (set the concurrency limit as needed)
|
|
87
|
+
await limitConcurrency(10, tasks); // Adjust 10 based on your system limits
|
|
69
88
|
};
|
|
70
89
|
exports.addDirectory = addDirectory;
|
|
71
90
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dignetwork/dig-sdk",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.30",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dignetwork/
|
|
28
|
+
"@dignetwork/datalayer-driver": "^0.1.24",
|
|
29
29
|
"bip39": "^3.1.0",
|
|
30
30
|
"chia-bls": "^1.0.2",
|
|
31
31
|
"chia-config-loader": "^1.0.1",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"chia-wallet": "^1.0.18",
|
|
35
35
|
"cli-progress": "^3.12.0",
|
|
36
36
|
"crypto-js": "^4.2.0",
|
|
37
|
-
"datalayer-driver": "^0.1.21",
|
|
38
37
|
"fs-extra": "^11.2.0",
|
|
39
38
|
"ignore": "^5.3.2",
|
|
40
39
|
"inquirer": "^10.1.8",
|
|
@@ -42,6 +41,7 @@
|
|
|
42
41
|
"merkletreejs": "^0.4.0",
|
|
43
42
|
"nanospinner": "^1.1.0",
|
|
44
43
|
"nconf": "^0.12.1",
|
|
44
|
+
"p-limit": "^6.1.0",
|
|
45
45
|
"superagent": "^10.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|