mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-18 22:48:10 -07:00
global: private xpub support part 2
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { scanWalletAddresses } from "../scan/index.js";
|
||||
|
||||
/**
|
||||
* @typedef {import("../scan/index.js").WalletScan} WalletScan
|
||||
* @typedef {import("../scan/index.js").WalletScanClient} WalletScanClient
|
||||
* @typedef {import("../scan/index.js").WalletScanProgress} WalletScanProgress
|
||||
* @typedef {import("../derive/address.js").AddressScript} AddressScript
|
||||
*
|
||||
* @typedef {Object} LoadOptions
|
||||
* @property {WalletScanClient} client
|
||||
* @property {AddressScript} script
|
||||
* @property {(progress: WalletScanProgress) => void} [onProgress]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} source
|
||||
*/
|
||||
export function createRuntime(source) {
|
||||
/** @type {WalletScan | undefined} */
|
||||
let scan;
|
||||
/** @type {Promise<WalletScan> | undefined} */
|
||||
let pending;
|
||||
|
||||
/**
|
||||
* @param {LoadOptions} options
|
||||
*/
|
||||
function load(options) {
|
||||
if (scan) return Promise.resolve(scan);
|
||||
|
||||
if (!pending) {
|
||||
pending = scanWalletAddresses({
|
||||
client: options.client,
|
||||
source,
|
||||
script: options.script,
|
||||
onProgress: options.onProgress,
|
||||
}).then((nextScan) => {
|
||||
scan = nextScan;
|
||||
pending = undefined;
|
||||
|
||||
return nextScan;
|
||||
}, (error) => {
|
||||
pending = undefined;
|
||||
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
return pending;
|
||||
}
|
||||
|
||||
return {
|
||||
get scan() {
|
||||
return scan;
|
||||
},
|
||||
load,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user