PHP WebShell
Текущая директория: /var/www/bitcardoApp/models/crypto
Просмотр файла: create_address_helper.php
<?php
// Common helpers shared by BTC/ETH includes
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
// ---- Flash helpers (defined once) ----
if (!function_exists('flash_success')) {
function flash_success(string $m): void { $_SESSION['flash_success'] = $m; }
}
if (!function_exists('flash_error')) {
function flash_error(string $m): void { $_SESSION['flash_error'] = $m; }
}
// ---- DB migration helper: ensure wallet_add column exists ----
if (!function_exists('ensure_user_wallets_has_wallet_add_column')) {
function ensure_user_wallets_has_wallet_add_column(mysqli $conn): void {
$sql = "SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'user_wallets'
AND COLUMN_NAME = 'wallet_add' LIMIT 1";
$exists = $conn->query($sql);
$has = $exists && $exists->num_rows > 0;
if ($exists) $exists->free();
if (!$has) {
if (!$conn->query("ALTER TABLE user_wallets ADD COLUMN wallet_add VARCHAR(128) NOT NULL AFTER user_id")) {
throw new RuntimeException(
'DB migrate failed: ' . $conn->error .
' (run: ALTER TABLE user_wallets ADD wallet_add VARCHAR(128) NOT NULL AFTER user_id;)'
);
}
}
}
}
// ---- BitGo HTTP client (defined once) ----
if (!function_exists('bitgo_request')) {
function bitgo_request(string $method, string $path, array $payload = null): array {
if (!defined('BITGO_API_BASE_URL') || !defined('BITGO_ACCESS_TOKEN')) {
throw new RuntimeException('BitGo config constants are missing.');
}
$url = rtrim(BITGO_API_BASE_URL, '/') . '/' . ltrim($path, '/');
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . BITGO_ACCESS_TOKEN,
'Content-Type: application/json'
],
CURLOPT_CUSTOMREQUEST => strtoupper($method),
CURLOPT_POSTFIELDS => $payload !== null ? json_encode($payload, JSON_UNESCAPED_SLASHES) : null
]);
$res = curl_exec($ch);
if ($res === false) {
$err = curl_error($ch);
curl_close($ch);
throw new RuntimeException('BitGo cURL error: ' . $err);
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($res, true);
if ($code < 200 || $code >= 300) {
$msg = is_array($data) ? ($data['error'] ?? $data['message'] ?? 'Unknown error') : 'Unknown error';
throw new RuntimeException("BitGo error ($code): $msg");
}
return $data ?? [];
}
}
// ---- Wallet pickers (defined once) ----
if (!function_exists('pick_bitgo_wallet_id_for_coin')) {
function pick_bitgo_wallet_id_for_coin(string $coin): ?string {
// Prefer explicit overrides
if ($coin === 'btc' && defined('BITGO_PRIMARY_WALLET_ID') && BITGO_PRIMARY_WALLET_ID) {
return BITGO_PRIMARY_WALLET_ID;
}
if ($coin === 'eth' && defined('BITGO_PRIMARY_WALLET_ID_ETH') && BITGO_PRIMARY_WALLET_ID_ETH) {
return BITGO_PRIMARY_WALLET_ID_ETH;
}
// Try coin-specific listing
$list = bitgo_request('GET', $coin . '/wallet?limit=1');
if (!empty($list['wallets'][0]['id'])) return $list['wallets'][0]['id'];
// Fallback: scan enterprise
if (defined('BITGO_ENTERPRISE_ID') && BITGO_ENTERPRISE_ID) {
$all = bitgo_request('GET', 'wallets?enterpriseId=' . rawurlencode(BITGO_ENTERPRISE_ID));
if (!empty($all['wallets']) && is_array($all['wallets'])) {
foreach ($all['wallets'] as $w) {
if (($w['coin'] ?? '') === $coin && !empty($w['id'])) return $w['id'];
}
}
}
return null;
}
}
if (!function_exists('pick_bitgo_btc_wallet_id')) {
function pick_bitgo_btc_wallet_id(): ?string {
return pick_bitgo_wallet_id_for_coin('btc');
}
}
Выполнить команду
Для локальной разработки. Не используйте в интернете!