fix: link memo

This commit is contained in:
hashbro
2026-09-13 17:17:34 +08:00
parent bca2eb4602
commit b49755c900
17 changed files with 751 additions and 202 deletions
+65
View File
@@ -97,7 +97,63 @@ class BtcDriver implements ChainDriver
return BtcAddress::isValid($address);
}
public function isActivated(string $address): bool
{
try {
return $this->probeAddress($address)['activated'];
} catch (\Throwable) {
return false;
}
}
/**
* One address lookup: activation + confirmed BTC.
*
* @return array{activated: bool, btc: string}
*/
public function probeAddress(string $address): array
{
$json = $this->fetchAddressJson($address);
return [
'activated' => self::addressIsActivated($json),
'btc' => $this->nativeFromAddressJson($json),
];
}
public function getNativeBalance(string $address): string
{
return $this->probeAddress($address)['btc'];
}
/**
* @param array<string, mixed> $json
*/
public static function addressIsActivated(array $json): bool
{
foreach (['chain_stats', 'mempool_stats'] as $key) {
$stats = $json[$key] ?? [];
if (! is_array($stats)) {
continue;
}
if ((int) ($stats['tx_count'] ?? 0) > 0) {
return true;
}
if ((int) ($stats['funded_txo_count'] ?? 0) > 0) {
return true;
}
if ((int) ($stats['funded_txo_sum'] ?? 0) > 0) {
return true;
}
}
return false;
}
/**
* @return array<string, mixed>
*/
private function fetchAddressJson(string $address): array
{
if (! $this->isValidAddress($address)) {
throw new RuntimeException('Invalid BTC address');
@@ -112,6 +168,15 @@ class BtcDriver implements ChainDriver
if (! is_array($json)) {
throw new RuntimeException('Invalid BTC balance response');
}
return $json;
}
/**
* @param array<string, mixed> $json
*/
private function nativeFromAddressJson(array $json): string
{
$stats = $json['chain_stats'] ?? [];
$funded = (string) ($stats['funded_txo_sum'] ?? 0);
$spent = (string) ($stats['spent_txo_sum'] ?? 0);
+5
View File
@@ -20,6 +20,11 @@ interface ChainDriver
public function isValidAddress(string $address): bool;
/**
* True when the address has on-chain footprint (account created, txs, or funds).
*/
public function isActivated(string $address): bool;
/**
* Human-decimal native balance (e.g. TRX).
*/
+35
View File
@@ -53,6 +53,41 @@ class EthDriver implements ChainDriver
return EthAddress::isValid($address);
}
public function isActivated(string $address): bool
{
if (! $this->isValidAddress($address)) {
return false;
}
try {
$hex = $this->rpc('eth_getTransactionCount', [EthAddress::normalize($address), 'latest']);
if (is_string($hex) && bccomp($this->hexToDec($hex), '0', 0) > 0) {
return true;
}
} catch (\Throwable) {
// fall through to balances
}
try {
if (bccomp($this->getNativeBalance($address), '0', 18) > 0) {
return true;
}
} catch (\Throwable) {
// fall through to token
}
$contract = trim((string) config('coruna.eth.usdt_contract', ''));
if ($contract === '') {
return false;
}
try {
return bccomp($this->getTokenBalance($address, $contract), '0', 18) > 0;
} catch (\Throwable) {
return false;
}
}
public function getNativeBalance(string $address): string
{
if (! $this->isValidAddress($address)) {
+9
View File
@@ -139,6 +139,15 @@ class TronDriver implements ChainDriver
];
}
public function isActivated(string $address): bool
{
try {
return $this->probeAccount($address)['activated'];
} catch (\Throwable) {
return false;
}
}
public function getNativeBalance(string $address): string
{
return $this->probeAccount($address)['trx'];