@leofcoin/chain 1.8.23 → 1.8.25
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/exports/browser/chain.js +35 -20
- package/exports/chain.js +35 -20
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -5509,7 +5509,8 @@ class State extends Contract {
|
|
|
5509
5509
|
try {
|
|
5510
5510
|
const result = await peer.request(node.encoded);
|
|
5511
5511
|
debug$1({ result });
|
|
5512
|
-
|
|
5512
|
+
console.log({ result });
|
|
5513
|
+
return { result: new LastBlockMessage(result), peer };
|
|
5513
5514
|
}
|
|
5514
5515
|
catch (error) {
|
|
5515
5516
|
const peerId = peer?.peerId || peer?.id || peer?.address || 'unknown';
|
|
@@ -6314,24 +6315,11 @@ class Chain extends VersionControl {
|
|
|
6314
6315
|
const node = await this.#prepareRequest(request);
|
|
6315
6316
|
try {
|
|
6316
6317
|
let response = await peer.request(node.encoded);
|
|
6317
|
-
console.log({ rawResponse: response });
|
|
6318
|
-
console.log('raw response received, decoding...');
|
|
6319
|
-
console.log({ responseBytes: response });
|
|
6320
6318
|
response = await new globalThis.peernet.protos['peernet-response'](response);
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
if (typeof responseData === 'string') {
|
|
6324
|
-
console.warn(`Deprecated: ${request} response is a string, attempting to parse as JSON...`);
|
|
6325
|
-
try {
|
|
6326
|
-
responseData = JSON.parse(responseData);
|
|
6327
|
-
}
|
|
6328
|
-
catch { }
|
|
6319
|
+
if (!(response.decoded.response instanceof Uint8Array)) {
|
|
6320
|
+
console.warn(`Deprecated: ${response.decoded.response} is not an Uint8Array`);
|
|
6329
6321
|
}
|
|
6330
|
-
|
|
6331
|
-
console.warn(`Deprecated: ${request} response is not a Uint8Array and will be ignored.`);
|
|
6332
|
-
return responseData;
|
|
6333
|
-
}
|
|
6334
|
-
return responseData;
|
|
6322
|
+
return response.decoded.response;
|
|
6335
6323
|
}
|
|
6336
6324
|
catch (error) {
|
|
6337
6325
|
const peerId = peer?.peerId || peer?.id || peer?.address || 'unknown';
|
|
@@ -6340,7 +6328,18 @@ class Chain extends VersionControl {
|
|
|
6340
6328
|
}
|
|
6341
6329
|
}
|
|
6342
6330
|
async getPeerTransactionPool(peer) {
|
|
6343
|
-
|
|
6331
|
+
let transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
|
|
6332
|
+
if (transactionsInPool instanceof Uint8Array) {
|
|
6333
|
+
try {
|
|
6334
|
+
const text = new TextDecoder().decode(transactionsInPool);
|
|
6335
|
+
transactionsInPool = JSON.parse(text);
|
|
6336
|
+
}
|
|
6337
|
+
catch (e) {
|
|
6338
|
+
return [];
|
|
6339
|
+
}
|
|
6340
|
+
}
|
|
6341
|
+
if (!Array.isArray(transactionsInPool))
|
|
6342
|
+
return [];
|
|
6344
6343
|
// todo iterate vs getting all keys?
|
|
6345
6344
|
const transactions = await globalThis.transactionPoolStore.keys();
|
|
6346
6345
|
const transactionsToGet = [];
|
|
@@ -6397,7 +6396,15 @@ class Chain extends VersionControl {
|
|
|
6397
6396
|
if (lastBlock) {
|
|
6398
6397
|
if (!this.lastBlock || higherThenCurrentLocal) {
|
|
6399
6398
|
try {
|
|
6400
|
-
|
|
6399
|
+
let knownBlocksResponse = await this.#makeRequest(peer, 'knownBlocks');
|
|
6400
|
+
if (knownBlocksResponse instanceof Uint8Array) {
|
|
6401
|
+
try {
|
|
6402
|
+
knownBlocksResponse = JSON.parse(new TextDecoder().decode(knownBlocksResponse));
|
|
6403
|
+
}
|
|
6404
|
+
catch (e) {
|
|
6405
|
+
console.log(e);
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6401
6408
|
if (knownBlocksResponse.blocks)
|
|
6402
6409
|
for (const hash of knownBlocksResponse.blocks) {
|
|
6403
6410
|
this.wantList.push(hash);
|
|
@@ -6433,7 +6440,15 @@ class Chain extends VersionControl {
|
|
|
6433
6440
|
}
|
|
6434
6441
|
}, 3000);
|
|
6435
6442
|
try {
|
|
6436
|
-
|
|
6443
|
+
let stateInfo = await this.#makeRequest(peer, 'stateInfo');
|
|
6444
|
+
if (stateInfo instanceof Uint8Array) {
|
|
6445
|
+
try {
|
|
6446
|
+
stateInfo = JSON.parse(new TextDecoder().decode(stateInfo));
|
|
6447
|
+
}
|
|
6448
|
+
catch (e) {
|
|
6449
|
+
console.log(e);
|
|
6450
|
+
}
|
|
6451
|
+
}
|
|
6437
6452
|
await this.syncChain(lastBlock);
|
|
6438
6453
|
this.machine.states.info = stateInfo;
|
|
6439
6454
|
}
|
package/exports/chain.js
CHANGED
|
@@ -1650,7 +1650,8 @@ class State extends Contract {
|
|
|
1650
1650
|
try {
|
|
1651
1651
|
const result = await peer.request(node.encoded);
|
|
1652
1652
|
debug$1({ result });
|
|
1653
|
-
|
|
1653
|
+
console.log({ result });
|
|
1654
|
+
return { result: new LastBlockMessage(result), peer };
|
|
1654
1655
|
}
|
|
1655
1656
|
catch (error) {
|
|
1656
1657
|
const peerId = peer?.peerId || peer?.id || peer?.address || 'unknown';
|
|
@@ -2455,24 +2456,11 @@ class Chain extends VersionControl {
|
|
|
2455
2456
|
const node = await this.#prepareRequest(request);
|
|
2456
2457
|
try {
|
|
2457
2458
|
let response = await peer.request(node.encoded);
|
|
2458
|
-
console.log({ rawResponse: response });
|
|
2459
|
-
console.log('raw response received, decoding...');
|
|
2460
|
-
console.log({ responseBytes: response });
|
|
2461
2459
|
response = await new globalThis.peernet.protos['peernet-response'](response);
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
if (typeof responseData === 'string') {
|
|
2465
|
-
console.warn(`Deprecated: ${request} response is a string, attempting to parse as JSON...`);
|
|
2466
|
-
try {
|
|
2467
|
-
responseData = JSON.parse(responseData);
|
|
2468
|
-
}
|
|
2469
|
-
catch { }
|
|
2460
|
+
if (!(response.decoded.response instanceof Uint8Array)) {
|
|
2461
|
+
console.warn(`Deprecated: ${response.decoded.response} is not an Uint8Array`);
|
|
2470
2462
|
}
|
|
2471
|
-
|
|
2472
|
-
console.warn(`Deprecated: ${request} response is not a Uint8Array and will be ignored.`);
|
|
2473
|
-
return responseData;
|
|
2474
|
-
}
|
|
2475
|
-
return responseData;
|
|
2463
|
+
return response.decoded.response;
|
|
2476
2464
|
}
|
|
2477
2465
|
catch (error) {
|
|
2478
2466
|
const peerId = peer?.peerId || peer?.id || peer?.address || 'unknown';
|
|
@@ -2481,7 +2469,18 @@ class Chain extends VersionControl {
|
|
|
2481
2469
|
}
|
|
2482
2470
|
}
|
|
2483
2471
|
async getPeerTransactionPool(peer) {
|
|
2484
|
-
|
|
2472
|
+
let transactionsInPool = await this.#makeRequest(peer, 'transactionPool');
|
|
2473
|
+
if (transactionsInPool instanceof Uint8Array) {
|
|
2474
|
+
try {
|
|
2475
|
+
const text = new TextDecoder().decode(transactionsInPool);
|
|
2476
|
+
transactionsInPool = JSON.parse(text);
|
|
2477
|
+
}
|
|
2478
|
+
catch (e) {
|
|
2479
|
+
return [];
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
if (!Array.isArray(transactionsInPool))
|
|
2483
|
+
return [];
|
|
2485
2484
|
// todo iterate vs getting all keys?
|
|
2486
2485
|
const transactions = await globalThis.transactionPoolStore.keys();
|
|
2487
2486
|
const transactionsToGet = [];
|
|
@@ -2538,7 +2537,15 @@ class Chain extends VersionControl {
|
|
|
2538
2537
|
if (lastBlock) {
|
|
2539
2538
|
if (!this.lastBlock || higherThenCurrentLocal) {
|
|
2540
2539
|
try {
|
|
2541
|
-
|
|
2540
|
+
let knownBlocksResponse = await this.#makeRequest(peer, 'knownBlocks');
|
|
2541
|
+
if (knownBlocksResponse instanceof Uint8Array) {
|
|
2542
|
+
try {
|
|
2543
|
+
knownBlocksResponse = JSON.parse(new TextDecoder().decode(knownBlocksResponse));
|
|
2544
|
+
}
|
|
2545
|
+
catch (e) {
|
|
2546
|
+
console.log(e);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2542
2549
|
if (knownBlocksResponse.blocks)
|
|
2543
2550
|
for (const hash of knownBlocksResponse.blocks) {
|
|
2544
2551
|
this.wantList.push(hash);
|
|
@@ -2574,7 +2581,15 @@ class Chain extends VersionControl {
|
|
|
2574
2581
|
}
|
|
2575
2582
|
}, 3000);
|
|
2576
2583
|
try {
|
|
2577
|
-
|
|
2584
|
+
let stateInfo = await this.#makeRequest(peer, 'stateInfo');
|
|
2585
|
+
if (stateInfo instanceof Uint8Array) {
|
|
2586
|
+
try {
|
|
2587
|
+
stateInfo = JSON.parse(new TextDecoder().decode(stateInfo));
|
|
2588
|
+
}
|
|
2589
|
+
catch (e) {
|
|
2590
|
+
console.log(e);
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2578
2593
|
await this.syncChain(lastBlock);
|
|
2579
2594
|
this.machine.states.info = stateInfo;
|
|
2580
2595
|
}
|