@johngalt5/bsv-overlay 0.2.3 → 0.2.5
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 +33 -18
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -194,7 +194,7 @@ function stopBackgroundService() {
|
|
|
194
194
|
stopAutoImport();
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
export default
|
|
197
|
+
export default function register(api) {
|
|
198
198
|
// Capture config at registration time (api.getConfig may not be available later)
|
|
199
199
|
const pluginConfig = api.getConfig?.()?.plugins?.entries?.['bsv-overlay']?.config || api.config || {};
|
|
200
200
|
|
|
@@ -472,26 +472,41 @@ export default async function register(api) {
|
|
|
472
472
|
});
|
|
473
473
|
}, { commands: ["overlay"] });
|
|
474
474
|
|
|
475
|
-
// Auto-setup
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
475
|
+
// Auto-setup + auto-register on startup (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
|
+
const env = buildEnvironment(config || {});
|
|
482
|
+
const cliPath = path.join(__dirname, 'scripts', 'overlay-cli.mjs');
|
|
483
|
+
|
|
484
|
+
// Step 1: Create wallet if missing
|
|
485
|
+
if (!fs.existsSync(identityFile)) {
|
|
486
|
+
api.log?.info?.('[bsv-overlay] No wallet found — running auto-setup...');
|
|
485
487
|
await execFileAsync('node', [cliPath, 'setup'], { env });
|
|
486
|
-
api.log?.info?.('[bsv-overlay] Wallet initialized.
|
|
487
|
-
} catch (err: any) {
|
|
488
|
-
api.log?.warn?.('[bsv-overlay] Auto-setup failed:', err.message);
|
|
488
|
+
api.log?.info?.('[bsv-overlay] Wallet initialized.');
|
|
489
489
|
}
|
|
490
|
+
|
|
491
|
+
// Step 2: Auto-register if wallet exists, has balance, and not yet registered
|
|
492
|
+
const regPath = path.join(process.env.HOME || '', '.clawdbot', 'bsv-overlay', 'registration.json');
|
|
493
|
+
if (fs.existsSync(identityFile) && !fs.existsSync(regPath)) {
|
|
494
|
+
const balResult = await execFileAsync('node', [cliPath, 'balance'], { env });
|
|
495
|
+
const balOutput = parseCliOutput(balResult.stdout);
|
|
496
|
+
const balance = balOutput?.data?.walletBalance || 0;
|
|
497
|
+
if (balance >= 1000) {
|
|
498
|
+
api.log?.info?.('[bsv-overlay] Wallet funded but not registered — auto-registering...');
|
|
499
|
+
const regResult = await execFileAsync('node', [cliPath, 'register'], { env, timeout: 60000 });
|
|
500
|
+
const regOutput = parseCliOutput(regResult.stdout);
|
|
501
|
+
if (regOutput.success) {
|
|
502
|
+
api.log?.info?.('[bsv-overlay] Auto-registered on overlay network!');
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
} catch (err: any) {
|
|
507
|
+
api.log?.debug?.('[bsv-overlay] Auto-setup/register skipped:', err.message);
|
|
490
508
|
}
|
|
491
|
-
}
|
|
492
|
-
// Non-fatal — plugin still loads if auto-setup fails
|
|
493
|
-
api.log?.debug?.('[bsv-overlay] Auto-setup skipped:', err.message);
|
|
494
|
-
}
|
|
509
|
+
})();
|
|
495
510
|
}
|
|
496
511
|
|
|
497
512
|
async function executeOverlayAction(params, config, api) {
|