From 6fdba19373e6f5f353f8c18a48a78da161faa802 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Thu, 18 Aug 2011 05:01:00 +0100 Subject: [PATCH] New utility function for parsing value strings. --- src/util.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util.js b/src/util.js index f58333a..d7c5409 100644 --- a/src/util.js +++ b/src/util.js @@ -80,6 +80,17 @@ Bitcoin.Util = { while (decimalPart.length < 2) decimalPart += "0"; return integerPart+"."+decimalPart; }, + parseValue: function (valueString) { + var valueComp = valueString.split('.'); + var integralPart = valueComp[0]; + var fractionalPart = valueComp[1] || "0"; + while (fractionalPart.length < 8) fractionalPart += "0"; + fractionalPart = fractionalPart.replace(/^0+/g, ''); + var value = BigInteger.valueOf(parseInt(integralPart)); + value = value.multiply(BigInteger.valueOf(100000000)); + value = value.add(BigInteger.valueOf(parseInt(fractionalPart))); + return value; + }, sha256ripe160: function (data) { return Crypto.RIPEMD160(Crypto.SHA256(data, {asBytes: true}), {asBytes: true}); }