diff --git a/walletjs.html b/walletjs.html index e0d556e..5a2381b 100644 --- a/walletjs.html +++ b/walletjs.html @@ -47,7 +47,7 @@ var result = myObj["data"].find(function(item){return item.id === "bitcoin"}); var btcUsd = Math.round(result["rateUsd"] * 100) / 100; result = myObj["data"].find(function(item){return item.id === "chinese-yuan-renminbi"}); - var btcCny = Math.round(1 / result["rateUsd"] * btcUsd * 100) / 100; + var btcCny = Math.round(1 / result["rateUsd"] * btcUsd * 100) / 100; //保留两位小数 document.getElementById('priceUsd').innerHTML = "Realtime Price(实时价格): " + btcUsd + "$, " + btcCny + "¥"; } }; @@ -719,6 +719,7 @@ hash = Crypto.util.hexToBytes(hash).reverse(); hash = Crypto.util.bytesToHex(hash); txJSON.hash = hash; + txJSON.hex_raw_length = raw.length; //计算单位字节花费矿工费sats/vB时用到 return txJSON; } @@ -1620,6 +1621,28 @@ } } } + + //计算每字节花费的矿工费 + function calFeepervB(txRaw, txSignedRaw){ + var txRawObj = txParseRaw(txRaw); + var arr = txRawObj.txJSON.tx_in_value.split(" "); + var txInValue = 0; + for(var i = 0; i < arr.length; i++){ + txInValue = floatAdd(txInValue, arr[i]); + } + txInValue = txInValue * 100000000; + + var txSignedRawObj = txParseRaw(txSignedRaw); + var tx_out_count = txSignedRawObj.txJSON.tx_out_count; + var txOutValue = 0; + for(var i = 0; i < tx_out_count; i++){ + txOutValue = floatAdd(txOutValue, txSignedRawObj.txJSON.tx_out[i].value); + } + txOutValue = txOutValue * 100000000; + + var vBytes = Math.round((txInValue - txOutValue) / txSignedRawObj.txJSON.hex_raw_length * 100) / 100; //保留两位小数 + return vBytes; + }
@@ -2077,7 +2100,7 @@ - +