From c8436856626e3f055c6ce80485a69c94cdd85f9c Mon Sep 17 00:00:00 2001 From: OutCast3k Date: Mon, 1 Jan 2018 18:53:23 +0000 Subject: [PATCH] added new #fee section to coinb.in --- images/btc32x.png | Bin 0 -> 1413 bytes index.html | 190 ++++++++++++++++++++++++++++-- js/coinbin.js | 290 +++++++++++++++++++++++++++++++++++++++++++++- sha1sum | 8 +- 4 files changed, 470 insertions(+), 18 deletions(-) create mode 100644 images/btc32x.png diff --git a/images/btc32x.png b/images/btc32x.png new file mode 100644 index 0000000000000000000000000000000000000000..442dcaad0db90a802220c7f837ea46e7852584f6 GIT binary patch literal 1413 zcmV;01$z34P)Px)FG)l}R9M5US6ggVMHC&1(1JqSnR7uAQpBo_F%taI z1e8d`4~_b#pMEKc(N7-{p*%{T_dH7!%K<57$b$CJPK5x(khfk zUv@9E&)nwpan9|bVUo!`=gyp2d(U2b?HM6rHWU}+U~6IpJoORTs)cOTPL}$cY}G}M zI!=!IhFtX_d5PuZ7G{gP)u<}>A*wc#J0E)a*ZVH z+{IG{h7eig%C+Pfz1Wrjstv$W@jB1lmH>atYe0x;cjoox{6*xdgV>(X-o*tT-}&3^ z3Eq(dR4y0B^L&dcB2RVr+nEu-0Lrt0idmBz(vSdEt8qv!Hk^#;gO=cz(12=}~MOeaenMMDI*DK$vdeHxsB zZe0cXuj{dvH-LTb0M(0tWM0Vk>7B6D5fqE8iQb!Xy&rQc0^FGoeEAAc_ZYBQ01Z#T zZ|B;8jRLrOLcecc22{?D-Z|z(Qhq!x)$$6+QT^~DKH^w6J+A=ZU9chx{q$%CxP8>0%i9AmWYx2osYHsJs_gCxE?c zf-xo~X9|yntyjxokb9Vb=VHli`AlHv>QV70;BbjHqG2h}v_ zAJF=i4vn3NV}LpjH$%bU*t57e_X9Ua#lQJA9d{;QT@i44Z!k7^Q`ZUBgbbCEOnH_$ z@I7jb=z_Dg0I=r)yIu+a26}pW-?4HL{f8rjo9@vaBxGoF=6e-C9N4FAqtJZ z`iIPgvve^^%KFG+#EbA&atZD^r3u#ZI&kqwnh!UEdN4c$bp8l5KBINRGNOx-C2N9e zSeba3Ts0V(4V(p^KbwyKAz-ZlI)2da{QtHmfiG49pFX7xX7<|=;I85`;sC7NC1cM7 zNmUwoAmIgfzNpoWW9u%^;MY2|aXikQ4@H~K(gs*;e4hnPv0{M9F<8KMV%QIUX| zr%y%4n}9-6m-+XD0fc z-HzT9+3<{V^3;H@l-?cQi1cNoj~rFX{F?gZ)Rm8ur&8pq9zQIp1pL~;-r4ES&o${W z-fl;AlV{YyQ$=_0mh8&8R4rGNqe{q;ZDh&6$dUtox8)`OKUZz>=TxXUao7DHfAdKf TINcB<00000NkvXXu0mjf+U=-D literal 0 HcmV?d00001 diff --git a/index.html b/index.html index f476ee0..bf91bb2 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ Bitcoin Wallet by Coinb.in - + @@ -74,6 +74,7 @@
  • About
  • + @@ -119,7 +120,7 @@

    Wallet

    -

    Quick access to an online wallet where only you have access to your own private keys!

    +

    Quick access to an online wallet where only you have access to your own private keys & can calculate your own fee!

    @@ -199,6 +200,12 @@ @@ -246,7 +248,7 @@
    - +
    @@ -708,7 +710,7 @@
    - +
    @@ -733,6 +735,176 @@
    + +
    +

    Bitcoin Fee Calculator

    +

    This page will give you a guide on the lowest fee to use to get your transaction included within the next few blocks. It works by predicting the size of a transaction and comparing it to another transaction in a recent block to determine an appropriate fee.

    + +
    +

    Recommended Fee: 0.00000000 BTC
    for a transaction of 0 bytes

    + ? Sat/Byte +
    + +
    +
    + +
    0
    Inputs
    +
    +
    + 0 Bytes +
    + +

    Regular Compressed + 1 + 148 bytes + +

    + + +

    SegWit + 0 + 0 bytes + +

    + + +

    MultiSig + 0 + 0 bytes + +

    + + +

    Hodl Time Locked + 0 + 0 bytes + +

    + + +

    Unknown + 0 + 0 bytes + +

    + + +
    +
    + +
    + +
    0
    Outputs
    +
    +
    + 0 Bytes +
    + +

    Regular p2pkh (1...) + 2 + 68 bytes + +

    + + +

    Regular p2sh (3...) + 0 + 0 bytes + +

    + + +
    +
    +
    + +
    + +
    +
    +
    Chargable Transaction Size: 0 bytes
    +
    +
    + +
    + +
    + +
    + +
    + + + + +
    +

    Verify transactions and other scripts

    diff --git a/js/coinbin.js b/js/coinbin.js index e07ef05..547572b 100644 --- a/js/coinbin.js +++ b/js/coinbin.js @@ -635,21 +635,84 @@ $(document).ready(function() { if(!$("#recipients .row, #inputs .row").hasClass('has-error')){ + $("#transactionCreate textarea").val(tx.serialize()); $("#transactionCreate .txSize").html(tx.size()); - $("#transactionCreate").removeClass("hidden"); + if($("#feesestnewtx").attr('est')=='y'){ + $("#fees .txhex").val($("#transactionCreate textarea").val()); + $("#analyseBtn").click(); + $("#fees .txhex").val(""); + window.location = "#fees"; + } else { - // Check fee against hard 0.01 as well as fluid 200 satoshis per byte calculation. - if($("#transactionFee").val()>=0.01 || $("#transactionFee").val()>= estimatedTxSize * 200 * 1e-8){ - $("#modalWarningFeeAmount").html($("#transactionFee").val()); - $("#modalWarningFee").modal("show"); + $("#transactionCreate").removeClass("hidden"); + + // Check fee against hard 0.01 as well as fluid 200 satoshis per byte calculation. + if($("#transactionFee").val()>=0.01 || $("#transactionFee").val()>= estimatedTxSize * 200 * 1e-8){ + $("#modalWarningFeeAmount").html($("#transactionFee").val()); + $("#modalWarningFee").modal("show"); + } } + $("#feesestnewtx").attr('est',''); } else { $("#transactionCreateStatus").removeClass("hidden").html("One or more input or output is invalid").fadeOut().fadeIn(); } }); + $("#feesestnewtx").click(function(){ + $(this).attr('est','y'); + $("#transactionBtn").click(); + }); + + $("#feesestwallet").click(function(){ + $(this).attr('est','y'); + var outputs = $("#walletSpendTo .output").length; + + $("#fees .inputno, #fees .outputno, #fees .bytes").html(0); + $("#fees .slider").val(0); + + var tx = coinjs.transaction(); + tx.listUnspent($("#walletAddress").html(), function(data){ + var inputs = $(data).find("unspent").children().length; + if($("#walletSegwit").is(":checked")){ + $("#fees .txi_segwit").val(inputs); + $("#fees .txi_segwit").change(); + } else { + $("#fees .txi_regular").val(inputs); + $("#fees .txi_regular").change(); + } + + $.each($("#walletSpendTo .output"), function(i,o){ + var addr = $('.addressTo',o); + var ad = coinjs.addressDecode(addr.val()); + if (ad.version == coinjs.multisig){ // p2sh + $("#fees .txo_p2sh").val(($("#fees .txo_p2sh").val()*1)+1); + $("#fees .txo_p2sh").change(); + } else { // p2pkh + $("#fees .txo_p2pkh").val(($("#fees .txo_p2pkh").val()*1)+1); + $("#fees .txo_p2pkh").change(); + } + }); + + if(($("#developerDonation").val()*1)>0){ + var addr = coinjs.developer; + var ad = coinjs.addressDecode(addr); + if (ad.version == coinjs.multisig){ // p2sh + $("#fees .txo_p2sh").val(($("#fees .txo_p2sh").val()*1)+1); + $("#fees .txo_p2sh").change(); + } else { // p2pkh + $("#fees .txo_p2pkh").val(($("#fees .txo_p2pkh").val()*1)+1); + $("#fees .txo_p2pkh").change(); + } + } + + }); + + //feeStats(); + window.location = "#fees"; + }); + $(".txidClear").click(function(){ $("#inputs .row:first input").attr('disabled',false); $("#inputs .row:first input").val(""); @@ -1549,6 +1612,12 @@ $(document).ready(function() { window.location.hash = "#verify"; } + $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { + if(e.target.hash == "#fees"){ + feeStats(); + } + }) + $(".qrcodeBtn").click(function(){ $("#qrcode").html(""); var thisbtn = $(this).parent().parent(); @@ -1719,6 +1788,216 @@ $(document).ready(function() { $("#redeemFromBtn").attr('rel',$("#coinjs_utxo option:selected").val()); } + + /* fees page code */ + + $("#fees .slider").change(function(){ + $('.'+$(this).attr('rel')+' .inputno, .'+$(this).attr('rel')+' .outputno',$(this).parent()).html($(this).val()); + $('.'+$(this).attr('rel')+' .estimate',$(this).parent()).removeClass('hidden'); + }); + + $("#fees .txo_p2pkh").change(function(){ + var outputno = $('.'+$(this).attr('rel')+' .outputno',$(this).parent()).html(); + $('.'+$(this).attr('rel')+' .bytes',$(this).parent()).html((outputno*$("#est_txo_p2pkh").val())+(outputno*9)); + mathFees(); + }); + + $("#fees .txo_p2sh").change(function(){ + var outputno = $('.'+$(this).attr('rel')+' .outputno',$(this).parent()).html(); + $('.'+$(this).attr('rel')+' .bytes',$(this).parent()).html((outputno*$("#est_txo_p2sh").val())+(outputno*9)); + mathFees(); + }); + + $("#fees .txi_regular").change(function(){ + var inputno = $('.'+$(this).attr('rel')+' .inputno',$(this).parent()).html(); + $('.'+$(this).attr('rel')+' .bytes',$(this).parent()).html((inputno*$("#est_txi_regular").val())+(inputno*41)); + mathFees(); + }); + + $("#fees .txi_segwit").change(function(){ + var inputno = $('.'+$(this).attr('rel')+' .inputno',$(this).parent()).html(); + var bytes = 0; + if(inputno >= 1){ + bytes = 2; + bytes += (inputno*32); + bytes += (inputno*$("#est_txi_segwit").val()); + bytes += (inputno*(41)) + } + + bytes = bytes.toFixed(0); + $('.'+$(this).attr('rel')+' .bytes',$(this).parent()).html(bytes); + mathFees(); + }); + + $("#fees .txi_multisig").change(function(){ + var inputno = $('.'+$(this).attr('rel')+' .inputno',$(this).parent()).html(); + $('.'+$(this).attr('rel')+' .bytes',$(this).parent()).html((inputno*$("#est_txi_multisig").val())+(inputno*41)); + mathFees(); + }); + + $("#fees .txi_hodl").change(function(){ + var inputno = $('.'+$(this).attr('rel')+' .inputno',$(this).parent()).html(); + $('.'+$(this).attr('rel')+' .bytes',$(this).parent()).html((inputno*$("#est_txi_hodl").val())+(inputno*41)); + mathFees(); + }); + + $("#fees .txi_unknown").change(function(){ + var inputno = $('.'+$(this).attr('rel')+' .inputno',$(this).parent()).html(); + $('.'+$(this).attr('rel')+' .bytes',$(this).parent()).html((inputno*$("#est_txi_unknown").val())+(inputno*41)); + mathFees(); + }); + + $("#advancedFeesCollapse").click(function(){ + if($("#advancedFees").hasClass('hidden')){ + $("span",this).removeClass('glyphicon-collapse-down').addClass('glyphicon-collapse-up'); + $("#advancedFees").removeClass("hidden"); + } else { + $("span",this).removeClass('glyphicon-collapse-up').addClass('glyphicon-collapse-down'); + $("#advancedFees").addClass("hidden"); + } + }); + + $("#analyseBtn").click(function(){ + if(!$("#fees .txhex").val().match(/^[a-f0-9]+$/ig)){ + alert('You must provide a hex encoded transaction'); + return; + } + + var tx = coinjs.transaction(); + var deserialized = tx.deserialize($("#fees .txhex").val()); + + $("#fees .txoutputs .outputno, #fees .txinputs .inputno").html("0"); + $("#fees .txoutputs .bytes, #fees .txinputs .bytes").html("0"); + $("#fees .slider").val(0); + + for(var i = 0; i < deserialized.ins.length; i++){ + var script = deserialized.extractScriptKey(i); + var size = 41; + if(script.type == 'segwit'){ + if(deserialized.witness[i]){ + size += deserialized.ins[i].script.buffer.length / 2; + for(w in deserialized.witness[i]){ + size += (deserialized.witness[i][w].length / 2) /4; + } + } else { + size += $("#est_txi_segwit").val()*1; + } + size = size.toFixed(0); + $("#fees .segwit .inputno").html(($("#fees .segwit .inputno").html()*1)+1); + $("#fees .txi_segwit").val(($("#fees .txi_segwit").val()*1)+1); + $("#fees .segwit .bytes").html(size); + + } else if(script.type == 'multisig'){ + var s = coinjs.script(); + var rs = s.decodeRedeemScript(script.script); + size += 4 + ((script.script.length / 2) + (73 * rs.signaturesRequired)); + $("#fees .multisig .inputno").html(($("#fees .multisig .inputno").html()*1)+1); + $("#fees .txi_multisig").val(($("#fees .txi_multisig").val()*1)+1); + $("#fees .multisig .bytes").html(size); + + } else if(script.type == 'hodl'){ + size += 78; + $("#fees .hodl .inputno").html(($("#fees .hodl .inputno").html()*1)+1); + $("#fees .hodl .bytes").html(size); + $("#fees .txi_hodl").val(($("#fees .txi_hodl").val()*1)+1); + + } else if(script.type == 'empty' || script.type == 'scriptpubkey'){ + if(script.signatures == 1){ + size += script.script.length / 2; + } else { + size += $("#est_txi_regular").val()*1; + } + + $("#fees .regular .inputno").html(($("#fees .regular .inputno").html()*1)+1); + $("#fees .txi_regular").val(($("#fees .txi_regular").val()*1)+1); + $("#fees .regular .bytes").html(($("#fees .regular .bytes").html()*1)+size); + + } else if(script.type == 'unknown'){ + size += script.script.length / 2; + $("#fees .unknown .inputno").html(($("#fees .unknown .inputno").html()*1)+1); + $("#fees .txi_unknown").val(($("#fees .txi_unknown").val()*1)+1); + $("#fees .unknown .bytes").html(($("#fees .unknown .bytes").html()*1)+size); + } + } + + for(var i = 0; i < deserialized.outs.length; i++){ + if(deserialized.outs[i].script.buffer[0]==118){ + $("#fees .txoutputs .p2pkh .outputno").html(($("#fees .txoutputs .p2pkh .outputno").html()*1)+1); + $("#fees .txoutputs .p2pkh .bytes").html(($("#fees .txoutputs .p2pkh .bytes").html()*1)+34); + $("#fees .txo_p2pkh").val(($("#fees .txo_p2pkh").val()*1)+1); + } else if (deserialized.outs[i].script.buffer[0]==169){ + $("#fees .txoutputs .p2sh .outputno").html(($("#fees .txoutputs .p2sh .outputno").html()*1)+1); + $("#fees .txoutputs .p2sh .bytes").html(($("#fees .txoutputs .p2sh .bytes").html()*1)+32); + $("#fees .txo_p2sh").val(($("#fees .txo_p2sh").val()*1)+1); + } + } + + //feeStats(); + }); + + $("#feeStatsReload").click(function(){ + feeStats(); + }); + + function mathFees(){ + + var inputsTotal = 0; + var inputsBytes = 0; + $.each($(".inputno"), function(i,o){ + inputsTotal += ($(o).html()*1); + inputsBytes += ($(".bytes",$(o).parent()).html()*1); + }); + + $("#fees .txinputs .txsize").html(inputsBytes.toFixed(0)); + $("#fees .txinputs .txtotal").html(inputsTotal.toFixed(0)); + + var outputsTotal = 0; + var outputsBytes = 0; + $.each($(".outputno"), function(i,o){ + outputsTotal += ($(o).html()*1); + outputsBytes += ($(".bytes",$(o).parent()).html()*1); + }); + + $("#fees .txoutputs .txsize").html(outputsBytes.toFixed(0)); + $("#fees .txoutputs .txtotal").html(outputsTotal.toFixed(0)); + + var totalBytes = 10 + outputsBytes + inputsBytes; + if((!isNaN($("#fees .feeSatByte:first").html())) && totalBytes > 10){ + var recommendedFee = ((totalBytes * $(".feeSatByte").html())/100000000).toFixed(8); + $(".recommendedFee").html(recommendedFee); + $(".feeTxSize").html(totalBytes); + } else { + $(".recommendedFee").html((0).toFixed(8)); + $(".feeTxSize").html(0); + } + }; + + function feeStats(){ + $("#feeStatsReload").attr('disabled',true); + $.ajax ({ + type: "GET", + url: "https://coinb.in/api/?uid=1&key=12345678901234567890123456789012&setmodule=fees&request=stats", + dataType: "xml", + error: function(data) { + }, + success: function(data) { + $("#fees .recommended .blockHeight").html(''+$(data).find("height").text()+''); + $("#fees .recommended .blockHash").html($(data).find("block").text()); + $("#fees .recommended .blockTime").html($(data).find("timestamp").text()); + $("#fees .recommended .blockDateTime").html(unescape($(data).find("datetime").text()).replace(/\+/g,' ')); + $("#fees .recommended .txId").html(''+$(data).find("txid").text()+''); + $("#fees .recommended .txSize").html($(data).find("txsize").text()); + $("#fees .recommended .txFee").html($(data).find("txfee").text()); + $("#fees .feeSatByte").html($(data).find("satbyte").text()); + + mathFees(); + }, + complete: function(data, status){ + $("#feeStatsReload").attr('disabled', false); + } + }); + } + /* capture mouse movement to add entropy */ var IE = document.all?true:false // Boolean, is browser IE? if (!IE) document.captureEvents(Event.MOUSEMOVE) @@ -1750,4 +2029,5 @@ $(document).ready(function() { return true; }; + }); diff --git a/sha1sum b/sha1sum index e31f3f5..9dfaa21 100644 --- a/sha1sum +++ b/sha1sum @@ -1,8 +1,8 @@ ----- Version 1.3 2017.12.09 --- +---- Version 1.3 2018.01.01 --- 77e4519962e2f6a9fc93342137dbb31c33b76b04 ./js/aes.js 3a09a8fc0cfe828b57fc798d668234d0490ee1a6 ./js/bootstrap-datetimepicker.min.js 253711c6d825de55a8360552573be950da180614 ./js/bootstrap.min.js -934f5330156c159378c370f14b46862d54ff5b35 ./js/coinbin.js +acd94783bcf56758633af126fc6742fe08db9f93 ./js/coinbin.js 31fbebf65d9cae8f26761cb057c4fb1b97339d08 ./js/coin.js 988565bc2cb402d63ed5c5fd7ff47c4278efc2c5 ./js/collapse.js 9ba5ede3d7f9d4c8fd623395f196adfdcf7e970f ./js/crypto-min.js @@ -22,6 +22,7 @@ ad038e1f39646b68ae666324ed4c2882a8c42474 ./js/qrcode.js ed29315e0ffb3f14382431f2724235bf67f44eb3 ./css/bootstrap.min.css fc6b4268fbd57ad95d2b41a1d4d6866f222fbdb2 ./css/bootstrap-theme.min.css 4198ed869836ea5727ad6b80bf2df0a9c1a83244 ./css/style.css +2e3217a3f3b7c2fb30562ab9a4ef9a407ae81897 ./images/btc32x.png 8ac24915d59cef71c542e7cb7d7e153f560cba1f ./images/coinbin.gif f2af060f1cadbc9065c8c465c648dc01be67cc12 ./images/loader.gif 86b6f62b7853e67d3e635f6512a5a5efc58ea3c3 ./fonts/glyphicons-halflings-regular.eot @@ -30,7 +31,6 @@ de51a8494180a6db074af2dee2383f0a363c5b08 ./fonts/glyphicons-halflings-regular.s 278e49a86e634da6f2a02f3b47dd9d2a8f26210f ./fonts/glyphicons-halflings-regular.woff 44bc1850f570972267b169ae18f1cb06b611ffa2 ./fonts/glyphicons-halflings-regular.ttf d8a324a13501cd5705dc26b945fc8088f00907ae ./README.md -4b0ef8c0520f45540f142b562e9fbf00145f219c ./index.html - +bb129ea3d4df64994fa40a143791304f5cc2fc74 ./index.html