feat: address
This commit is contained in:
@@ -12,6 +12,9 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TokenviewMonitorService
|
||||
{
|
||||
/** Stop retrying an address after this many consecutive sync failures. */
|
||||
public const MAX_SYNC_FAILURES = 3;
|
||||
|
||||
public function __construct(
|
||||
private readonly TokenviewClient $client,
|
||||
private readonly TelegramNotifier $telegram,
|
||||
@@ -78,10 +81,29 @@ class TokenviewMonitorService
|
||||
|
||||
$addr = (string) $address->address;
|
||||
if ((int) $address->monitor === 1) {
|
||||
return $this->client->addAddress($coin, $addr);
|
||||
$ok = $this->client->addAddress($coin, $addr);
|
||||
if ($ok) {
|
||||
$address->monitor_synced = true;
|
||||
$address->monitor_failures = 0;
|
||||
$address->save();
|
||||
} else {
|
||||
// Bump consecutive failure counter; the scheduled task stops
|
||||
// retrying once it reaches MAX_SYNC_FAILURES.
|
||||
$address->monitor_failures = (int) $address->monitor_failures + 1;
|
||||
$address->save();
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
|
||||
return $this->client->removeAddress($coin, $addr);
|
||||
$ok = $this->client->removeAddress($coin, $addr);
|
||||
if ($ok) {
|
||||
$address->monitor_synced = false;
|
||||
$address->monitor_failures = 0;
|
||||
$address->save();
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user