$balance = DB::queryFirstField("SELECT sum(amount) FROM coin_inputs WHERE wallet_id = %d AND is_spent = 0", $_POST['wallet_id']); $total_inputs = DB::queryFirstField("SELECT count(*) FROM coin_inputs WHERE wallet_id = %d AND is_spent = 0", $_POST['wallet_id']); $balance -= $total_inputs * $config['btc_txfee']; // Generate address from new wallet $address = $bip32->generate_address($new_wallet_id); $outputs = array($address => $balance); // Gather all unspent inputs $client = new rawtx(); $inputs = $client->gather_inputs($_POST['wallet_id'], $balance, $privkeys); // Create transaction $transaction = $client->create_transaction($_POST['wallet_id'], $inputs, $outputs); // Sign transaction $signed_tx = $client->sign_transaction($transaction, $inputs); // Send transaction $client = new transaction(); $client->send_transaction($signed_tx); // Update wallets DB::query("UPDATE coin_wallets SET status = 'inactive' WHERE id = %d", $_POST['wallet_id']); DB::query("UPDATE coin_inputs SET is_spent = 1 WHERE wallet_id = %d", $_POST['wallet_id']); // User message $balance = fmoney_coin($balance); $template->add_message("Successfully transferred your wallet to the new BIP32 keys. A total of {$balance} BTC was transferred to your new BIP32 key(s), and your new wallet ID# is {$new_wallet_id}."); } // Get wallets $first = true; $bip32_key_fields = ''; $bip32_public_key_fields = ''; $required_sigs = 0; $total_sigs = 0; $wallet_id = 0; $wallet_javascript = '';