Browse Source

simplify use of bignum in Base58 and Block

patch-2
Ryan X. Charles 11 years ago
parent
commit
823d02118c
  1. 12
      lib/Base58.js
  2. 2
      lib/Block.js

12
lib/Base58.js

@ -24,9 +24,9 @@ var base58 = {
str = new Buffer(buf.length << 1);
}
var i = str.length - 1;
while (x.gt(new bignum(0))) {
r = x.mod(new bignum(58));
x = x.div(new bignum(58));
while (x.gt(0)) {
r = x.mod(58);
x = x.div(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 = new bignum(0);
var answer = bignum(0);
for (var i = 0; i < str.length; i++) {
answer = answer.mul(new bignum(58));
answer = answer.add(new bignum(ALPHABET_INV[str[i]]));
answer = answer.mul(58);
answer = answer.add(ALPHABET_INV[str[i]]);
};
var i = 0;
while (i < str.length && str[i] == ALPHABET_ZERO) {

2
lib/Block.js

@ -114,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(new Bignum(1)));
return BlockRules.largestHash.div(target.add(1));
};
Block.prototype.checkTimestamp = function checkTimestamp() {

Loading…
Cancel
Save