feat: 查看钱包优化,地址增加链上查询
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Chain;
|
||||
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
|
||||
/**
|
||||
* Optional shorter HTTP timeout for a block of chain calls.
|
||||
* Drivers opt in via apply(); transfers keep their own defaults.
|
||||
*/
|
||||
final class ChainHttpTimeout
|
||||
{
|
||||
private static ?int $seconds = null;
|
||||
|
||||
public static function active(): bool
|
||||
{
|
||||
return self::$seconds !== null;
|
||||
}
|
||||
|
||||
public static function using(int $seconds, callable $callback): mixed
|
||||
{
|
||||
$previous = self::$seconds;
|
||||
self::$seconds = max(1, $seconds);
|
||||
try {
|
||||
return $callback();
|
||||
} finally {
|
||||
self::$seconds = $previous;
|
||||
}
|
||||
}
|
||||
|
||||
public static function apply(PendingRequest $request): PendingRequest
|
||||
{
|
||||
if (self::$seconds === null) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
return $request->connectTimeout(min(3, self::$seconds))->timeout(self::$seconds);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user