Files
coruna-lab/app/Console/Commands/LinkMnemonicsCommand.php
2026-09-29 05:25:55 +08:00

43 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\WalletAddress;
use App\Models\WalletMnemonic;
use App\Services\MnemonicAddressLinker;
use App\Services\MnemonicWalletDiscovery;
use Illuminate\Console\Command;
class LinkMnemonicsCommand extends Command
{
protected $signature = 'coruna:link-mnemonics';
protected $description = 'Link existing addresses to mnemonics (BIP44 0..9), then persist activated derived addresses (0..2) when a mnemonic has none';
public function handle(MnemonicAddressLinker $linker, MnemonicWalletDiscovery $discovery): int
{
$before = WalletAddress::query()->whereNull('mnemonic_id')->count();
$this->info("unlinked addresses before: {$before}");
$result = $linker->backfill();
// Only probe mnemonics that haven't been fully discovered across all 5
// chains yet. Manual "view wallet" / "refresh" bypasses this via force=true.
$discovered = 0;
foreach (WalletMnemonic::query()->where('discovery_complete', false)->orderBy('id')->cursor() as $mnemonic) {
$discovered += $discovery->discoverActivated($mnemonic);
}
$after = WalletAddress::query()->whereNull('mnemonic_id')->count();
$this->info(sprintf(
'scanned mnemonics=%d linked=%d discovered=%d unlinked_after=%d',
$result['mnemonics'],
$result['linked'],
$discovered,
$after,
));
return self::SUCCESS;
}
}