68 lines
1.6 KiB
PHP
68 lines
1.6 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';
|
|
|
|
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)]);
|
|
}
|
|
}
|