Exemplo n.º 1
0
 if ($template->has_errors != 1) {
     // Online send
     if ($_POST['signing_method'] == 'online') {
         // Gather private keys
         $x = 1;
         $privkeys = array();
         while (1) {
             $var = 'private_key' . $x;
             if (!isset($_POST[$var])) {
                 break;
             }
             $privkeys[] = trim($_POST[$var]);
             $x++;
         }
         // Gather inputs
         $client = new rawtx();
         if (!($inputs = $client->gather_inputs($_POST['wallet_id'], $send_amount, $privkeys))) {
             $template->add_message('Unable to find enough spendable inputs for this transaction.  Please verify public keys via the Settings->Wallets menu.', 'error');
             $template->parse();
             exit(0);
         }
         // Create transaction
         $transaction = $client->create_transaction($_POST['wallet_id'], $inputs, $outputs);
         // Sign transaction
         $signed_tx = $client->sign_transaction($transaction, $inputs);
         $txid = bin2hex(strrev(hash('sha256', hash('sha256', hex2bin($signed_tx), true), true)));
         // Mark inputs as locked
         foreach ($inputs as $input) {
             DB::query("UPDATE coin_inputs SET is_locked = 1 WHERE id = %d", $input['input_id']);
         }
         // Send transaction
Exemplo n.º 2
0
        $var = 'private_key' . $x;
        if (!isset($_POST[$var])) {
            break;
        }
        $privkeys[] = $_POST[$var];
        $x++;
    }
    // Get total inputs
    $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}.");
}
Exemplo n.º 3
0
        foreach ($addr_rows as $addr_row) {
            // Get public key & index
            $public_key = trim($enc->decrypt(DB::queryFirstField("SELECT public_key FROM coin_wallets_keys WHERE id = %d", $addr_row['key_id'])));
            $keyindex = $is_change . '/' . $addr_row['address_num'];
            $keyindexes[] = $keyindex;
            // Generate child key
            $child_ext_key = $bip32->build_key($public_key, $keyindex)[0];
            $public_keys[] = $bip32->import($child_ext_key)['key'];
        }
        $scriptsig = $bip32->create_redeem_script($wallet['sigs_required'], $public_keys);
        $keyindex = implode(", ", $keyindexes);
    } else {
        $addr_row = DB::queryFirstRow("SELECT * FROM coin_addresses WHERE address = %s", $row['address']);
        $keyindex = $addr_row['is_change_address'] . '/' . $addr_row['address_num'];
        $decode_address = $bip32->base58_decode($row['address']);
        $scriptsig = '76a914' . substr($decode_address, 2, 40) . '88ac';
    }
    // Add input
    $vars = array('input_id' => $row['id'], 'txid' => $row['txid'], 'vout' => $row['vout'], 'amount' => $row['amount'], 'keyindex' => $keyindex, 'scriptsig' => $scriptsig);
    array_push($inputs, $vars);
    $input_ids[] = $row['id'];
}
// Create transaction
$client = new rawtx();
$trans = $client->create_transaction($send['wallet_id'], $inputs, $outputs);
// Template variables
$template->assign('send_id', $_REQUEST['send_id']);
$template->assign('sigs_required', $sigs_required);
$template->assign('hexcode', implode("", $trans));
$template->assign('inputs', $inputs);
$template->assign('input_ids', implode(",", $input_ids));