fix: link memo
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user