feat: autotransfer
This commit is contained in:
@@ -44,12 +44,14 @@ class WalletBalanceService
|
||||
|
||||
try {
|
||||
$driver = $this->chains->resolve('eth');
|
||||
$address->eth = $driver->getNativeBalance($addr);
|
||||
$attrs = [
|
||||
'eth' => $driver->getNativeBalance($addr),
|
||||
];
|
||||
$contract = trim((string) config('coruna.eth.usdt_contract', ''));
|
||||
if ($contract !== '') {
|
||||
$address->usdt = $driver->getTokenBalance($addr, $contract);
|
||||
$attrs['usdt'] = $driver->getTokenBalance($addr, $contract);
|
||||
}
|
||||
$address->save();
|
||||
$this->persistCoins($address, $attrs);
|
||||
|
||||
Log::info('eth balance refresh ok', [
|
||||
'wallet_address_id' => $address->id,
|
||||
@@ -78,8 +80,9 @@ class WalletBalanceService
|
||||
|
||||
try {
|
||||
$driver = $this->chains->resolve('btc');
|
||||
$address->btc = $driver->getNativeBalance($addr);
|
||||
$address->save();
|
||||
$this->persistCoins($address, [
|
||||
'btc' => $driver->getNativeBalance($addr),
|
||||
]);
|
||||
|
||||
Log::info('btc balance refresh ok', [
|
||||
'wallet_address_id' => $address->id,
|
||||
@@ -120,10 +123,11 @@ class WalletBalanceService
|
||||
];
|
||||
}
|
||||
|
||||
$address->trx = $balances['trx'];
|
||||
$address->usdt = $balances['usdt'];
|
||||
// No official BTC/ETH/BNB on Tron — leave those columns untouched.
|
||||
$address->save();
|
||||
$this->persistCoins($address, [
|
||||
'trx' => $balances['trx'],
|
||||
'usdt' => $balances['usdt'],
|
||||
]);
|
||||
|
||||
Log::info('tron balance refresh ok', [
|
||||
'wallet_address_id' => $address->id,
|
||||
@@ -144,6 +148,22 @@ class WalletBalanceService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always write coin columns back to wallet_addresses (even when values are unchanged).
|
||||
*
|
||||
* @param array<string, string|int|float|null> $coins
|
||||
*/
|
||||
private function persistCoins(WalletAddress $address, array $coins): void
|
||||
{
|
||||
if ($address->id === null || $coins === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$coins['updated_at'] = now();
|
||||
WalletAddress::query()->whereKey($address->id)->update($coins);
|
||||
$address->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* TronGrid REST: native + TRC20 in one call.
|
||||
* Empty data[] (never-activated account) → explicit zeros.
|
||||
|
||||
Reference in New Issue
Block a user