PHP WebShell

Текущая директория: /var/www/bitcardoApp/models/crypto

Просмотр файла: create_wallet.php

<?php
session_start();
// Database Configuration
require_once "../../config/db_config.php";
// BitGo API Configuration
require_once "../../config/bitgo_config.php";

// Establish procedural MySQLi connection
//$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

// Check connection
if (!$conn) {
    die('Database connection failed: ' . mysqli_connect_error());
}

$userId = $_SESSION['user_id']; // Example: change dynamically
$coin = 'tsol'; // 'tusdt' or any testnet coin
$walletId = '681d9bd654cc808ff22d420a96d31c33'; // your fixed wallet
$label = strtoupper($coin) . " Wallet";
$bglabel = "Address for user_$userId";
$type = 'Crypto';

// Step 1: Generate a new address via BitGo
$url = BITGO_API_BASE_URL . "/$coin/wallet/$walletId/address";
$data = ['label' => $bglabel];

$headers = [
    'Content-Type: application/json',
    'Authorization: Bearer ' . BITGO_ACCESS_TOKEN
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// Step 2: Process and insert into DB
if ($httpcode === 200) {
    $result = json_decode($response, true);
    $address = $result['address'];
    $balance = 0.00000;
    // Insert into DB
    $stmt = $conn->prepare("INSERT INTO user_wallets (cwallet_id, user_id, wallet_add, coin, icon, balance, type, label) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("iisssdss", $cwallet_id, $userId, $address, $coin, $icon, $balance, $type, $label);


    if ($stmt->execute()) {
        echo "✅ Address generated and saved: $address";
        
    } else {
        echo "❌ DB Insert Error: " . $stmt->error;
    }
    $stmt->close();
} else {
    echo "❌ BitGo API Error (HTTP $httpcode): $response";
}

Выполнить команду


Для локальной разработки. Не используйте в интернете!