@bsv/wallet-toolbox-client 2.6.0 → 2.6.1
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/out/index.client.cjs
CHANGED
|
@@ -20784,9 +20784,11 @@ var BulkFileDataManager = class BulkFileDataManager {
|
|
|
20784
20784
|
const nextHeight = lbf != null ? lbf.firstHeight + lbf.count : 0;
|
|
20785
20785
|
({headers: newBulkHeaders, incrementalChainWork} = trimAlreadyStoredHeaders(newBulkHeaders, nextHeight, incrementalChainWork));
|
|
20786
20786
|
if (newBulkHeaders.length === 0) return;
|
|
20787
|
-
if (
|
|
20788
|
-
if (!lbf.lastHash) throw new WERR_INTERNAL(`lastHash is not defined for the last bulk file ${lbf.fileName}`);
|
|
20789
|
-
const
|
|
20787
|
+
if (nextHeight !== newBulkHeaders[0].height) throw new WERR_INVALID_PARAMETER("newBulkHeaders", "an extension of existing bulk headers");
|
|
20788
|
+
if (lbf != null && !lbf.lastHash) throw new WERR_INTERNAL(`lastHash is not defined for the last bulk file ${lbf.fileName}`);
|
|
20789
|
+
const prevChainWork = lbf?.lastChainWork ?? "00".repeat(32);
|
|
20790
|
+
const prevHash = lbf?.lastHash ?? "00".repeat(32);
|
|
20791
|
+
const lastChainWork = incrementalChainWork ? addWork(incrementalChainWork, prevChainWork) : computeChainWorkFromHeaders(newBulkHeaders, lbf);
|
|
20790
20792
|
const data = serializeBaseBlockHeaders(newBulkHeaders);
|
|
20791
20793
|
const fileHash = asString(_bsv_sdk.Hash.sha256(asArray(data)), "base64");
|
|
20792
20794
|
const bf = {
|
|
@@ -20796,9 +20798,9 @@ var BulkFileDataManager = class BulkFileDataManager {
|
|
|
20796
20798
|
fileName: "incremental",
|
|
20797
20799
|
firstHeight: newBulkHeaders[0].height,
|
|
20798
20800
|
count: newBulkHeaders.length,
|
|
20799
|
-
prevChainWork
|
|
20801
|
+
prevChainWork,
|
|
20800
20802
|
lastChainWork,
|
|
20801
|
-
prevHash
|
|
20803
|
+
prevHash,
|
|
20802
20804
|
lastHash: newBulkHeaders.at(-1).hash,
|
|
20803
20805
|
fileHash,
|
|
20804
20806
|
data
|
|
@@ -21228,12 +21230,13 @@ function trimAlreadyStoredHeaders(headers, nextHeight, incrementalChainWork) {
|
|
|
21228
21230
|
}
|
|
21229
21231
|
/**
|
|
21230
21232
|
* Computes `lastChainWork` for a sequence of new bulk headers extending `lbf`,
|
|
21231
|
-
*
|
|
21233
|
+
* or beginning at genesis when bulk storage is empty, validating that the
|
|
21234
|
+
* sequence is contiguous.
|
|
21232
21235
|
*/
|
|
21233
21236
|
function computeChainWorkFromHeaders(headers, lbf) {
|
|
21234
|
-
let lastHeight = lbf.firstHeight + lbf.count - 1;
|
|
21235
|
-
let lastHash = lbf.
|
|
21236
|
-
let lastChainWork = lbf.
|
|
21237
|
+
let lastHeight = lbf != null ? lbf.firstHeight + lbf.count - 1 : -1;
|
|
21238
|
+
let lastHash = lbf?.lastHash ?? "00".repeat(32);
|
|
21239
|
+
let lastChainWork = lbf?.lastChainWork ?? "00".repeat(32);
|
|
21237
21240
|
for (const h of headers) {
|
|
21238
21241
|
if (h.height !== lastHeight + 1 || h.previousHash !== lastHash) throw new WERR_INVALID_PARAMETER("headers", `an extension of existing bulk headers, header with height ${h.height} is non-sequential`);
|
|
21239
21242
|
lastChainWork = addWork(lastChainWork, convertBitsToWork(h.bits));
|