@johngalt5/bsv-overlay 0.2.4 → 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 +23 -5
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -472,21 +472,39 @@ export default function register(api) {
|
|
|
472
472
|
});
|
|
473
473
|
}, { commands: ["overlay"] });
|
|
474
474
|
|
|
475
|
-
// Auto-setup
|
|
475
|
+
// Auto-setup + auto-register on startup (best-effort, non-fatal, fire-and-forget)
|
|
476
476
|
(async () => {
|
|
477
477
|
try {
|
|
478
478
|
const config = pluginConfig;
|
|
479
479
|
const walletDir = config?.walletDir || path.join(process.env.HOME || '', '.clawdbot', 'bsv-wallet');
|
|
480
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
|
|
481
485
|
if (!fs.existsSync(identityFile)) {
|
|
482
486
|
api.log?.info?.('[bsv-overlay] No wallet found — running auto-setup...');
|
|
483
|
-
const env = buildEnvironment(config || {});
|
|
484
|
-
const cliPath = path.join(__dirname, 'scripts', 'overlay-cli.mjs');
|
|
485
487
|
await execFileAsync('node', [cliPath, 'setup'], { env });
|
|
486
|
-
api.log?.info?.('[bsv-overlay] Wallet initialized.
|
|
488
|
+
api.log?.info?.('[bsv-overlay] Wallet initialized.');
|
|
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
|
+
}
|
|
487
505
|
}
|
|
488
506
|
} catch (err: any) {
|
|
489
|
-
api.log?.debug?.('[bsv-overlay] Auto-setup skipped:', err.message);
|
|
507
|
+
api.log?.debug?.('[bsv-overlay] Auto-setup/register skipped:', err.message);
|
|
490
508
|
}
|
|
491
509
|
})();
|
|
492
510
|
}
|