Browse Source

Fixed bug in numToBytes and util -> conv

hk-custom-address
vub 11 years ago
parent
commit
a753f069a5
  1. 2
      bitcoinjs-min.js
  2. 2
      src/transaction.js
  3. 11
      src/util.js

2
bitcoinjs-min.js

File diff suppressed because one or more lines are too long

2
src/transaction.js

@ -398,7 +398,7 @@ Transaction.prototype.calcImpact = function (wallet) {
if (wallet.hasHash(hash)) {
var fromTx = wallet.txIndex[txin.outpoint.hash];
if (fromTx) {
valueIn = valueIn.add(util.valueToBigInt(fromTx.outs[txin.outpoint.index].value));
valueIn = valueIn.add(conv.valueToBigInt(fromTx.outs[txin.outpoint.index].value));
}
}
}

11
src/util.js

@ -26,9 +26,18 @@ module.exports = {
* Create a byte array representing a number with the given length
*/
numToBytes: function(num,bytes) {
if (bytes == 0 || (bytes === undefined && num === 0)) return [];
if (bytes === undefined) bytes = 8;
if (bytes == 0) return [];
else return [num % 256].concat(module.exports.numToBytes(Math.floor(num / 256),bytes-1));
},
/**
* Create a byte array representing a number with the given length
*/
bytesToNum: function(bytes) {
if (bytes.length == 0) return 0;
else return bytes[0] + 256 * bytesToNum(bytes.slice(1));
},
/**
* Turn an integer into a "var_int".
*

Loading…
Cancel
Save