Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Increased Testnet Support #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ <h2>Settings <small> making coinb.in even better!</small></h2>
<option value="dogecoin_mainnet" rel="0x1e;0x9e;0x16;0x0827421e;0x089944e4;chain.so_dogecoin;chain.so_dogecoin">Dogecoin (mainnet)</option>
<option value="carboncoin_mainnet" rel="0x2f;0xaf;0x05;0x488b21e;0x488ade4;cryptoid.info_carboncoin;cryptoid.info_carboncoin">Carboncoin (mainnet)</option>
<option value="shadowcash_mainnet" rel="0x3f;0xbf;0x7d;0xee80286a;0xee8031e8;false;false">ShadowCash (mainnet)</option>
<option value="bitcoin_testnet" rel="0x6f;0xef;0xc4;0x043587cf;0x04358394;false;false">Bitcoin (testnet)</option>
<option value="bitcoin_testnet" rel="0x6f;0xef;0xc4;0x043587cf;0x04358394;blockr.io_bitcointestnet;blockr.io_bitcointestnet">Bitcoin (testnet)</option>

<option value="custom" rel="0x00;0x80;0x05;0x488b21e;0x488ade4;false;false">Custom</option>
</select>
Expand Down Expand Up @@ -1065,7 +1065,7 @@ <h2>Settings <small> making coinb.in even better!</small></h2>
<option value="blockr.io_litecoin"> Blockr.io (Litecoin)</option>
<option value="chain.so_dogecoin"> Chain.so (Dogecoin)</option>
<option value="cryptoid.info_carboncoin"> Cryptoid.info (Carboncoin)</option>
<!-- <option value="blockr.io_bitcointestnet"> Blockr.io (Bitcoin testnet)</option> -->
<option value="blockr.io_bitcointestnet"> Blockr.io (Bitcoin testnet)</option>
</select>
</div>
</div>
Expand All @@ -1079,6 +1079,7 @@ <h2>Settings <small> making coinb.in even better!</small></h2>
<select class="form-control" id="coinjs_utxo">
<option value="coinb.in">coinb.in (Bitcoin mainnet)</option>
<option value="blockr.io_bitcoinmainnet"> Blockr.io (Bitcoin mainnet)</option>
<option value="blockr.io_bitcointestnet"> Blockr.io (Bitcoin testnet)</option>
<option value="chain.so_litecoin"> Chain.so (Litecoin)</option>
<option value="chain.so_dogecoin"> Chain.so (Dogecoin)</option>
<option value="cryptoid.info_carboncoin"> Cryptoid.info (Carboncoin)</option>
Expand Down
84 changes: 80 additions & 4 deletions js/coinbin.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ $(document).ready(function() {

if(host=='blockr.io_bitcoinmainnet'){
listUnspentBlockrio_BitcoinMainnet(redeem);
}
else if(host=='blockr.io_bitcointestnet'){
listUnspentBlockrio_BitcoinTestnet(redeem);
} else if(host=='chain.so_litecoin'){
listUnspentChainso_Litecoin(redeem);
} else if(host=='chain.so_dogecoin'){
Expand Down Expand Up @@ -797,16 +800,20 @@ $(document).ready(function() {
}

/* global function to add outputs to page */
function addOutput(tx, n, script, amount) {
function addOutput(tx, n, script, amount, testnet) {
if(tx){
if($("#inputs .txId:last").val()!=""){
$("#inputs .txidAdd").click();
}

$("#inputs .row:last input").attr('disabled',true);

var txid = ((tx).match(/.{1,2}/g).reverse()).join("")+'';

if (testnet != "yes") {
var txid = ((tx).match(/.{1,2}/g).reverse()).join("")+'';
} else {
var txid = tx;
}

$("#inputs .txId:last").val(txid);
$("#inputs .txIdN:last").val(n);
$("#inputs .txIdAmount:last").val(amount);
Expand Down Expand Up @@ -841,7 +848,7 @@ $(document).ready(function() {
/* retrieve unspent data from blockrio for mainnet */
function listUnspentBlockrio_BitcoinMainnet(redeem){
$.ajax ({
type: "POST",
type: "GET",
url: "https://btc.blockr.io/api/v1/address/unspent/"+redeem.addr+"?unconfirmed=1",
dataType: "json",
error: function(data) {
Expand All @@ -868,6 +875,39 @@ $(document).ready(function() {
}
});
}

/* retrieve unspent data from blockrio for testnet */
function listUnspentBlockrio_BitcoinTestnet(redeem){
$.ajax ({
type: "GET",
url: "https://tbtc.blockr.io/api/v1/address/unspent/"+redeem.addr+"?unconfirmed=0",
dataType: "json",
error: function(data) {
$("#redeemFromStatus").removeClass('hidden').html('<span class="glyphicon glyphicon-exclamation-sign"></span> Unexpected error, unable to retrieve unspent outputs!');
},
success: function(data) {
if((data.status && data.data) && data.status=='success'){
$("#redeemFromAddress").removeClass('hidden').html('<span class="glyphicon glyphicon-info-sign"></span> Retrieved unspent inputs from address <a href="https://tbtc.blockr.io/address/info/'+redeem.addr+'" target="_blank">'+redeem.addr+'</a>');
for(var i in data.data.unspent){
var o = data.data.unspent[i];
var tx = o.tx;
//console.log(tx);
var n = o.n;
var script = (redeem.isMultisig==true) ? $("#redeemFrom").val() : o.script;
var amount = o.amount;
var testnet = "yes";
addOutput(tx, n, script, amount, testnet);
}
} else {
$("#redeemFromStatus").removeClass('hidden').html('<span class="glyphicon glyphicon-exclamation-sign"></span> Unexpected error, unable to retrieve unspent outputs.');
}
},
complete: function(data, status) {
$("#redeemFromBtn").html("Load").attr('disabled',false);
totalInputAmount();
}
});
}

/* retrieve unspent data from blockrio for litecoin */
function listUnspentChainso_Litecoin(redeem){
Expand Down Expand Up @@ -1110,6 +1150,38 @@ $(document).ready(function() {
dataType: "json",
error: function(data) {
var obj = $.parseJSON(data.responseText);
console.log(obj);
var r = ' ';
r += (obj.data) ? obj.data : '';
r += (obj.message) ? ' '+obj.message : '';
r = (r!='') ? r : ' Failed to broadcast'; // build response
$("#rawTransactionStatus").addClass('alert-danger').removeClass('alert-success').removeClass("hidden").html(r).prepend('<span class="glyphicon glyphicon-exclamation-sign"></span>');
},
success: function(data) {
if((data.status && data.data) && data.status=='success'){
$("#rawTransactionStatus").addClass('alert-success').removeClass('alert-danger').removeClass("hidden").html(' Txid: '+data.data);
} else {
$("#rawTransactionStatus").addClass('alert-danger').removeClass('alert-success').removeClass("hidden").html(' Unexpected error, please try again').prepend('<span class="glyphicon glyphicon-exclamation-sign"></span>');
}
},
complete: function(data, status) {
$("#rawTransactionStatus").fadeOut().fadeIn();
$(thisbtn).val('Submit').attr('disabled',false);
}
});
}

// broadcast transaction via blockr.io (testnet)
function rawSubmitBlockrio_BitcoinTestnet(thisbtn){
$(thisbtn).val('Please wait, loading...').attr('disabled',true);
$.ajax ({
type: "POST",
url: "https://tbtc.blockr.io/api/v1/tx/push",
data: {"hex":$("#rawTransaction").val()},
dataType: "json",
error: function(data) {
var obj = $.parseJSON(data.responseText);
//console.log(obj);
var r = ' ';
r += (obj.data) ? obj.data : '';
r += (obj.message) ? ' '+obj.message : '';
Expand Down Expand Up @@ -1720,6 +1792,10 @@ $(document).ready(function() {
$("#rawSubmitBtn").click(function(){
rawSubmitBlockrio_BitcoinMainnet(this);
});
} else if(host=="blockr.io_bitcointestnet"){
$("#rawSubmitBtn").click(function(){
rawSubmitBlockrio_BitcoinTestnet(this);
});
} else if(host=="chain.so_bitcoinmainnet"){
$("#rawSubmitBtn").click(function(){
rawSubmitChainso_BitcoinMainnet(this);
Expand Down