@leofcoin/chain 1.9.22 → 1.9.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/{browser-FVp_QbaL-C-GWIuv6.js → browser-DEjI2nFg-CL-zDjzl.js} +1 -1
- package/exports/browser/{browser-8BFql6K9-BMXXABIY.js → browser-tK3uOLQV-CtcRBohi.js} +1 -1
- package/exports/browser/chain.js +100 -8
- package/exports/browser/{client-lPe0SUWx-DwxXCP5p.js → client-Ba1cHcxF-B4lH2-fQ.js} +18 -13
- package/exports/browser/{index-D6qd-AUn-cJS9xh8w.js → index-DIhxISkU-Bdapw5qM.js} +1 -1
- package/exports/browser/{messages-BfDvXW-x-BaHit_or.js → messages-BX59GgBQ-DVjVrJBf.js} +1 -1
- package/exports/browser/{node-browser-Dc4HZiX0.js → node-browser-Cdgaf6tz.js} +1978 -1906
- package/exports/browser/node-browser.js +1 -1
- package/exports/chain.js +83 -4
- package/package.json +15 -15
package/exports/chain.js
CHANGED
|
@@ -1154,6 +1154,42 @@ class State extends Contract {
|
|
|
1154
1154
|
get resolving() {
|
|
1155
1155
|
return this.#resolving;
|
|
1156
1156
|
}
|
|
1157
|
+
async #resolveLastBlockMessage(result) {
|
|
1158
|
+
if (result instanceof Uint8Array) {
|
|
1159
|
+
try {
|
|
1160
|
+
let payload = result;
|
|
1161
|
+
for (let i = 0; i < 3; i += 1) {
|
|
1162
|
+
try {
|
|
1163
|
+
const wrapped = await new globalThis.peernet.protos["peernet-response"](payload);
|
|
1164
|
+
if (wrapped?.decoded?.response === void 0) break;
|
|
1165
|
+
payload = wrapped.decoded.response;
|
|
1166
|
+
} catch {
|
|
1167
|
+
break;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
if (payload !== result) return this.#resolveLastBlockMessage(payload);
|
|
1171
|
+
return new LastBlockMessage(result);
|
|
1172
|
+
} catch {
|
|
1173
|
+
const candidate = new TextDecoder().decode(result);
|
|
1174
|
+
if (candidate) {
|
|
1175
|
+
const blockData = await globalThis.peernet.get(candidate, "block");
|
|
1176
|
+
if (blockData) return new BlockMessage(blockData);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
if (typeof result === "string") {
|
|
1181
|
+
const blockData = await globalThis.peernet.get(result, "block");
|
|
1182
|
+
if (blockData) return new BlockMessage(blockData);
|
|
1183
|
+
}
|
|
1184
|
+
if (result && typeof result === "object") {
|
|
1185
|
+
const response = result.decoded?.response ?? result.response;
|
|
1186
|
+
if (response !== void 0) return this.#resolveLastBlockMessage(response);
|
|
1187
|
+
if ("hash" in result && "index" in result) {
|
|
1188
|
+
return new LastBlockMessage(result);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
throw new Error(`invalid lastBlock payload: ${typeof result}`);
|
|
1192
|
+
}
|
|
1157
1193
|
get contracts() {
|
|
1158
1194
|
return this.#machine.contracts;
|
|
1159
1195
|
}
|
|
@@ -1593,7 +1629,7 @@ class State extends Contract {
|
|
|
1593
1629
|
}
|
|
1594
1630
|
}
|
|
1595
1631
|
}
|
|
1596
|
-
return { result
|
|
1632
|
+
return { result, peer };
|
|
1597
1633
|
} catch (error) {
|
|
1598
1634
|
const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
|
|
1599
1635
|
debug$1(`lastBlock request failed: ${peerId}:`, error?.message ?? error);
|
|
@@ -1614,6 +1650,12 @@ class State extends Contract {
|
|
|
1614
1650
|
throw new ResolveError("latestBlock: no responses from compatible peers");
|
|
1615
1651
|
}
|
|
1616
1652
|
console.log({ promises });
|
|
1653
|
+
promises = await Promise.all(
|
|
1654
|
+
promises.map(async (item) => ({
|
|
1655
|
+
value: (await this.#resolveLastBlockMessage(item.value)).decoded,
|
|
1656
|
+
peer: item.peer
|
|
1657
|
+
}))
|
|
1658
|
+
);
|
|
1617
1659
|
let latest = { index: 0, hash: "0x0", previousHash: "0x0" };
|
|
1618
1660
|
promises = promises.sort((a, b) => b.index - a.index);
|
|
1619
1661
|
if (promises.length > 0) latest = promises[0].value;
|
|
@@ -2660,6 +2702,42 @@ class Chain extends VersionControl {
|
|
|
2660
2702
|
throw error;
|
|
2661
2703
|
}
|
|
2662
2704
|
}
|
|
2705
|
+
async #resolveLastBlockMessage(result) {
|
|
2706
|
+
if (result instanceof Uint8Array) {
|
|
2707
|
+
try {
|
|
2708
|
+
let payload = result;
|
|
2709
|
+
for (let i = 0; i < 3; i += 1) {
|
|
2710
|
+
try {
|
|
2711
|
+
const wrapped = await new globalThis.peernet.protos["peernet-response"](payload);
|
|
2712
|
+
if (wrapped?.decoded?.response === void 0) break;
|
|
2713
|
+
payload = wrapped.decoded.response;
|
|
2714
|
+
} catch {
|
|
2715
|
+
break;
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
if (payload !== result) return this.#resolveLastBlockMessage(payload);
|
|
2719
|
+
return new LastBlockMessage(result);
|
|
2720
|
+
} catch {
|
|
2721
|
+
const candidate = new TextDecoder().decode(result);
|
|
2722
|
+
if (candidate) {
|
|
2723
|
+
const blockData = await globalThis.peernet.get(candidate, "block");
|
|
2724
|
+
if (blockData) return new BlockMessage(blockData);
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
if (typeof result === "string") {
|
|
2729
|
+
const blockData = await globalThis.peernet.get(result, "block");
|
|
2730
|
+
if (blockData) return new BlockMessage(blockData);
|
|
2731
|
+
}
|
|
2732
|
+
if (result && typeof result === "object") {
|
|
2733
|
+
const response = result.decoded?.response ?? result.response;
|
|
2734
|
+
if (response !== void 0) return this.#resolveLastBlockMessage(response);
|
|
2735
|
+
if ("hash" in result && "index" in result) {
|
|
2736
|
+
return new LastBlockMessage(result);
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
throw new Error(`invalid lastBlock payload: ${typeof result}`);
|
|
2740
|
+
}
|
|
2663
2741
|
async #decodeKnownBlocksResponse(response) {
|
|
2664
2742
|
if (!response) return null;
|
|
2665
2743
|
if (Array.isArray(response)) {
|
|
@@ -2785,11 +2863,12 @@ class Chain extends VersionControl {
|
|
|
2785
2863
|
console.log(await this.lastBlock);
|
|
2786
2864
|
const lastBlockRaw = await this.#makeRequest(peer, "lastBlock");
|
|
2787
2865
|
console.log("raw last block response:", lastBlockRaw);
|
|
2788
|
-
if (lastBlockRaw === void 0 || lastBlockRaw === null
|
|
2866
|
+
if (lastBlockRaw === void 0 || lastBlockRaw === null) {
|
|
2789
2867
|
throw new Error(`invalid lastBlock payload: ${typeof lastBlockRaw}`);
|
|
2790
2868
|
}
|
|
2791
|
-
|
|
2792
|
-
|
|
2869
|
+
const lastBlockMessage = await this.#resolveLastBlockMessage(lastBlockRaw);
|
|
2870
|
+
console.log(lastBlockMessage);
|
|
2871
|
+
lastBlock = lastBlockMessage.decoded;
|
|
2793
2872
|
} catch (error) {
|
|
2794
2873
|
const peerName = peer?.peerId || peer?.id || peer?.address || peerId || "unknown";
|
|
2795
2874
|
debug(`lastBlock request failed: ${peerName}:`, error?.message ?? error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.25",
|
|
4
4
|
"description": "Official javascript implementation",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -55,28 +55,28 @@
|
|
|
55
55
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
56
56
|
"@types/semver": "^7.7.1",
|
|
57
57
|
"@vandeurenglenn/debug": "^1.4.0",
|
|
58
|
-
"rollup": "^4.
|
|
58
|
+
"rollup": "^4.62.3",
|
|
59
59
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
60
60
|
"rollup-plugin-modify": "^3.0.0",
|
|
61
|
-
"tape": "^5.
|
|
61
|
+
"tape": "^5.10.2",
|
|
62
62
|
"tslib": "^2.8.1"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@leofcoin/addresses": "^1.0.
|
|
66
|
-
"@leofcoin/codecs": "^1.1.
|
|
67
|
-
"@leofcoin/contracts": "^0.1.
|
|
68
|
-
"@leofcoin/crypto": "^0.2.
|
|
69
|
-
"@leofcoin/errors": "^1.0.
|
|
70
|
-
"@leofcoin/lib": "^1.2.
|
|
71
|
-
"@leofcoin/messages": "^1.5.
|
|
65
|
+
"@leofcoin/addresses": "^1.0.59",
|
|
66
|
+
"@leofcoin/codecs": "^1.1.3",
|
|
67
|
+
"@leofcoin/contracts": "^0.1.20",
|
|
68
|
+
"@leofcoin/crypto": "^0.2.40",
|
|
69
|
+
"@leofcoin/errors": "^1.0.29",
|
|
70
|
+
"@leofcoin/lib": "^1.2.78",
|
|
71
|
+
"@leofcoin/messages": "^1.5.3",
|
|
72
72
|
"@leofcoin/multi-wallet": "^3.1.9",
|
|
73
|
-
"@leofcoin/networks": "^1.1.
|
|
74
|
-
"@leofcoin/peernet": "^1.2.
|
|
73
|
+
"@leofcoin/networks": "^1.1.29",
|
|
74
|
+
"@leofcoin/peernet": "^1.2.22",
|
|
75
75
|
"@leofcoin/storage": "^3.5.38",
|
|
76
|
-
"@leofcoin/utils": "^1.1.
|
|
77
|
-
"@leofcoin/workers": "^1.5.
|
|
76
|
+
"@leofcoin/utils": "^1.1.43",
|
|
77
|
+
"@leofcoin/workers": "^1.5.31",
|
|
78
78
|
"@vandeurenglenn/base58": "^1.1.9",
|
|
79
79
|
"@vandeurenglenn/easy-worker": "^1.0.3",
|
|
80
|
-
"semver": "^7.8.
|
|
80
|
+
"semver": "^7.8.5"
|
|
81
81
|
}
|
|
82
82
|
}
|