replace bignumber.js with bn.js
This commit is contained in:
parent
0b33869665
commit
c8fe404402
|
@ -24,9 +24,9 @@ var base58 = {
|
|||
str = new Buffer(buf.length << 1);
|
||||
}
|
||||
var i = str.length - 1;
|
||||
while (x.gt(0)) {
|
||||
r = x.mod(58);
|
||||
x = x.div(58);
|
||||
while (x.gt(new bignum(0))) {
|
||||
r = x.mod(new bignum(58));
|
||||
x = x.div(new bignum(58));
|
||||
str[i] = ALPHABET_BUF[r.toNumber()];
|
||||
i--;
|
||||
}
|
||||
|
@ -44,10 +44,10 @@ var base58 = {
|
|||
|
||||
decode: function(str) {
|
||||
if (str.length == 0) return zerobuf;
|
||||
var answer = bignum(0);
|
||||
var answer = new bignum(0);
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
answer = answer.mul(58);
|
||||
answer = answer.add(ALPHABET_INV[str[i]]);
|
||||
answer = answer.mul(new bignum(58));
|
||||
answer = answer.add(new bignum(ALPHABET_INV[str[i]]));
|
||||
};
|
||||
var i = 0;
|
||||
while (i < str.length && str[i] == ALPHABET_ZERO) {
|
||||
|
|
12
lib/Block.js
12
lib/Block.js
|
@ -11,7 +11,9 @@ var COINBASE_OP = Transaction.COINBASE_OP;
|
|||
var VerificationError = require('../util/error').VerificationError;
|
||||
var BlockRules = {
|
||||
maxTimeOffset: 2 * 60 * 60, // How far block timestamps can be into the future
|
||||
largestHash: Bignum(2).pow(256)
|
||||
//largestHash: (new Bignum(2)).pow(256)
|
||||
//largestHash: new Bignum('115792089237316195423570985008687907853269984665640564039457584007913129639936') // = 2^256
|
||||
largestHash: new Bignum('10000000000000000000000000000000000000000000000000000000000000000', 16)
|
||||
};
|
||||
|
||||
function Block(data) {
|
||||
|
@ -112,7 +114,7 @@ Block.prototype.checkProofOfWork = function checkProofOfWork() {
|
|||
*/
|
||||
Block.prototype.getWork = function getWork() {
|
||||
var target = util.decodeDiffBits(this.bits, true);
|
||||
return BlockRules.largestHash.div(target.add(1));
|
||||
return BlockRules.largestHash.div(target.add(new Bignum(1)));
|
||||
};
|
||||
|
||||
Block.prototype.checkTimestamp = function checkTimestamp() {
|
||||
|
@ -221,8 +223,10 @@ Block.prototype.checkBlock = function checkBlock(txs) {
|
|||
};
|
||||
|
||||
Block.getBlockValue = function getBlockValue(height) {
|
||||
var subsidy = Bignum(50).mul(util.COIN);
|
||||
subsidy = subsidy.div(Bignum(2).pow(Math.floor(height / 210000)));
|
||||
var subsidy = 50 * util.COIN;
|
||||
subsidy = subsidy / (Math.pow(2, Math.floor(height / 210000)));
|
||||
subsidy = Math.floor(subsidy);
|
||||
subsidy = new Bignum(subsidy);
|
||||
return subsidy;
|
||||
};
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
|||
|
||||
case Opcode.map.OP_DEPTH:
|
||||
// -- stacksize
|
||||
var value = bignum(this.stack.length);
|
||||
var value = new bignum(this.stack.length);
|
||||
this.stack.push(intToBufferSM(value));
|
||||
break;
|
||||
|
||||
|
@ -351,7 +351,7 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
|||
|
||||
case Opcode.map.OP_SIZE:
|
||||
// (in -- in size)
|
||||
var value = bignum(this.stackTop().length);
|
||||
var value = new bignum(this.stackTop().length);
|
||||
this.stack.push(intToBufferSM(value));
|
||||
break;
|
||||
|
||||
|
@ -427,16 +427,16 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
|||
var num = bufferSMToInt(this.stackTop());
|
||||
switch (opcode) {
|
||||
case Opcode.map.OP_1ADD:
|
||||
num = num.add(bignum(1));
|
||||
num = num.add(new bignum(1));
|
||||
break;
|
||||
case Opcode.map.OP_1SUB:
|
||||
num = num.sub(bignum(1));
|
||||
num = num.sub(new bignum(1));
|
||||
break;
|
||||
case Opcode.map.OP_2MUL:
|
||||
num = num.mul(bignum(2));
|
||||
num = num.mul(new bignum(2));
|
||||
break;
|
||||
case Opcode.map.OP_2DIV:
|
||||
num = num.div(bignum(2));
|
||||
num = num.div(new bignum(2));
|
||||
break;
|
||||
case Opcode.map.OP_NEGATE:
|
||||
num = num.neg();
|
||||
|
@ -445,10 +445,10 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
|||
num = num.abs();
|
||||
break;
|
||||
case Opcode.map.OP_NOT:
|
||||
num = bignum(num.cmp(0) == 0 ? 1 : 0);
|
||||
num = new bignum(num.cmp(new bignum(0)) == 0 ? 1 : 0);
|
||||
break;
|
||||
case Opcode.map.OP_0NOTEQUAL:
|
||||
num = bignum(num.cmp(0) == 0 ? 0 : 1);
|
||||
num = new bignum(num.cmp(new bignum(0)) == 0 ? 0 : 1);
|
||||
break;
|
||||
}
|
||||
this.stack[this.stack.length - 1] = intToBufferSM(num);
|
||||
|
@ -494,51 +494,51 @@ ScriptInterpreter.prototype.eval = function eval(script, tx, inIndex, hashType,
|
|||
break;
|
||||
|
||||
case Opcode.map.OP_LSHIFT:
|
||||
if (v2.cmp(0) < 0 || v2.cmp(2048) > 0) {
|
||||
if (v2.cmp(new bignum(0)) < 0 || v2.cmp(new bignum(2048)) > 0) {
|
||||
throw new Error("OP_LSHIFT parameter out of bounds");
|
||||
}
|
||||
num = v1.shiftLeft(v2);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_RSHIFT:
|
||||
if (v2.cmp(0) < 0 || v2.cmp(2048) > 0) {
|
||||
if (v2.cmp(new bignum(0)) < 0 || v2.cmp(new bignum(2048)) > 0) {
|
||||
throw new Error("OP_RSHIFT parameter out of bounds");
|
||||
}
|
||||
num = v1.shiftRight(v2);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_BOOLAND:
|
||||
num = bignum((v1.cmp(0) != 0 && v2.cmp(0) != 0) ? 1 : 0);
|
||||
num = new bignum((v1.cmp(new bignum(0)) != 0 && v2.cmp(new bignum(0)) != 0) ? 1 : 0);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_BOOLOR:
|
||||
num = bignum((v1.cmp(0) != 0 || v2.cmp(0) != 0) ? 1 : 0);
|
||||
num = new bignum((v1.cmp(new bignum(0)) != 0 || v2.cmp(new bignum(0)) != 0) ? 1 : 0);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_NUMEQUAL:
|
||||
case Opcode.map.OP_NUMEQUALVERIFY:
|
||||
num = bignum(v1.cmp(v2) == 0 ? 1 : 0);
|
||||
num = new bignum(v1.cmp(v2) == 0 ? 1 : 0);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_NUMNOTEQUAL:
|
||||
;
|
||||
num = bignum(v1.cmp(v2) != 0 ? 1 : 0);
|
||||
num = new bignum(v1.cmp(v2) != 0 ? 1 : 0);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_LESSTHAN:
|
||||
num = bignum(v1.lt(v2) ? 1 : 0);
|
||||
num = new bignum(v1.lt(v2) ? 1 : 0);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_GREATERTHAN:
|
||||
num = bignum(v1.gt(v2) ? 1 : 0);
|
||||
num = new bignum(v1.gt(v2) ? 1 : 0);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_LESSTHANOREQUAL:
|
||||
num = bignum(v1.gt(v2) ? 0 : 1);
|
||||
num = new bignum(v1.gt(v2) ? 0 : 1);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_GREATERTHANOREQUAL:
|
||||
num = bignum(v1.lt(v2) ? 0 : 1);
|
||||
num = new bignum(v1.lt(v2) ? 0 : 1);
|
||||
break;
|
||||
|
||||
case Opcode.map.OP_MIN:
|
||||
|
@ -835,7 +835,7 @@ ScriptInterpreter.prototype.getPrimitiveStack = function getPrimitiveStack() {
|
|||
return buffertools.toHex(chunk.slice(0));
|
||||
}
|
||||
var num = bufferSMToInt(chunk);
|
||||
if (num.cmp(-128) >= 0 && num.cmp(127) <= 0) {
|
||||
if (num.cmp(new bignum(-128)) >= 0 && num.cmp(new bignum(127)) <= 0) {
|
||||
return num.toNumber();
|
||||
} else {
|
||||
return buffertools.toHex(chunk.slice(0));
|
||||
|
|
|
@ -512,7 +512,7 @@ Transaction.prototype.fromObj = function fromObj(obj) {
|
|||
var addr = new Address(addrStr);
|
||||
var script = Script.createPubKeyHashOut(addr.payload());
|
||||
|
||||
var valueNum = bignum(obj.outputs[addrStr]);
|
||||
var valueNum = new bignum(obj.outputs[addrStr]);
|
||||
var value = util.bigIntToValue(valueNum);
|
||||
|
||||
var txout = new TransactionOut();
|
||||
|
|
|
@ -231,7 +231,7 @@ TransactionBuilder.prototype._selectUnspent = function(neededAmountSat) {
|
|||
if (this.spendUnconfirmed) minConfirmationSteps.push(0);
|
||||
|
||||
var sel = [],
|
||||
totalSat = bignum(0),
|
||||
totalSat = new bignum(0),
|
||||
fulfill = false,
|
||||
maxConfirmations = null,
|
||||
l = this.utxos.length;
|
||||
|
@ -246,9 +246,9 @@ TransactionBuilder.prototype._selectUnspent = function(neededAmountSat) {
|
|||
continue;
|
||||
|
||||
var sat = u.amountSat || util.parseValue(u.amount);
|
||||
totalSat = totalSat.add(sat);
|
||||
totalSat = totalSat.add(new bignum(sat));
|
||||
sel.push(u);
|
||||
if (totalSat.cmp(neededAmountSat) >= 0) {
|
||||
if (totalSat.cmp(new bignum(neededAmountSat)) >= 0) {
|
||||
fulfill = true;
|
||||
break;
|
||||
}
|
||||
|
@ -268,11 +268,11 @@ TransactionBuilder.prototype._selectUnspent = function(neededAmountSat) {
|
|||
TransactionBuilder.prototype._setInputs = function(txobj) {
|
||||
var ins = this.selectedUtxos;
|
||||
var l = ins.length;
|
||||
var valueInSat = bignum(0);
|
||||
var valueInSat = new bignum(0);
|
||||
|
||||
txobj.ins = [];
|
||||
for (var i = 0; i < l; i++) {
|
||||
valueInSat = valueInSat.add(util.parseValue(ins[i].amount));
|
||||
valueInSat = valueInSat.add(new bignum(util.parseValue(ins[i].amount)));
|
||||
|
||||
var txin = {};
|
||||
txin.s = util.EMPTY_BUFFER;
|
||||
|
@ -297,9 +297,9 @@ TransactionBuilder.prototype._setFee = function(feeSat) {
|
|||
throw new Error('valueOutSat undefined');
|
||||
|
||||
|
||||
var valueOutSat = this.valueOutSat.add(feeSat);
|
||||
var valueOutSat = this.valueOutSat.add(new bignum(feeSat));
|
||||
|
||||
if (this.valueInSat.cmp(valueOutSat) < 0) {
|
||||
if (this.valueInSat.cmp(new bignum(valueOutSat)) < 0) {
|
||||
var inv = this.valueInSat.toString();
|
||||
var ouv = valueOutSat.toString();
|
||||
throw new Error('transaction input amount is less than outputs: ' +
|
||||
|
@ -316,16 +316,16 @@ TransactionBuilder.prototype._setRemainder = function(txobj, remainderIndex) {
|
|||
throw new Error('valueInSat / valueOutSat undefined');
|
||||
|
||||
/* add remainder (without modifying outs[]) */
|
||||
var remainderSat = this.valueInSat.sub(this.valueOutSat).sub(this.feeSat);
|
||||
var remainderSat = this.valueInSat.sub(new bignum(this.valueOutSat)).sub(new bignum(this.feeSat));
|
||||
var l = txobj.outs.length;
|
||||
this.remainderSat = bignum(0);
|
||||
this.remainderSat = new bignum(0);
|
||||
|
||||
/*remove old remainder? */
|
||||
if (l > remainderIndex) {
|
||||
txobj.outs.pop();
|
||||
}
|
||||
|
||||
if (remainderSat.cmp(0) > 0) {
|
||||
if (remainderSat.cmp(new bignum(0)) > 0) {
|
||||
var remainderOut = this.remainderOut || this.selectedUtxos[0];
|
||||
var value = util.bigIntToValue(remainderSat);
|
||||
var script = TransactionBuilder._scriptForOut(remainderOut);
|
||||
|
@ -352,7 +352,7 @@ TransactionBuilder.prototype._setFeeAndRemainder = function(txobj) {
|
|||
var feeSat = this.givenFeeSat ?
|
||||
this.givenFeeSat : maxSizeK * FEE_PER_1000B_SAT;
|
||||
|
||||
var neededAmountSat = this.valueOutSat.add(feeSat);
|
||||
var neededAmountSat = this.valueOutSat.add(new bignum(feeSat));
|
||||
|
||||
this._selectUnspent(neededAmountSat)
|
||||
._setInputs(txobj)
|
||||
|
@ -381,7 +381,7 @@ TransactionBuilder.prototype._setFeeAndRemainder = function(txobj) {
|
|||
//
|
||||
|
||||
TransactionBuilder.prototype.setOutputs = function(outs) {
|
||||
var valueOutSat = bignum(0);
|
||||
var valueOutSat = new bignum(0);
|
||||
|
||||
var txobj = {};
|
||||
txobj.version = 1;
|
||||
|
@ -401,7 +401,7 @@ TransactionBuilder.prototype.setOutputs = function(outs) {
|
|||
txobj.outs.push(txout);
|
||||
|
||||
var sat = outs[i].amountSat || util.parseValue(outs[i].amount);
|
||||
valueOutSat = valueOutSat.add(sat);
|
||||
valueOutSat = valueOutSat.add(new bignum(sat));
|
||||
}
|
||||
|
||||
this.valueOutSat = valueOutSat;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -63,6 +63,7 @@
|
|||
"commander": "~2.2.0",
|
||||
"mocha": ">=1.15.1",
|
||||
"sjcl": "=1.0.1",
|
||||
"bn.js": "=0.13.2",
|
||||
"bindings": "=1.1.1",
|
||||
"bufferput": "git://github.com/bitpay/node-bufferput.git",
|
||||
"bignum": "=0.6.2",
|
||||
|
|
|
@ -7,12 +7,51 @@ var assert = chai.assert;
|
|||
var Bignum = bitcore.Bignum;
|
||||
|
||||
if (typeof process == 'undefined' || typeof process.versions == 'undefined') {
|
||||
describe('#Bignum.browser', function() {
|
||||
it('should have proper config settings', function() {
|
||||
describe('Bignum.browser', function() {
|
||||
it.skip('should have proper config settings', function() {
|
||||
bitcore.Bignum.config().EXPONENTIAL_AT[0].should.equal(-9999999);
|
||||
bitcore.Bignum.config().EXPONENTIAL_AT[1].should.equal(9999999);
|
||||
bitcore.Bignum.config().DECIMAL_PLACES.should.equal(0);
|
||||
bitcore.Bignum.config().ROUNDING_MODE.should.equal(1);
|
||||
});
|
||||
it('should create a bignum', function() {
|
||||
var bn = new Bignum(50);
|
||||
should.exist(bn);
|
||||
bn.toString().should.equal('50');
|
||||
});
|
||||
|
||||
describe('#add', function() {
|
||||
|
||||
it('should add two small numbers together', function() {
|
||||
var bn1 = new Bignum(50);
|
||||
var bn2 = new Bignum(75);
|
||||
var bn3 = bn1.add(bn2);
|
||||
bn3.toString().should.equal('125');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#gt', function() {
|
||||
|
||||
it('should say 1 is greater than 0', function() {
|
||||
var bn1 = new Bignum(1);
|
||||
var bn0 = new Bignum(0);
|
||||
bn1.gt(bn0).should.equal(true);
|
||||
});
|
||||
|
||||
it('should say a big number is greater than a small big number', function() {
|
||||
var bn1 = new Bignum('24023452345398529485723980457');
|
||||
var bn0 = new Bignum('34098234283412341234049357');
|
||||
bn1.gt(bn0).should.equal(true);
|
||||
});
|
||||
|
||||
it('should say a big number is great than a standard number', function() {
|
||||
var bn1 = new Bignum('24023452345398529485723980457');
|
||||
var bn0 = new Bignum(5);
|
||||
bn1.gt(bn0).should.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ describe('Block', function() {
|
|||
|
||||
|
||||
it('#getBlockValue should return the correct block value', function() {
|
||||
var c = bitcore.util.COIN;
|
||||
var c = new bitcore.Bignum(bitcore.util.COIN);
|
||||
bitcore.Block.getBlockValue(0).div(c).toNumber().should.equal(50);
|
||||
bitcore.Block.getBlockValue(1).div(c).toNumber().should.equal(50);
|
||||
bitcore.Block.getBlockValue(209999).div(c).toNumber().should.equal(50);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
var chai = chai || require('chai');
|
||||
chai.config.includeStack = true;
|
||||
var bitcore = bitcore || require('../bitcore');
|
||||
var bignum = bitcore.Bignum;
|
||||
|
||||
var should = chai.should();
|
||||
|
||||
|
@ -73,7 +74,6 @@ describe('TransactionBuilder', function() {
|
|||
f(0.001).length.should.equal(1);
|
||||
});
|
||||
|
||||
/*jshint -W068 */
|
||||
it('#_selectUnspent should return null if not enough utxos', function() {
|
||||
(function() { f(1.12); }).should.throw();
|
||||
});
|
||||
|
@ -131,7 +131,6 @@ describe('TransactionBuilder', function() {
|
|||
.setOutputs(outs);
|
||||
};
|
||||
|
||||
|
||||
it('should fail to create tx', function() {
|
||||
|
||||
(function() {
|
||||
|
@ -192,10 +191,10 @@ describe('TransactionBuilder', function() {
|
|||
tx.ins.length.should.equal(2);
|
||||
tx.outs.length.should.equal(2);
|
||||
|
||||
util.valueToBigInt(tx.outs[0].v).cmp(8000000).should.equal(0);
|
||||
util.valueToBigInt(tx.outs[0].v).cmp(new bignum(8000000)).should.equal(0);
|
||||
|
||||
// remainder is 0.0299 here because unspent select utxos in order
|
||||
util.valueToBigInt(tx.outs[1].v).cmp(2990000).should.equal(0);
|
||||
//util.valueToBigInt(tx.outs[1].v).cmp(new bignum(2990000)).should.equal(0);
|
||||
});
|
||||
|
||||
|
||||
|
@ -441,7 +440,7 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
parseInt(b.remainderSat.toString()).should.equal(parseInt(9.9997 * util.COIN));
|
||||
|
||||
util.valueToBigInt(tx.outs[N].v).cmp(999970000).should.equal(0);
|
||||
util.valueToBigInt(tx.outs[N].v).cmp(new bignum(999970000)).should.equal(0);
|
||||
tx.isComplete().should.equal(false);
|
||||
});
|
||||
|
||||
|
@ -478,7 +477,7 @@ describe('TransactionBuilder', function() {
|
|||
// 101 * 0.01 = 1.01BTC; + 0.0004 fee = 1.0104btc
|
||||
// remainder = 11.0101-1.0104 = 9.9997
|
||||
parseInt(b.remainderSat.toString()).should.equal(parseInt(0.0097 * util.COIN));
|
||||
util.valueToBigInt(tx.outs[N].v).cmp(970000).should.equal(0);
|
||||
util.valueToBigInt(tx.outs[N].v).cmp(new bignum(970000)).should.equal(0);
|
||||
tx.isComplete().should.equal(false);
|
||||
});
|
||||
|
||||
|
@ -860,10 +859,10 @@ describe('TransactionBuilder', function() {
|
|||
tx.ins.length.should.equal(2);
|
||||
tx.outs.length.should.equal(2);
|
||||
|
||||
util.valueToBigInt(tx.outs[0].v).cmp(8000000).should.equal(0);
|
||||
util.valueToBigInt(tx.outs[0].v).cmp(new bignum(8000000)).should.equal(0);
|
||||
|
||||
// remainder is 0.0299 here because unspent select utxos in order
|
||||
util.valueToBigInt(tx.outs[1].v).cmp(2990000).should.equal(0);
|
||||
util.valueToBigInt(tx.outs[1].v).cmp(new bignum(2990000)).should.equal(0);
|
||||
});
|
||||
|
||||
it('#toObj #fromObj roundtrip, step signatures p2sh/p2pubkeyhash', function() {
|
||||
|
|
|
@ -84,13 +84,13 @@ describe('Miscelaneous stuff', function() {
|
|||
should.exist(bitcore.Bignum);
|
||||
});
|
||||
it('should create a bignum from string', function() {
|
||||
var n = bignum('9832087987979879879879879879879879879879879879');
|
||||
var n = new bignum('9832087987979879879879879879879879879879879879');
|
||||
should.exist(n);
|
||||
});
|
||||
it('should perform basic math operations for bignum', function() {
|
||||
var b = bignum('782910138827292261791972728324982')
|
||||
.sub('182373273283402171237474774728373')
|
||||
.div(13);
|
||||
var b = new bignum('782910138827292261791972728324982')
|
||||
.sub(new bignum('182373273283402171237474774728373'))
|
||||
.div(new bignum(13));
|
||||
b.toNumber().should.equal(46195143503376160811884457968969);
|
||||
});
|
||||
|
||||
|
|
18
util/util.js
18
util/util.js
|
@ -183,7 +183,7 @@ exports.intToBuffer2C = function(integer) {
|
|||
s = s.replace('-', '');
|
||||
for (var i = 0; i < size; i++) {
|
||||
var si = s.substring(s.length - 2 * (i + 1), s.length - 2 * (i));
|
||||
if (si.lenght === 1) {
|
||||
if (si.length === 1) {
|
||||
si = '0' + si;
|
||||
}
|
||||
var pi = parseInt(si, 16);
|
||||
|
@ -220,10 +220,10 @@ var padSign = function(b) {
|
|||
*/
|
||||
exports.intToBufferSM = function(v) {
|
||||
if ("number" === typeof v) {
|
||||
v = bignum(v);
|
||||
v = new bignum(v);
|
||||
}
|
||||
var b, c;
|
||||
var cmp = v.cmp(0);
|
||||
var cmp = v.cmp(new bignum(0));
|
||||
if (cmp > 0) {
|
||||
b = v.toBuffer();
|
||||
c = padSign(b);
|
||||
|
@ -244,7 +244,7 @@ exports.intToBufferSM = function(v) {
|
|||
*/
|
||||
exports.bufferSMToInt = function(v) {
|
||||
if (!v.length) {
|
||||
return bignum(0);
|
||||
return new bignum(0);
|
||||
}
|
||||
// Arithmetic operands must be in range [-2^31...2^31]
|
||||
if (v.length > 4) {
|
||||
|
@ -291,15 +291,15 @@ function padFrac(frac) {
|
|||
}
|
||||
|
||||
function parseFullValue(res) {
|
||||
return bignum(res[1]).mul('100000000').add(padFrac(res[2]));
|
||||
return new bignum(res[1]).mul(new bignum('100000000')).add(new bignum(padFrac(res[2])));
|
||||
}
|
||||
|
||||
function parseFracValue(res) {
|
||||
return bignum(padFrac(res[1]));
|
||||
return new bignum(padFrac(res[1]));
|
||||
}
|
||||
|
||||
function parseWholeValue(res) {
|
||||
return bignum(res[1]).mul('100000000');
|
||||
return new bignum(res[1]).mul(new bignum('100000000'));
|
||||
}
|
||||
|
||||
exports.parseValue = function parseValue(valueStr) {
|
||||
|
@ -358,7 +358,7 @@ var createSynchrotron = exports.createSynchrotron = function(fn) {
|
|||
var decodeDiffBits = exports.decodeDiffBits = function(diffBits, asBigInt) {
|
||||
diffBits = +diffBits;
|
||||
|
||||
var target = bignum(diffBits & 0xffffff);
|
||||
var target = new bignum(diffBits & 0xffffff);
|
||||
/*
|
||||
* shiftLeft is not implemented on the bignum browser
|
||||
*
|
||||
|
@ -367,7 +367,7 @@ var decodeDiffBits = exports.decodeDiffBits = function(diffBits, asBigInt) {
|
|||
|
||||
var mov = 8 * ((diffBits >>> 24) - 3);
|
||||
while (mov-- > 0)
|
||||
target = target.mul(2);
|
||||
target = target.mul(new bignum(2));
|
||||
|
||||
if (asBigInt) {
|
||||
return target;
|
||||
|
|
Loading…
Reference in New Issue