From dd4712130cf3403e7872e67d0ef1217cb335d059 Mon Sep 17 00:00:00 2001 From: Wowee0 Date: Tue, 24 Sep 2019 19:28:16 -0500 Subject: [PATCH] add bitcoin testnet with blockcypher --- index.html | 5 ++-- js/coinbin.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index d0df43e..6d5e018 100644 --- a/index.html +++ b/index.html @@ -1357,8 +1357,7 @@ - - + @@ -1421,6 +1420,7 @@ + @@ -1443,6 +1443,7 @@ + diff --git a/js/coinbin.js b/js/coinbin.js index 69f266d..ed18e2f 100644 --- a/js/coinbin.js +++ b/js/coinbin.js @@ -911,7 +911,7 @@ $(document).ready(function() { // network name "btc" "bitcoin" "BTC" // network name "ltc" "litecoin" "LTC" // network name "doge" "dogecoin" "DOGE" - debugger; + if(host=='chain.so_bitcoinmainnet'){ listUnspentChainso(redeem, "BTC"); } else if(host=='chain.so_litecoin'){ @@ -933,6 +933,8 @@ $(document).ready(function() { } else if(host=='blockchair_dogecoin'){ listUnspentBlockchair(redeem, "dogecoin"); + } else if(host=='blockcypher_bitcointestnet'){ + listUnspentBlockcypherTest(redeem, "btc"); } else if(host=='cryptoid.info_carboncoin'){ listUnspentCryptoidinfo_Carboncoin(redeem); } else { @@ -1111,6 +1113,41 @@ $(document).ready(function() { } + /* retrieve unspent data from blockcypher TESTNET */ + function listUnspentBlockcypherTest(redeem,network){ + $.ajax ({ + type: "GET", + url: "https://api.blockcypher.com/v1/"+network+"/test3/addrs/"+redeem.addr+"?includeScript=true&unspentOnly=true", + dataType: "json", + error: function(data) { + $("#redeemFromStatus").removeClass('hidden').html(' Unexpected error, unable to retrieve unspent outputs!'); + }, + success: function(data) { + if (data.address) { // address field will always be present, txrefs is only present if there are UTXOs + $("#redeemFromAddress").removeClass('hidden').html( + ' Retrieved unspent inputs from address '+redeem.addr+''); + for(var i in data.txrefs){ + var o = data.txrefs[i] + var tx = ((""+o.tx_hash).match(/.{1,2}/g).reverse()).join("")+''; + if(tx.match(/^[a-f0-9]+$/)){ + var n = o.tx_output_n; + var script = (redeem.redeemscript==true) ? redeem.decodedRs : o.script; + var amount = ((o.value.toString()*1)/100000000).toFixed(8); + addOutput(tx, n, script, amount); + } + } + } else { + $("#redeemFromStatus").removeClass('hidden').html(' Unexpected error, unable to retrieve unspent outputs.'); + } + }, + complete: function(data, status) { + $("#redeemFromBtn").html("Load").attr('disabled',false); + totalInputAmount(); + } + }); + } + + /* retrieve unspent data from chain.so for carboncoin */ function listUnspentCryptoidinfo_Carboncoin(redeem) { @@ -1381,6 +1418,32 @@ $(document).ready(function() { }); } + // broadcast transaction via blockcypher.com (testnet) + function rawSubmitblockcypherTest(thisbtn, network){ + $(thisbtn).val('Please wait, loading...').attr('disabled',true); + $.ajax ({ + type: "POST", + url: "https://api.blockcypher.com/v1/"+network+"/test3/txs/push", + data: JSON.stringify({"tx":$("#rawTransaction").val()}), + error: function(data) { + var r = 'Failed to broadcast: error code=' + data.status.toString() + ' ' + data.statusText; + $("#rawTransactionStatus").addClass('alert-danger').removeClass('alert-success').removeClass("hidden").html(r).prepend(''); + }, + success: function(data) { + if((data.tx) && data.tx.hash){ + $("#rawTransactionStatus").addClass('alert-success').removeClass('alert-danger').removeClass("hidden") + .html(' TXID: ' + data.tx.hash + '
View on Blockchain Explorer'); + } else { + $("#rawTransactionStatus").addClass('alert-danger').removeClass('alert-success').removeClass("hidden").html(' Unexpected error, please try again').prepend(''); + } + }, + complete: function(data, status) { + $("#rawTransactionStatus").fadeOut().fadeIn(); + $(thisbtn).val('Submit').attr('disabled',false); + } + }); + } + // broadcast transaction via blockchair function rawSubmitblockchair(thisbtn, network){ $(thisbtn).val('Please wait, loading...').attr('disabled',true); @@ -1958,6 +2021,10 @@ $(document).ready(function() { $("#rawSubmitBtn").click(function(){ rawSubmitcryptoid_Carboncoin(this); }); + } else if(host=="blockcypher_bitcointestnet"){ + $("#rawSubmitBtn").click(function(){ + rawSubmitblockcypherTest(this, "btc"); + }); } else { $("#rawSubmitBtn").click(function(){ rawSubmitDefault(this); // revert to default