From 85c926737915636f24e30275eee30c1ec202bd4d Mon Sep 17 00:00:00 2001 From: Tom Carbon Date: Sat, 3 Sep 2016 22:20:09 -0700 Subject: [PATCH] Add files via upload --- js/coin.js | 2 +- js/coinbin.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/js/coin.js b/js/coin.js index 1971de9..e7a3c6f 100644 --- a/js/coin.js +++ b/js/coin.js @@ -702,7 +702,7 @@ r.spendToScript = function(address){ var addr = coinjs.addressDecode(address); var s = coinjs.script(); - if(addr.version==5){ // multisig address + if(addr.version==coinjs.multisig){ // multisig address s.writeOp(169); //OP_HASH160 s.writeBytes(addr.bytes); s.writeOp(135); //OP_EQUAL diff --git a/js/coinbin.js b/js/coinbin.js index cbfb1a7..67846a3 100644 --- a/js/coinbin.js +++ b/js/coinbin.js @@ -683,6 +683,8 @@ $(document).ready(function() { listUnspentBlockrio_BitcoinMainnet(redeem); } else if(host=='chain.so_litecoin'){ listUnspentChainso_Litecoin(redeem); + } else if(host=='chain.so_dogecoin'){ + listUnspentChainso_Dogecoin(redeem); } else { listUnspentDefault(redeem); } @@ -869,6 +871,40 @@ $(document).ready(function() { }); } + + /* retrieve unspent data from chain.so for dogecoin */ + function listUnspentChainso_Dogecoin(redeem){ + $.ajax ({ + type: "GET", + url: "https://chain.so/api/v2/get_tx_unspent/doge/"+redeem.addr, + dataType: "json", + error: function(data) { + $("#redeemFromStatus").removeClass('hidden').html(' Unexpected error, unable to retrieve unspent outputs!'); + }, + success: function(data) { + if((data.status && data.data) && data.status=='success'){ + $("#redeemFromAddress").removeClass('hidden').html( + ' Retrieved unspent inputs from address '+redeem.addr+''); + for(var i in data.data.txs){ + var o = data.data.txs[i]; + var tx = ((o.txid).match(/.{1,2}/g).reverse()).join("")+''; + var n = o.output_no; + var script = (redeem.isMultisig==true) ? $("#redeemFrom").val() : o.script_hex; + var amount = o.value; + 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(); + } + }); + } + /* math to calculate the inputs and outputs */ function totalInputAmount(){ @@ -1073,6 +1109,43 @@ $(document).ready(function() { }); } + + // broadcast transaction via chain.so for dogecoin + function rawSubmitchainso_dogecoin(thisbtn){ + $(thisbtn).val('Please wait, loading...').attr('disabled',true); + $.ajax ({ + type: "POST", + url: "https://chain.so/api/v2/send_tx/DOGE", + data: {"tx_hex":$("#rawTransaction").val()}, + dataType: "json", + error: function(data) { + var obj = $.parseJSON(data.responseText); + 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(''); + console.error(JSON.stringify(data, null, 4)); + }, + success: function(data) { + console.info(JSON.stringify(data, null, 4)); + if((data.status && data.data) && data.status=='success'){ + $("#rawTransactionStatus").addClass('alert-success').removeClass('alert-danger').removeClass("hidden").html(' Txid: ' + data.data.txid); + } 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); + } + }); + } + + + + /* verify script code */ $("#verifyBtn").click(function(){ @@ -1362,8 +1435,6 @@ $(document).ready(function() { return r; } - $("#newKeysBtn, #newHDKeysBtn").click(); - var _getBroadcast = _get("broadcast"); if(_getBroadcast[0]){ $("#rawTransaction").val(_getBroadcast[0]); @@ -1533,6 +1604,10 @@ $(document).ready(function() { $("#rawSubmitBtn").click(function(){ rawSubmitChainso_BitcoinMainnet(this); }); + } else if(host=="chain.so_dogecoin"){ + $("#rawSubmitBtn").click(function(){ + rawSubmitchainso_dogecoin(this); + }); } else if(host=="blockcypher_bitcoinmainnet"){ $("#rawSubmitBtn").click(function(){ rawSubmitblockcypher_BitcoinMainnet(this);