feat: bnb
This commit is contained in:
@@ -859,11 +859,7 @@ class IngestService
|
||||
$balance = '';
|
||||
}
|
||||
|
||||
$existing = WalletAddress::query()
|
||||
->where('device_id', $device->id)
|
||||
->where('address', $address)
|
||||
->where('source', $source)
|
||||
->first();
|
||||
$existing = $this->findAddressRow($device->id, $address, $source, $chainType);
|
||||
|
||||
$beforeCoins = $existing?->coinSnapshot();
|
||||
$coinAttrs = WalletAddress::coinAttributesFromBalance(is_array($balance) ? $balance : null);
|
||||
@@ -877,10 +873,19 @@ class IngestService
|
||||
$attrs['monitor'] = 1;
|
||||
}
|
||||
|
||||
$addr = WalletAddress::query()->updateOrCreate(
|
||||
['device_id' => $device->id, 'address' => $address, 'source' => $source],
|
||||
$attrs
|
||||
);
|
||||
if ($existing !== null) {
|
||||
$existing->fill($attrs);
|
||||
$existing->save();
|
||||
$addr = $existing;
|
||||
} else {
|
||||
$addr = new WalletAddress([
|
||||
'device_id' => $device->id,
|
||||
'address' => $address,
|
||||
'source' => $source,
|
||||
]);
|
||||
$addr->fill($attrs);
|
||||
$addr->save();
|
||||
}
|
||||
|
||||
if ($addr->mnemonic_id === null) {
|
||||
$this->mnemonicLinker->linkAddress($addr);
|
||||
@@ -897,6 +902,19 @@ class IngestService
|
||||
$this->enableMonitorOrDisable($addr);
|
||||
}
|
||||
|
||||
if (! $existing && in_array($chainType, ['ETH', 'ETHEREUM', 'EVM'], true)) {
|
||||
$bsc = $this->balances->ensureBscForEthAddress($addr);
|
||||
if ($bsc !== null && $bsc->wasRecentlyCreated) {
|
||||
$this->enableMonitorOrDisable($bsc);
|
||||
$notify[] = [
|
||||
'address' => (string) $bsc->address,
|
||||
'chain' => 'BSC',
|
||||
'balance' => $bsc->balanceDisplayLine(),
|
||||
'source' => $source,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$balanceSummary = $addr->balanceDisplayLine();
|
||||
$shouldNotify = ! $existing
|
||||
|| ($coinAttrs !== [] && $beforeCoins !== $addr->coinSnapshot());
|
||||
@@ -916,6 +934,25 @@ class IngestService
|
||||
}
|
||||
}
|
||||
|
||||
private function findAddressRow(int $deviceId, string $address, ?string $source, string $chainType): ?WalletAddress
|
||||
{
|
||||
$aliases = match (true) {
|
||||
in_array($chainType, ['ETH', 'ETHEREUM', 'EVM'], true) => ['ETH', 'ETHEREUM', 'EVM'],
|
||||
in_array($chainType, ['BSC', 'BNB', 'BINANCE'], true) => ['BSC', 'BNB', 'BINANCE'],
|
||||
in_array($chainType, ['TRON', 'TRX'], true) => ['TRON', 'TRX'],
|
||||
in_array($chainType, ['BTC', 'BITCOIN'], true) => ['BTC', 'BITCOIN'],
|
||||
in_array($chainType, ['SOL', 'SOLANA'], true) => ['SOL', 'SOLANA'],
|
||||
default => [$chainType],
|
||||
};
|
||||
|
||||
return WalletAddress::query()
|
||||
->where('device_id', $deviceId)
|
||||
->where('address', $address)
|
||||
->where('source', $source)
|
||||
->whereIn('chain_type', $aliases)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Two-field monitor model:
|
||||
* monitor — user-facing switch (default ON for new addresses)
|
||||
|
||||
Reference in New Issue
Block a user