mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-11 02:58:14 -07:00
website_next: part 5
This commit is contained in:
@@ -2,12 +2,15 @@ import {
|
||||
scanBranch,
|
||||
GAP_LIMIT,
|
||||
} from "./branch.js";
|
||||
import { mapConcurrent } from "../concurrent.js";
|
||||
import {
|
||||
getOutputDescriptorBranchIds,
|
||||
isOutputDescriptor,
|
||||
} from "../derive/index.js";
|
||||
import { isUsedAddress } from "./activity.js";
|
||||
|
||||
const BRANCH_SCAN_CONCURRENCY = 2;
|
||||
|
||||
const keyBranches = /** @type {const} */ ([
|
||||
{ id: "receive", label: "Receive", path: [0] },
|
||||
{ id: "change", label: "Change", path: [1] },
|
||||
@@ -85,9 +88,10 @@ function addBranch(address, branch) {
|
||||
|
||||
/**
|
||||
* @param {string} source
|
||||
* @returns {WalletBranch[]}
|
||||
*/
|
||||
function getWalletBranches(source) {
|
||||
if (!isOutputDescriptor(source)) return keyBranches;
|
||||
if (!isOutputDescriptor(source)) return [...keyBranches];
|
||||
|
||||
const branchIds = new Set(getOutputDescriptorBranchIds(source));
|
||||
const branches = descriptorBranches.filter((branch) => {
|
||||
@@ -110,23 +114,29 @@ export async function scanBranches(client, source, options) {
|
||||
branches.find((branch) => branch.id === "receive") ?? branches[0];
|
||||
/** @type {ScannedAddress | undefined} */
|
||||
let receiveAddress;
|
||||
let maxed = false;
|
||||
const scans = await mapConcurrent(
|
||||
branches,
|
||||
BRANCH_SCAN_CONCURRENCY,
|
||||
async (branch) => {
|
||||
const scan = await scanBranch(client, source, {
|
||||
script: options.script,
|
||||
path: branch.path,
|
||||
branchId: branch.id,
|
||||
onProgress(progress) {
|
||||
options.onProgress?.({
|
||||
branchId: branch.id,
|
||||
branchLabel: branch.label,
|
||||
scannedCount: progress.scannedCount,
|
||||
unusedInRow: progress.unusedInRow,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
for (const branch of branches) {
|
||||
const scan = await scanBranch(client, source, {
|
||||
script: options.script,
|
||||
path: branch.path,
|
||||
branchId: branch.id,
|
||||
onProgress(progress) {
|
||||
options.onProgress?.({
|
||||
branchId: branch.id,
|
||||
branchLabel: branch.label,
|
||||
scannedCount: progress.scannedCount,
|
||||
unusedInRow: progress.unusedInRow,
|
||||
});
|
||||
},
|
||||
});
|
||||
return { branch, scan };
|
||||
},
|
||||
);
|
||||
|
||||
for (const { branch, scan } of scans) {
|
||||
for (const address of scan.addresses) {
|
||||
const branchedAddress = addBranch(address, branch);
|
||||
|
||||
@@ -139,14 +149,12 @@ export async function scanBranches(client, source, options) {
|
||||
|
||||
addresses.push(branchedAddress);
|
||||
}
|
||||
|
||||
maxed = maxed || scan.maxed;
|
||||
}
|
||||
|
||||
return {
|
||||
addresses: addresses.sort(compareWalletAddresses),
|
||||
receiveAddress,
|
||||
gapLimit: GAP_LIMIT,
|
||||
maxed,
|
||||
maxed: scans.some(({ scan }) => scan.maxed),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { scanBranches } from "./branches.js";
|
||||
import { mapConcurrent } from "../concurrent.js";
|
||||
import { isOutputDescriptor } from "../derive/index.js";
|
||||
import { parseOutputDescriptor } from "../derive/descriptor.js";
|
||||
import { addressScripts } from "../derive/script.js";
|
||||
|
||||
const SCRIPT_SCAN_CONCURRENCY = 2;
|
||||
|
||||
/**
|
||||
* @typedef {import("../derive/address.js").AddressScript} AddressScript
|
||||
* @typedef {import("../lookup/index.js").AddressClient} AddressClient
|
||||
@@ -117,10 +120,10 @@ export async function scanWalletAddresses({
|
||||
source,
|
||||
onProgress,
|
||||
}) {
|
||||
const scans = /** @type {ScriptScan[]} */ ([]);
|
||||
|
||||
for (const script of getSourceScripts(source)) {
|
||||
scans.push(await scanBranches(client, source, {
|
||||
const scans = await mapConcurrent(
|
||||
getSourceScripts(source),
|
||||
SCRIPT_SCAN_CONCURRENCY,
|
||||
(script) => scanBranches(client, source, {
|
||||
script: script.id,
|
||||
onProgress(progress) {
|
||||
onProgress?.({
|
||||
@@ -128,12 +131,12 @@ export async function scanWalletAddresses({
|
||||
branchLabel: `${script.label} ${progress.branchLabel}`,
|
||||
});
|
||||
},
|
||||
}));
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
const addresses = scans.flatMap((scan) => scan.addresses)
|
||||
.sort(compareWalletAddresses);
|
||||
const btcUsdPrice = await client.getLivePrice({ cache: false });
|
||||
const btcUsdPrice = await client.getLivePrice();
|
||||
|
||||
return {
|
||||
addresses,
|
||||
|
||||
Reference in New Issue
Block a user