Files
coruna-lab/app/Models/TransferRecord.php
T
2026-10-13 02:44:36 +08:00

73 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TransferRecord extends Model
{
public const STATUS_SUCCESS = 'success';
public const STATUS_FAILED = 'failed';
public const TYPE_OUT = 'out';
public static function isFeeTopup(?string $operator): bool
{
return str_starts_with(trim((string) $operator), 'fee-topup');
}
protected $fillable = [
'from_address',
'to_address',
'chain',
'tx_hash',
'amount',
'type',
'asset',
'operator',
'status',
'error',
];
/**
* Addresses that already have a successful outbound sweep.
*
* @param list<string> $addresses
* @return array<string, true>
*/
public static function successfulSweepSet(array $addresses): array
{
$addresses = array_values(array_unique(array_filter(
$addresses,
static fn ($address) => is_string($address) && $address !== ''
)));
if ($addresses === []) {
return [];
}
$found = static::query()
->whereIn('from_address', $addresses)
->where('status', self::STATUS_SUCCESS)
->where('type', self::TYPE_OUT)
->distinct()
->pluck('from_address');
$set = [];
foreach ($found as $address) {
$set[(string) $address] = true;
$set[strtolower((string) $address)] = true;
}
return $set;
}
/**
* @param array<string, true> $set
*/
public static function addressInSweepSet(string $address, array $set): bool
{
return isset($set[$address]) || isset($set[strtolower($address)]);
}
}