41 lines
1.3 KiB
PHP
41 lines
1.3 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();
|
|
|
|
$discovered = 0;
|
|
foreach (WalletMnemonic::query()->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;
|
|
}
|
|
}
|