PHP WebShell
Текущая директория: /var/www/bitcardoApp/models/crypto
Просмотр файла: create_eth_user_address.php
<?php
// Create one ETH address for logged-in user (use your existing ETH wallet).
// Trigger: POST/GET create_eth_address=1
// Optional: define('BITGO_PRIMARY_WALLET_ID_ETH', '...') to force a specific ETH wallet id.
try {
if (!isset($conn) || !($conn instanceof mysqli)) throw new RuntimeException('DB connection not available.');
$create = (isset($_POST['create_eth_address']) && $_POST['create_eth_address']=='1')
|| (isset($_GET['create_eth_address']) && $_GET['create_eth_address']=='1');
if (!$create) return;
if (empty($_SESSION['user_id'])) throw new RuntimeException('You must be logged in.');
$userId = (int)$_SESSION['user_id'];
$coin = 'ETH';
ensure_user_wallets_has_wallet_add_column($conn);
// If active ETH exists, reuse it
$stmt = $conn->prepare("SELECT cwallet_id, wallet_add FROM user_wallets WHERE user_id=? AND coin=? AND wallet_status='Active' LIMIT 1");
if (!$stmt) throw new RuntimeException('DB prepare failed: '.$conn->error);
$stmt->bind_param('is', $userId, $coin);
$stmt->execute();
$res = $stmt->get_result();
if ($res && $res->num_rows) {
$row = $res->fetch_assoc();
$stmt->close();
flash_success("ETH address already exists: " . htmlspecialchars($row['wallet_add']));
return;
}
$stmt->close();
// Use existing ETH wallet id (not stored in DB)
$walletId = pick_bitgo_wallet_id_for_coin('eth');
if (!$walletId) throw new RuntimeException('No ETH wallet found in BitGo.');
$addrObj = bitgo_request('POST', "eth/wallet/" . rawurlencode($walletId) . "/address", []);
$address = $addrObj['address'] ?? null;
if (!$address) throw new RuntimeException('BitGo did not return an ETH address.');
// Insert new Active row (do NOT write your PK wallet_id)
$bankName='bitcardo'; $icon='eth.png'; $balance='0.00000000'; $type='crypto'; $label='ETH Wallet'; $status='Active';
$sql = "INSERT INTO user_wallets (user_id, wallet_add, bank_name, coin, icon, balance, type, label, wallet_status)
VALUES (?,?,?,?,?,?,?,?,?)";
$stmt = $conn->prepare($sql);
if (!$stmt) throw new RuntimeException('DB prepare failed: '.$conn->error);
$stmt->bind_param('issssssss', $userId,$address,$bankName,$coin,$icon,$balance,$type,$label,$status);
if (!$stmt->execute()) throw new RuntimeException('DB insert failed: '.$stmt->error);
$stmt->close();
flash_success("ETH address created: " . htmlspecialchars($address));
} catch (Throwable $e) {
flash_error($e->getMessage());
}
Выполнить команду
Для локальной разработки. Не используйте в интернете!