@dignetwork/dig-sdk 0.0.1-alpha.125 → 0.0.1-alpha.127
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/DigNetwork.d.ts +1 -0
- package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
- package/dist/DigNetwork/DigNetwork.js +3 -0
- package/dist/blockchain/DataStore.d.ts +5 -7
- package/dist/blockchain/DataStore.d.ts.map +1 -1
- package/dist/blockchain/DataStore.js +25 -135
- package/dist/blockchain/FullNodePeer.d.ts +93 -9
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +314 -137
- package/dist/blockchain/StoreMonitorRegistry.d.ts +85 -0
- package/dist/blockchain/StoreMonitorRegistry.d.ts.map +1 -0
- package/dist/blockchain/StoreMonitorRegistry.js +242 -0
- package/dist/blockchain/index.d.ts +1 -0
- package/dist/blockchain/index.d.ts.map +1 -1
- package/dist/blockchain/index.js +1 -0
- package/package.json +1 -1
- package/dist/blockchain/StoreInfoCacheUpdater.d.ts +0 -16
- package/dist/blockchain/StoreInfoCacheUpdater.d.ts.map +0 -1
- package/dist/blockchain/StoreInfoCacheUpdater.js +0 -242
|
@@ -6,6 +6,7 @@ export declare class DigNetwork {
|
|
|
6
6
|
private peerBlacklist;
|
|
7
7
|
constructor(storeId: string);
|
|
8
8
|
static subscribeToStore(storeId: string): Promise<void>;
|
|
9
|
+
static getUdiContent(udi: string): Promise<void>;
|
|
9
10
|
static findPeerWithStoreKey(storeId: string, rootHash: string, key?: string, intialBlackList?: string[]): Promise<DigPeer | null>;
|
|
10
11
|
static unsubscribeFromStore(storeId: string): void;
|
|
11
12
|
syncStoreFromPeers(maxRootsToProcess?: number): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DigNetwork.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigNetwork.ts"],"names":[],"mappings":"AAEA,OAA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,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5C,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiG7D,mBAAmB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAUvD"}
|
|
@@ -46,6 +46,9 @@ class DigNetwork {
|
|
|
46
46
|
const digNetwork = new DigNetwork(storeId);
|
|
47
47
|
await digNetwork.syncStoreFromPeers();
|
|
48
48
|
}
|
|
49
|
+
static async getUdiContent(udi) {
|
|
50
|
+
// TODO: Implement this method
|
|
51
|
+
}
|
|
49
52
|
static async findPeerWithStoreKey(storeId, rootHash, key, intialBlackList = []) {
|
|
50
53
|
const peerBlackList = intialBlackList;
|
|
51
54
|
const serverCoin = new blockchain_1.ServerCoin(storeId);
|
|
@@ -35,13 +35,11 @@ export declare class DataStore {
|
|
|
35
35
|
private static calculateFolderSize;
|
|
36
36
|
static getAllStores(): DataStore[];
|
|
37
37
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*/
|
|
44
|
-
static monitorStoreIndefinitely(storeId: string): Promise<void>;
|
|
38
|
+
* Fetches the latest coin information using the StoreMonitorRegistry.
|
|
39
|
+
* Registers the storeId if it's not already registered, retrieves the cached value, and returns it.
|
|
40
|
+
*
|
|
41
|
+
* @returns {Promise<{ latestStore: DataStoreDriver; latestHeight: number; latestHash: Buffer }>}
|
|
42
|
+
*/
|
|
45
43
|
fetchCoinInfo(): Promise<{
|
|
46
44
|
latestStore: DataStoreDriver;
|
|
47
45
|
latestHeight: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataStore.d.ts","sourceRoot":"","sources":["../../src/blockchain/DataStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,SAAS,IAAI,eAAe,EAE5B,iBAAiB,EAIlB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"Data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EAAE,MAAM,CAAC;KACpB,CAAC;IAkCW,wBAAwB,IAAI,OAAO,CAAC;QAC/C,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IAiBW,iBAAiB,IAAI,OAAO,CAAC;QACxC,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;YA0BY,iBAAiB;IAYlB,cAAc,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IA4C/D,oBAAoB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAexD,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAKzC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAM5B,uBAAuB,CAClC,kBAAkB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAAC,OAAO,CAAC;IAkBN,cAAc,CACzB,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,eAAe,CAAC;IAgD3B;;;;;OAKG;IACU,qBAAqB,CAChC,QAAQ,EAAE,MAAM,EAChB,kBAAkB,GAAE,OAAe,GAClC,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CA6C7C"}
|
|
@@ -20,7 +20,7 @@ const FileCache_1 = require("../utils/FileCache");
|
|
|
20
20
|
const DataStoreSerializer_1 = require("./DataStoreSerializer");
|
|
21
21
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
22
22
|
const config_2 = require("../utils/config");
|
|
23
|
-
const
|
|
23
|
+
const StoreMonitorRegistry_1 = require("./StoreMonitorRegistry");
|
|
24
24
|
// Initialize the cache with a TTL of 180 seconds (3 minutes)
|
|
25
25
|
const rootHistoryCache = new node_cache_1.default({ stdTTL: 180 });
|
|
26
26
|
const stat = (0, util_1.promisify)(fs_1.default.stat);
|
|
@@ -39,9 +39,6 @@ class DataStore {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
this.tree = new DataIntegrityTree_1.DataIntegrityTree(storeId, _options);
|
|
42
|
-
if (!utils_1.Environment.CLI_MODE) {
|
|
43
|
-
DataStore.monitorStoreIndefinitely(this.storeId);
|
|
44
|
-
}
|
|
45
42
|
}
|
|
46
43
|
get StoreId() {
|
|
47
44
|
return this.storeId;
|
|
@@ -205,143 +202,36 @@ class DataStore {
|
|
|
205
202
|
return storIds.map((storeId) => DataStore.from(storeId));
|
|
206
203
|
}
|
|
207
204
|
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
*/
|
|
214
|
-
static async monitorStoreIndefinitely(storeId) {
|
|
215
|
-
// Check if a monitor is already running for this storeId
|
|
216
|
-
if (this.activeMonitors.get(storeId)) {
|
|
217
|
-
console.log("Monitor:", `Monitor already running for storeId: ${storeId}`);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
// Set the monitor as active
|
|
221
|
-
this.activeMonitors.set(storeId, true);
|
|
222
|
-
const storeCoinCache = new FileCache_1.FileCache(`stores`);
|
|
223
|
-
// Clear the cache at the start
|
|
224
|
-
console.log("Monitor:", `Clearing cache for storeId: ${storeId}`);
|
|
225
|
-
storeCoinCache.delete(storeId);
|
|
226
|
-
while (true) {
|
|
227
|
-
try {
|
|
228
|
-
console.log("Monitor:", `Connecting to peer for storeId: ${storeId}`);
|
|
229
|
-
const peer = await FullNodePeer_1.FullNodePeer.connect();
|
|
230
|
-
const cachedInfo = storeCoinCache.get(storeId);
|
|
231
|
-
if (cachedInfo) {
|
|
232
|
-
// Log cached store info retrieval
|
|
233
|
-
console.log("Monitor:", `Cached store info found for storeId: ${storeId}, syncing...`);
|
|
234
|
-
// Deserialize cached info and wait for the coin to be spent
|
|
235
|
-
const previousStore = DataStoreSerializer_1.DataStoreSerializer.deserialize({
|
|
236
|
-
latestStore: cachedInfo.latestStore,
|
|
237
|
-
latestHeight: cachedInfo.latestHeight.toString(),
|
|
238
|
-
latestHash: cachedInfo.latestHash,
|
|
239
|
-
});
|
|
240
|
-
console.log("Monitor:", `Waiting for coin to be spent for storeId: ${storeId}...`);
|
|
241
|
-
const dataStore = DataStore.from(storeId);
|
|
242
|
-
const { createdAtHeight, createdAtHash } = await dataStore.getCreationHeight();
|
|
243
|
-
await peer.waitForCoinToBeSpent((0, datalayer_driver_1.getCoinId)(previousStore.latestStore.coin), createdAtHeight, createdAtHash);
|
|
244
|
-
// Sync store and get updated details
|
|
245
|
-
console.log("Monitor:", `Syncing store for storeId: ${storeId}`);
|
|
246
|
-
const { latestStore, latestHeight } = await peer.syncStore(previousStore.latestStore, createdAtHeight, createdAtHash, false);
|
|
247
|
-
const latestHash = await peer.getHeaderHash(latestHeight);
|
|
248
|
-
console.log("Monitor:", `Store synced for storeId: ${storeId}, coin id: ${(0, datalayer_driver_1.getCoinId)(latestStore.coin).toString("hex")}`);
|
|
249
|
-
// Serialize and cache the updated store info
|
|
250
|
-
const serializedLatestStore = new DataStoreSerializer_1.DataStoreSerializer(latestStore, latestHeight, latestHash).serialize();
|
|
251
|
-
console.log("Monitor:", `Caching updated store info for storeId: ${storeId}`);
|
|
252
|
-
storeCoinCache.set(storeId, {
|
|
253
|
-
latestStore: serializedLatestStore,
|
|
254
|
-
latestHeight,
|
|
255
|
-
latestHash: latestHash.toString("hex"),
|
|
256
|
-
});
|
|
257
|
-
continue; // Continue monitoring
|
|
258
|
-
}
|
|
259
|
-
// If no cached info exists, log and sync from the creation height
|
|
260
|
-
console.log("Monitor:", `No cached info found for storeId: ${storeId}. Retrieving creation height.`);
|
|
261
|
-
const dataStore = DataStore.from(storeId);
|
|
262
|
-
const { createdAtHeight, createdAtHash } = await dataStore.getCreationHeight();
|
|
263
|
-
// Sync store from the peer using launcher ID
|
|
264
|
-
console.log("Monitor:", `Syncing store from launcher ID for storeId: ${storeId}`);
|
|
265
|
-
const { latestStore, latestHeight } = await peer.syncStoreFromLauncherId(Buffer.from(storeId, "hex"), createdAtHeight, createdAtHash, false);
|
|
266
|
-
const latestHash = await peer.getHeaderHash(latestHeight);
|
|
267
|
-
// Serialize and cache the new store info
|
|
268
|
-
const serializedLatestStore = new DataStoreSerializer_1.DataStoreSerializer(latestStore, latestHeight, latestHash).serialize();
|
|
269
|
-
console.log("Monitor:", `Caching new store info for storeId: ${storeId}`);
|
|
270
|
-
storeCoinCache.set(storeId, {
|
|
271
|
-
latestStore: serializedLatestStore,
|
|
272
|
-
latestHeight,
|
|
273
|
-
latestHash: latestHash.toString("hex"),
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
catch (error) {
|
|
277
|
-
console.error("Monitor:", `Error in monitorStoreIndefinitely for storeId: ${storeId} - ${error.message}`);
|
|
278
|
-
// Delay before restarting to avoid rapid retries
|
|
279
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
205
|
+
* Fetches the latest coin information using the StoreMonitorRegistry.
|
|
206
|
+
* Registers the storeId if it's not already registered, retrieves the cached value, and returns it.
|
|
207
|
+
*
|
|
208
|
+
* @returns {Promise<{ latestStore: DataStoreDriver; latestHeight: number; latestHash: Buffer }>}
|
|
209
|
+
*/
|
|
283
210
|
async fetchCoinInfo() {
|
|
211
|
+
const storeMonitor = StoreMonitorRegistry_1.StoreMonitorRegistry.getInstance();
|
|
284
212
|
try {
|
|
285
|
-
//
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const { latestStore: previousInfo } = DataStoreSerializer_1.DataStoreSerializer.deserialize({
|
|
294
|
-
latestStore: serializedStore,
|
|
295
|
-
latestHeight: previousHeight.toString(),
|
|
296
|
-
latestHash: previousHash,
|
|
297
|
-
});
|
|
298
|
-
// Sync with peer if necessary
|
|
299
|
-
const peer = await FullNodePeer_1.FullNodePeer.connect();
|
|
300
|
-
const { latestStore, latestHeight } = await peer.syncStore(previousInfo, previousHeight, Buffer.from(previousHash, "hex"), false);
|
|
301
|
-
const latestHash = await peer.getHeaderHash(latestHeight);
|
|
302
|
-
// Serialize the store data for caching
|
|
303
|
-
const serializedLatestStore = new DataStoreSerializer_1.DataStoreSerializer(latestStore, latestHeight, latestHash).serialize();
|
|
304
|
-
// Cache updated store info
|
|
305
|
-
storeCoinCache.set(this.storeId, {
|
|
306
|
-
latestStore: serializedLatestStore,
|
|
307
|
-
latestHeight,
|
|
308
|
-
latestHash: latestHash.toString("hex"),
|
|
309
|
-
});
|
|
310
|
-
return { latestStore, latestHeight, latestHash };
|
|
311
|
-
}
|
|
312
|
-
catch {
|
|
313
|
-
// Return cached info if sync fails
|
|
314
|
-
const { latestStore, latestHeight, latestHash } = DataStoreSerializer_1.DataStoreSerializer.deserialize({
|
|
315
|
-
latestStore: cachedInfo.latestStore,
|
|
316
|
-
latestHeight: cachedInfo.latestHeight.toString(),
|
|
317
|
-
latestHash: cachedInfo.latestHash,
|
|
318
|
-
});
|
|
319
|
-
return {
|
|
320
|
-
latestStore,
|
|
321
|
-
latestHeight,
|
|
322
|
-
latestHash: latestHash,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
213
|
+
// Register the storeId with a no-op callback. If already registered, the registry will handle it.
|
|
214
|
+
await storeMonitor.registerStore(this.storeId, () => {
|
|
215
|
+
// No operation callback since we're fetching the cache directly
|
|
216
|
+
});
|
|
217
|
+
// Retrieve the latest cached store information
|
|
218
|
+
const cachedInfo = await storeMonitor.getLatestCache(this.storeId);
|
|
219
|
+
if (!cachedInfo) {
|
|
220
|
+
throw new Error(`No cached info found for storeId: ${this.storeId}`);
|
|
325
221
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const { latestStore, latestHeight } = await peer.syncStoreFromLauncherId(Buffer.from(this.storeId, "hex"), createdAtHeight, createdAtHash, false);
|
|
331
|
-
const latestHash = await peer.getHeaderHash(latestHeight);
|
|
332
|
-
// Serialize the latest store info for caching
|
|
333
|
-
const serializedLatestStore = new DataStoreSerializer_1.DataStoreSerializer(latestStore, latestHeight, latestHash).serialize();
|
|
334
|
-
// Cache the latest store info
|
|
335
|
-
storeCoinCache.set(this.storeId, {
|
|
336
|
-
latestStore: serializedLatestStore,
|
|
337
|
-
latestHeight,
|
|
338
|
-
latestHash: latestHash.toString("hex"),
|
|
222
|
+
const deserializedStore = DataStoreSerializer_1.DataStoreSerializer.deserialize({
|
|
223
|
+
latestStore: cachedInfo.latestStore,
|
|
224
|
+
latestHeight: cachedInfo.latestHeight.toString(),
|
|
225
|
+
latestHash: cachedInfo.latestHash
|
|
339
226
|
});
|
|
340
|
-
return {
|
|
227
|
+
return {
|
|
228
|
+
latestStore: deserializedStore.latestStore,
|
|
229
|
+
latestHeight: deserializedStore.latestHeight,
|
|
230
|
+
latestHash: deserializedStore.latestHash,
|
|
231
|
+
};
|
|
341
232
|
}
|
|
342
233
|
catch (error) {
|
|
343
|
-
|
|
344
|
-
throw error;
|
|
234
|
+
throw new Error(`Failed to fetch coin info for storeId ${this.storeId}: ${error.message}`);
|
|
345
235
|
}
|
|
346
236
|
}
|
|
347
237
|
async cacheStoreCreationHeight() {
|
|
@@ -1,25 +1,109 @@
|
|
|
1
1
|
import { Peer } from "@dignetwork/datalayer-driver";
|
|
2
|
+
/**
|
|
3
|
+
* FullNodePeer manages connections to full nodes, prioritizing certain peers and handling reliability.
|
|
4
|
+
*/
|
|
2
5
|
export declare class FullNodePeer {
|
|
3
|
-
private static cachedPeer;
|
|
4
|
-
private static memoizedFetchNewPeerIPs;
|
|
5
6
|
private peer;
|
|
6
|
-
private static
|
|
7
|
+
private static instance;
|
|
8
|
+
private static cachedPeer;
|
|
9
|
+
private static cooldownCache;
|
|
10
|
+
private static peerWeights;
|
|
11
|
+
private static prioritizedPeers;
|
|
12
|
+
private static peerInfos;
|
|
13
|
+
private static peerIPCache;
|
|
7
14
|
private constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the singleton instance of FullNodePeer.
|
|
17
|
+
* @returns {FullNodePeer} The singleton instance.
|
|
18
|
+
*/
|
|
19
|
+
static getInstance(): FullNodePeer;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the singleton instance by connecting to the best peer.
|
|
22
|
+
*/
|
|
23
|
+
initialize(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Connects and returns the best available peer.
|
|
26
|
+
* Implements singleton behavior.
|
|
27
|
+
* @returns {Promise<Peer>} The connected Peer instance.
|
|
28
|
+
*/
|
|
8
29
|
static connect(): Promise<Peer>;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if a given port on a host is reachable.
|
|
32
|
+
* @param {string} host - The host IP address.
|
|
33
|
+
* @param {number} port - The port number.
|
|
34
|
+
* @param {number} timeout - Connection timeout in milliseconds.
|
|
35
|
+
* @returns {Promise<boolean>} Whether the port is reachable.
|
|
36
|
+
*/
|
|
9
37
|
private static isPortReachable;
|
|
38
|
+
/**
|
|
39
|
+
* Validates an IPv4 address.
|
|
40
|
+
* @param {string} ip - The IP address to validate.
|
|
41
|
+
* @returns {boolean} Whether the IP address is valid.
|
|
42
|
+
*/
|
|
10
43
|
private static isValidIpAddress;
|
|
11
44
|
/**
|
|
12
|
-
* Retrieves the TRUSTED_FULLNODE IP from the environment
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @returns {string | null} The valid IP address or null if invalid
|
|
45
|
+
* Retrieves the TRUSTED_FULLNODE IP from the environment and verifies its validity.
|
|
46
|
+
* @returns {string | null} The trusted full node IP or null if invalid.
|
|
16
47
|
*/
|
|
17
48
|
private static getTrustedFullNode;
|
|
49
|
+
/**
|
|
50
|
+
* Fetches new peer IPs from DNS introducers and prioritized hosts.
|
|
51
|
+
* Utilizes caching to avoid redundant DNS resolutions.
|
|
52
|
+
* @returns {Promise<string[]>} An array of reachable peer IPs.
|
|
53
|
+
*/
|
|
18
54
|
private static fetchNewPeerIPs;
|
|
55
|
+
/**
|
|
56
|
+
* Shuffles an array using the Fisher-Yates algorithm.
|
|
57
|
+
* @param {T[]} array - The array to shuffle.
|
|
58
|
+
* @returns {T[]} The shuffled array.
|
|
59
|
+
*/
|
|
60
|
+
private static shuffleArray;
|
|
61
|
+
/**
|
|
62
|
+
* Initializes the peer weights map.
|
|
63
|
+
* Assigns higher initial weights to prioritized peers.
|
|
64
|
+
* @param {string[]} peerIPs - An array of peer IPs.
|
|
65
|
+
*/
|
|
66
|
+
private static initializePeerWeights;
|
|
67
|
+
/**
|
|
68
|
+
* Selects a peer based on weighted random selection.
|
|
69
|
+
* Prioritized peers have higher weights.
|
|
70
|
+
* @returns {string} The selected peer IP.
|
|
71
|
+
*/
|
|
72
|
+
private static selectPeerByWeight;
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves all reachable peer IPs, excluding those in cooldown.
|
|
75
|
+
* @returns {Promise<string[]>} An array of reachable peer IPs.
|
|
76
|
+
*/
|
|
19
77
|
private static getPeerIPs;
|
|
20
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Initializes the peer weights based on prioritization and reliability.
|
|
80
|
+
* @param {string[]} peerIPs - An array of peer IPs.
|
|
81
|
+
*/
|
|
82
|
+
private static setupPeers;
|
|
83
|
+
/**
|
|
84
|
+
* Connects to the best available peer based on weighted selection and reliability.
|
|
85
|
+
* @returns {Promise<Peer>} The connected Peer instance.
|
|
86
|
+
*/
|
|
21
87
|
private static getBestPeer;
|
|
22
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Creates a proxy for the peer to handle errors and implement retries.
|
|
90
|
+
* @param {Peer} peer - The Peer instance.
|
|
91
|
+
* @param {string} peerIP - The IP address of the peer.
|
|
92
|
+
* @param {number} [retryCount=0] - The current retry attempt.
|
|
93
|
+
* @returns {Peer} The proxied Peer instance.
|
|
94
|
+
*/
|
|
95
|
+
private static createPeerProxy;
|
|
96
|
+
/**
|
|
97
|
+
* Extracts the IP address from a Peer instance.
|
|
98
|
+
* @param {Peer} peer - The Peer instance.
|
|
99
|
+
* @returns {string | null} The extracted IP address or null if not found.
|
|
100
|
+
*/
|
|
101
|
+
private static extractPeerIP;
|
|
102
|
+
/**
|
|
103
|
+
* Waits for a coin to be confirmed (spent) on the blockchain.
|
|
104
|
+
* @param {Buffer} parentCoinInfo - The parent coin information.
|
|
105
|
+
* @returns {Promise<boolean>} Whether the coin was confirmed.
|
|
106
|
+
*/
|
|
23
107
|
static waitForConfirmation(parentCoinInfo: Buffer): Promise<boolean>;
|
|
24
108
|
}
|
|
25
109
|
//# sourceMappingURL=FullNodePeer.d.ts.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAO,MAAM,8BAA8B,CAAC;AAiCzD;;GAEG;AACH,qBAAa,YAAY;IAuBH,OAAO,CAAC,IAAI;IArBhC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA6B;IAGpD,OAAO,CAAC,MAAM,CAAC,UAAU,CAAkD;IAG3E,OAAO,CAAC,MAAM,CAAC,aAAa,CAAuD;IAGnF,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;IAEP;;;OAGG;WACW,WAAW,IAAI,YAAY;IAOzC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxC;;;;OAIG;WACiB,OAAO,IAAI,OAAO,CAAC,IAAI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