@johngalt5/bsv-overlay 0.2.2 → 0.2.4
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/index.ts +15 -20
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -78,9 +78,9 @@ async function startAutoImport(env, cliPath, logger) {
|
|
|
78
78
|
const network = env.BSV_NETWORK === 'testnet' ? 'test' : 'main';
|
|
79
79
|
const controller = new AbortController();
|
|
80
80
|
const timeout = setTimeout(() => controller.abort(), 15000);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const resp = await fetch(`https://api.whatsonchain.com/v1/bsv/${network}/address/${address}/unspent`, { signal: controller.signal });
|
|
82
|
+
clearTimeout(timeout);
|
|
83
|
+
if (!resp.ok) return;
|
|
84
84
|
const utxos = await resp.json();
|
|
85
85
|
|
|
86
86
|
for (const utxo of utxos) {
|
|
@@ -118,8 +118,6 @@ async function startAutoImport(env, cliPath, logger) {
|
|
|
118
118
|
}
|
|
119
119
|
} catch (err) {
|
|
120
120
|
// WoC API error — just skip this cycle
|
|
121
|
-
} finally {
|
|
122
|
-
clearTimeout(timeout);
|
|
123
121
|
}
|
|
124
122
|
}, 60000); // Check every 60 seconds
|
|
125
123
|
} catch (err) {
|
|
@@ -196,7 +194,7 @@ function stopBackgroundService() {
|
|
|
196
194
|
stopAutoImport();
|
|
197
195
|
}
|
|
198
196
|
|
|
199
|
-
export default
|
|
197
|
+
export default function register(api) {
|
|
200
198
|
// Capture config at registration time (api.getConfig may not be available later)
|
|
201
199
|
const pluginConfig = api.getConfig?.()?.plugins?.entries?.['bsv-overlay']?.config || api.config || {};
|
|
202
200
|
|
|
@@ -474,26 +472,23 @@ export default async function register(api) {
|
|
|
474
472
|
});
|
|
475
473
|
}, { commands: ["overlay"] });
|
|
476
474
|
|
|
477
|
-
// Auto-setup: ensure wallet exists (best-effort, non-fatal)
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
475
|
+
// Auto-setup: ensure wallet exists (best-effort, non-fatal, fire-and-forget)
|
|
476
|
+
(async () => {
|
|
477
|
+
try {
|
|
478
|
+
const config = pluginConfig;
|
|
479
|
+
const walletDir = config?.walletDir || path.join(process.env.HOME || '', '.clawdbot', 'bsv-wallet');
|
|
480
|
+
const identityFile = path.join(walletDir, 'wallet-identity.json');
|
|
481
|
+
if (!fs.existsSync(identityFile)) {
|
|
482
|
+
api.log?.info?.('[bsv-overlay] No wallet found — running auto-setup...');
|
|
485
483
|
const env = buildEnvironment(config || {});
|
|
486
484
|
const cliPath = path.join(__dirname, 'scripts', 'overlay-cli.mjs');
|
|
487
485
|
await execFileAsync('node', [cliPath, 'setup'], { env });
|
|
488
486
|
api.log?.info?.('[bsv-overlay] Wallet initialized. Fund it and run: overlay({ action: "register" })');
|
|
489
|
-
} catch (err: any) {
|
|
490
|
-
api.log?.warn?.('[bsv-overlay] Auto-setup failed:', err.message);
|
|
491
487
|
}
|
|
488
|
+
} catch (err: any) {
|
|
489
|
+
api.log?.debug?.('[bsv-overlay] Auto-setup skipped:', err.message);
|
|
492
490
|
}
|
|
493
|
-
}
|
|
494
|
-
// Non-fatal — plugin still loads if auto-setup fails
|
|
495
|
-
api.log?.debug?.('[bsv-overlay] Auto-setup skipped:', err.message);
|
|
496
|
-
}
|
|
491
|
+
})();
|
|
497
492
|
}
|
|
498
493
|
|
|
499
494
|
async function executeOverlayAction(params, config, api) {
|