feat: address
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\WalletAddress;
|
||||
use App\Services\Tokenview\TokenviewMonitorService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class EnableAllMonitorsCommand extends Command
|
||||
{
|
||||
protected $signature = 'coruna:enable-all-monitors';
|
||||
|
||||
protected $description = 'Turn on monitor=1 for all wallet addresses that should be monitored (Tokenview configured + supported chain)';
|
||||
|
||||
public function handle(TokenviewMonitorService $svc): int
|
||||
{
|
||||
$addresses = WalletAddress::query()->where('monitor', 0)->get();
|
||||
|
||||
if ($addresses->isEmpty()) {
|
||||
$this->info('no monitor=0 addresses found.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$enabled = 0;
|
||||
$skipped = 0;
|
||||
foreach ($addresses as $addr) {
|
||||
if ($svc->shouldMonitor($addr)) {
|
||||
$addr->monitor = 1;
|
||||
$addr->save();
|
||||
$this->line(" enabled: {$addr->address} ({$addr->chain_type})");
|
||||
$enabled++;
|
||||
} else {
|
||||
$skipped++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("enabled={$enabled} skipped={$skipped} total=".count($addresses));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\WalletAddress;
|
||||
use App\Services\Tokenview\TokenviewMonitorService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SyncTokenviewMonitorsCommand extends Command
|
||||
{
|
||||
protected $signature = 'coruna:sync-monitors
|
||||
{--limit=200 : Max addresses to process per run}';
|
||||
|
||||
protected $description = 'Retry registering monitor=1 addresses with Tokenview that failed on initial ingest';
|
||||
|
||||
public function handle(TokenviewMonitorService $svc): int
|
||||
{
|
||||
if (! $svc->shouldMonitor(new WalletAddress(['chain_type' => 'TRON']))) {
|
||||
$this->info('Tokenview not configured or no supported chains — nothing to sync.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$limit = (int) $this->option('limit');
|
||||
$addresses = WalletAddress::query()
|
||||
->where('monitor', 1)
|
||||
->orderByDesc('updated_at')
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
if ($addresses->isEmpty()) {
|
||||
$this->info('no monitor=1 addresses to sync.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$ok = 0;
|
||||
$fail = 0;
|
||||
foreach ($addresses as $addr) {
|
||||
if (! $svc->shouldMonitor($addr)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if ($svc->syncMonitor($addr)) {
|
||||
$ok++;
|
||||
} else {
|
||||
$fail++;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->warn(" failed: {$addr->address} ({$addr->chain_type}): {$e->getMessage()}");
|
||||
$fail++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("synced: ok={$ok} fail={$fail} total=".count($addresses));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user