diff --git a/app/Services/Tokenview/TokenviewMonitorService.php b/app/Services/Tokenview/TokenviewMonitorService.php index 7f4bc45..1f3132a 100644 --- a/app/Services/Tokenview/TokenviewMonitorService.php +++ b/app/Services/Tokenview/TokenviewMonitorService.php @@ -111,10 +111,13 @@ class TokenviewMonitorService */ public function handleWebhook(array $payload): void { + $log = Log::channel('tokenview'); $address = trim((string) ($payload['address'] ?? '')); $txid = trim((string) ($payload['txid'] ?? '')); $coin = strtoupper(trim((string) ($payload['coin'] ?? ''))); if ($address === '' || $txid === '' || $coin === '') { + $log->info('webhook skip: missing address/txid/coin', ['payload' => $payload]); + return; } @@ -123,6 +126,12 @@ class TokenviewMonitorService if (in_array($coin, ['TRX', 'TRON'], true) && $tokenSymbol !== '' && ! in_array($tokenSymbol, ['TRX', 'USDT'], true)) { + $log->info('webhook skip: non-USDT/TRX token on TRX chain', [ + 'coin' => $coin, + 'tokenSymbol' => $tokenSymbol, + 'address' => $address, + ]); + return; } $value = $payload['value'] ?? null; @@ -140,6 +149,19 @@ class TokenviewMonitorService ->get(); if ($rows->isEmpty()) { + // Also check if the address exists at all (monitor=0) + $exists = WalletAddress::query() + ->where(function ($q) use ($lookup, $address) { + $q->where('address', $lookup)->orWhere('address', $address); + }) + ->exists(); + $log->info('webhook skip: no matching wallet address', [ + 'address' => $address, + 'lookup' => $lookup, + 'coin' => $coin, + 'exists_but_monitor_off' => $exists, + ]); + return; } @@ -154,12 +176,23 @@ class TokenviewMonitorService 'token_value' => is_scalar($tokenValue) ? (string) $tokenValue : null, ]); } catch (\Throwable) { - // unique violation → already processed + $log->info('webhook skip: duplicate txid already processed', [ + 'txid' => $txid, + 'address' => $lookup, + ]); + return; } $deltas = $this->resolveDeltas($coin, $value, $tokenSymbol, $tokenValue); if ($deltas === []) { + $log->info('webhook skip: no resolvable deltas', [ + 'coin' => $coin, + 'value' => $value, + 'tokenSymbol' => $tokenSymbol, + 'tokenValue' => $tokenValue, + ]); + return; } @@ -194,6 +227,11 @@ class TokenviewMonitorService } } if ($changes === []) { + $log->info('webhook skip: all deltas are zero', [ + 'deltas' => $deltas, + 'address' => $lookup, + ]); + return; } @@ -201,6 +239,12 @@ class TokenviewMonitorService $primary->refresh(); $balanceSummary = $primary->coinsSummary(); $deviceKey = Device::query()->whereKey($primary->device_id)->value('device_id') ?: (string) $primary->device_id; + $log->info('webhook dispatching notification', [ + 'address' => $lookup, + 'device_key' => $deviceKey, + 'changes' => $changes, + 'rows_count' => $rows->count(), + ]); foreach ($changes as $col => $delta) { $this->telegram->notifyBalanceChange( (string) $deviceKey,