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 bitcoin testnet testnet.blockexplorer.com #133

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
23 changes: 19 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -636,19 +636,32 @@ <h2>Transaction <small>Create a new transaction</small></h2>
<p>Enter the address and amount you wish to make a payment to.</p>
<div class="row">
<div class="col-xs-8">
<label><abbr title="Address to send to">Address</abbr></label>
<label><abbr title="Address to send to">Recipient addresses</abbr></label>
</div>
<div class="col-xs-3">
<label><abbr title="Amount to send">Amount</abbr></label>
</div>
<div class="col-xs-1">
</div>
</div>

<div id="recipients">
<p>Address of sender for returning unspent amount: </p>
<div class="row recipient">
<div class="col-xs-8">
<input type="text" id="returnoutputaddress" class="form-control address" placeholder="" data-original-title="" title="" readonly>
</div>
<div class="col-xs-3">
<input type="text" id="returnoutputamount" class="form-control amount" placeholder="" data-original-title="" title="">
</div>
<div class="col-xs-1">
<a href="javascript:;" class="addressAddTo" hidden><span class="glyphicon glyphicon-plus"></span></a>
</div>
<br><br><br>
</div>
<p>Recipients: </p>
<div class="row recipient">
<div class="col-xs-8">
<input type="text" class="form-control address" placeholder="1">
<input type="text" class="form-control address" placeholder="">
</div>
<div class="col-xs-3">
<input type="text" class="form-control amount" placeholder="0.00">
Expand Down Expand Up @@ -1090,7 +1103,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;bexp_bitcointestnet;bexp_bitcointestnet">Bitcoin (testnet)</option>

<option value="custom" rel="0x00;0x80;0x05;0x488b21e;0x488ade4;false;false">Custom</option>
</select>
Expand Down Expand Up @@ -1146,6 +1159,7 @@ <h2>Settings <small> making coinb.in even better!</small></h2>
<option value="coinb.in">coinb.in (Bitcoin mainnet)</option>
<option value="chain.so_bitcoinmainnet"> Chain.so (Bitcoin mainnet)</option>
<option value="blockcypher_bitcoinmainnet"> Blockcypher.com (Bitcoin mainnet)</option>
<option value="bexp_bitcointestnet"> blockexplorer (Bitcoin testnet)</option>
<option value="chain.so_dogecoin"> Chain.so (Dogecoin)</option>
<option value="cryptoid.info_carboncoin"> Cryptoid.info (Carboncoin)</option>
</select>
Expand All @@ -1160,6 +1174,7 @@ <h2>Settings <small> making coinb.in even better!</small></h2>
<p class="text-muted">Select the network you wish to retreive your unspent inputs from</p>
<select class="form-control" id="coinjs_utxo">
<option value="coinb.in">coinb.in (Bitcoin mainnet)</option>
<option value="bexp_bitcointestnet"> blockexplorer (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
70 changes: 68 additions & 2 deletions js/coinbin.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ $(document).ready(function() {

$("#redeemFromBtn").click(function(){
var redeem = redeemingFrom($("#redeemFrom").val());

document.getElementById("returnoutputaddress").value = redeem.addr;
$("#redeemFromStatus, #redeemFromAddress").addClass('hidden');

if(redeem.from=='multisigAddress'){
Expand Down Expand Up @@ -782,6 +782,8 @@ $(document).ready(function() {
listUnspentChainso_Dogecoin(redeem);
} else if(host=='cryptoid.info_carboncoin'){
listUnspentCryptoidinfo_Carboncoin(redeem);
} else if(host=='bexp_bitcointestnet'){
listUnspentbexp_bitcointestnet(redeem);
} else {
listUnspentDefault(redeem);
}
Expand Down Expand Up @@ -1014,7 +1016,40 @@ $(document).ready(function() {
}
});
}

/* retrieve unspent data from blockexplorer.com for bitcoin (testnet) */
function listUnspentbexp_bitcointestnet(redeem){
var bp = "https://testnet.blockexplorer.com/api/addr/"+redeem.addr+"/utxo";
$.ajax ({
type: "GET",
url: "https://testnet.blockexplorer.com/api/addr/"+redeem.addr+"/utxo",
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[0].address)){
$("#redeemFromAddress").removeClass('hidden').html(
'<span class="glyphicon glyphicon-info-sign"></span> Retrieved unspent inputs from address <a href="'+explorer_addr+redeem.addr+'" target="_blank">'+redeem.addr+'</a>');
for (var i = 0; i < data.length; i++) {
var o = data[i];
var tx = ((""+o.txid).match(/.{1,2}/g).reverse()).join("")+'';
if(tx.match(/^[a-f0-9]+$/)){
var n = o.vout;
var script = (redeem.isMultisig==true) ? $("#redeemFrom").val() : o.scriptPubKey;
var amount = o.amount;
addOutput(tx, n, script, amount);
}
}
} 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();
}
});
}

/* math to calculate the inputs and outputs */

function totalInputAmount(){
Expand Down Expand Up @@ -1186,6 +1221,33 @@ $(document).ready(function() {
});
}

// broadcast transaction via blockexplorer.com (testnet)
function rawSubmitbexp_bitcointestnet(thisbtn){
$(thisbtn).val('Please wait, loading...').attr('disabled',true);
var sendtr = {'tx':$("#rawTransaction").val()};
$.ajax ({
type: "POST",
url: "https://testnet.blockexplorer.com/api/tx/send",
data: {'rawtx':$("#rawTransaction").val()},
error: function(res) {
var r = ' ';
r += (res.responseText) ? res.responseText : '';
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(res) {
if(res.txid){
$("#rawTransactionStatus").addClass('alert-success').removeClass('alert-danger').removeClass("hidden").html(' Txid: '+res.txid+'<br> Check this transaction by searching Txid on <a href="https://testnet.blockexplorer.com/">testnet.blockexplorer.com</a>');
} else {
$("#rawTransactionStatus").addClass('alert-danger').removeClass('alert-success').removeClass("hidden").html(' Unexpected error, please try again. Response error text: ').res.responseText.prepend('<span class="glyphicon glyphicon-exclamation-sign"></span>');
}
},
complete: function(data, status) {
$("#rawTransactionStatus").fadeOut().fadeIn();
$(thisbtn).val('Submit').attr('disabled',false);
}
});
}

// broadcast transaction via chain.so for dogecoin
function rawSubmitchainso_dogecoin(thisbtn){
Expand Down Expand Up @@ -1708,6 +1770,10 @@ $(document).ready(function() {
$("#rawSubmitBtn").click(function(){
rawSubmitcryptoid_Carboncoin(this);
});
} else if(host=="bexp_bitcointestnet"){
$("#rawSubmitBtn").click(function(){
rawSubmitbexp_bitcointestnet(this);
});
} else {
$("#rawSubmitBtn").click(function(){
rawSubmitDefault(this); // revert to default
Expand Down