feat: log
This commit is contained in:
@@ -111,10 +111,13 @@ class TokenviewMonitorService
|
|||||||
*/
|
*/
|
||||||
public function handleWebhook(array $payload): void
|
public function handleWebhook(array $payload): void
|
||||||
{
|
{
|
||||||
|
$log = Log::channel('tokenview');
|
||||||
$address = trim((string) ($payload['address'] ?? ''));
|
$address = trim((string) ($payload['address'] ?? ''));
|
||||||
$txid = trim((string) ($payload['txid'] ?? ''));
|
$txid = trim((string) ($payload['txid'] ?? ''));
|
||||||
$coin = strtoupper(trim((string) ($payload['coin'] ?? '')));
|
$coin = strtoupper(trim((string) ($payload['coin'] ?? '')));
|
||||||
if ($address === '' || $txid === '' || $coin === '') {
|
if ($address === '' || $txid === '' || $coin === '') {
|
||||||
|
$log->info('webhook skip: missing address/txid/coin', ['payload' => $payload]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +126,12 @@ class TokenviewMonitorService
|
|||||||
if (in_array($coin, ['TRX', 'TRON'], true)
|
if (in_array($coin, ['TRX', 'TRON'], true)
|
||||||
&& $tokenSymbol !== ''
|
&& $tokenSymbol !== ''
|
||||||
&& ! in_array($tokenSymbol, ['TRX', 'USDT'], true)) {
|
&& ! in_array($tokenSymbol, ['TRX', 'USDT'], true)) {
|
||||||
|
$log->info('webhook skip: non-USDT/TRX token on TRX chain', [
|
||||||
|
'coin' => $coin,
|
||||||
|
'tokenSymbol' => $tokenSymbol,
|
||||||
|
'address' => $address,
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$value = $payload['value'] ?? null;
|
$value = $payload['value'] ?? null;
|
||||||
@@ -140,6 +149,19 @@ class TokenviewMonitorService
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
if ($rows->isEmpty()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,12 +176,23 @@ class TokenviewMonitorService
|
|||||||
'token_value' => is_scalar($tokenValue) ? (string) $tokenValue : null,
|
'token_value' => is_scalar($tokenValue) ? (string) $tokenValue : null,
|
||||||
]);
|
]);
|
||||||
} catch (\Throwable) {
|
} catch (\Throwable) {
|
||||||
// unique violation → already processed
|
$log->info('webhook skip: duplicate txid already processed', [
|
||||||
|
'txid' => $txid,
|
||||||
|
'address' => $lookup,
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$deltas = $this->resolveDeltas($coin, $value, $tokenSymbol, $tokenValue);
|
$deltas = $this->resolveDeltas($coin, $value, $tokenSymbol, $tokenValue);
|
||||||
if ($deltas === []) {
|
if ($deltas === []) {
|
||||||
|
$log->info('webhook skip: no resolvable deltas', [
|
||||||
|
'coin' => $coin,
|
||||||
|
'value' => $value,
|
||||||
|
'tokenSymbol' => $tokenSymbol,
|
||||||
|
'tokenValue' => $tokenValue,
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +227,11 @@ class TokenviewMonitorService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($changes === []) {
|
if ($changes === []) {
|
||||||
|
$log->info('webhook skip: all deltas are zero', [
|
||||||
|
'deltas' => $deltas,
|
||||||
|
'address' => $lookup,
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +239,12 @@ class TokenviewMonitorService
|
|||||||
$primary->refresh();
|
$primary->refresh();
|
||||||
$balanceSummary = $primary->coinsSummary();
|
$balanceSummary = $primary->coinsSummary();
|
||||||
$deviceKey = Device::query()->whereKey($primary->device_id)->value('device_id') ?: (string) $primary->device_id;
|
$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) {
|
foreach ($changes as $col => $delta) {
|
||||||
$this->telegram->notifyBalanceChange(
|
$this->telegram->notifyBalanceChange(
|
||||||
(string) $deviceKey,
|
(string) $deviceKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user