Example #1
0
    foreach ($json['tx'] as $tx) {
        // Send transaction
        if (!$client->send_transaction($tx['hexcode'])) {
            $template->add_message("Unable to send transaction ID# {$tx['txid']} due to an unknown error from bitcoind.", 'error');
            continue;
        }
        // Update sent
        DB::query("UPDATE coin_sends SET status = 'sent', txid = %s WHERE id = %d", $tx['txid'], $tx['output_id']);
        // Send notifications
        send_notifications('funds_sent', $tx['output_id']);
        // Execute hooks
        execute_hooks('funds_sent', $tx['output_id']);
    }
    // Go through change inputs
    foreach ($json['change_inputs'] as $vars) {
        $client->add_input($vars['address'], $vars['amount'], $vars['txid'], $vars['vout']);
    }
    // Go through spent inputs
    foreach ($json['spent_inputs'] as $vars) {
        DB::query("UPDATE coin_inputs SET is_spent = 1 WHERE txid = %s AND vout = %d", $vars['txid'], $vars['vout']);
    }
    // User message
    if ($template->has_errors != 1) {
        $template->add_message("Successfully broadcast all transactions to the blockchain.");
    }
    // Broadcast transaction
} elseif (isset($_POST['submit']) && $_POST['submit'] == tr('Broadcast Transaction')) {
    // Set variables
    $signed_tx = trim($_POST['signed_hex']);
    $txid = bin2hex(strrev(hash('sha256', hash('sha256', hex2bin($signed_tx), true), true)));
    // Mark inputs as locked