Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 28dee51

Browse files
author
Kristjan Kosic
authored
Merge pull request #114 from nge6427/mainnet
bignum fixes and other minor corrections
2 parents c2a398c + 6acff2b commit 28dee51

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

helpers/bignum.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var MAX = 1E9, // 0 to 1e+9
3030
MAX_POWER = 1E6, // 1 to 1e+6
3131

3232
// The maximum number of decimal places for operations involving division.
33-
DECIMAL_PLACES = 20, // 0 to MAX
33+
DECIMAL_PLACES = 0, // 0 to MAX
3434

3535
/*
3636
* The rounding mode used when rounding to the above decimal places, and when
@@ -51,11 +51,11 @@ var MAX = 1E9, // 0 to 1e+9
5151

5252
// The exponent value at and beneath which toString returns exponential notation.
5353
// Number type: -7
54-
TO_EXP_NEG = -7, // 0 to -MAX
54+
TO_EXP_NEG = -MAX, // 0 to -MAX
5555

5656
// The exponent value at and above which toString returns exponential notation.
5757
// Number type: 21
58-
TO_EXP_POS = 21, // 0 to MAX
58+
TO_EXP_POS = MAX, // 0 to MAX
5959

6060
// RANGE : [MIN_EXP, MAX_EXP]
6161

helpers/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ module.exports = {
4141
distance: 3000000, // Distance between each milestone
4242
},
4343
signatureLength: 196,
44-
totalAmount: 12500000000000000,
44+
totalAmount: 12500000000000004, // TODO: Fix properly because this value exceeds JS Number precision
4545
unconfirmedTransactionTimeOut: 10800 // 1080 blocks
4646
};

logic/account.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function Account (scope, cb) {
131131
required: true,
132132
type: 'integer',
133133
minimum: 0,
134-
maximum: constants.totalAMount
134+
maximum: constants.totalAmount
135135
},
136136
conv: Number,
137137
expression: '("u_balance")::bigint'

logic/transaction.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ Transaction.prototype.apply = function (trs, block, sender, cb) {
706706
return cb(senderBalance.error);
707707
}
708708

709-
amount = amount.toNumber();
709+
amount = parseInt(amount.toFixed(), 10);
710710

711711
this.scope.account.merge(sender.address, {
712712
balance: -amount,
@@ -739,7 +739,7 @@ Transaction.prototype.apply = function (trs, block, sender, cb) {
739739
//
740740
Transaction.prototype.undo = function (trs, block, sender, cb) {
741741
var amount = bignum(trs.amount.toString());
742-
amount = amount.plus(trs.fee.toString()).toNumber();
742+
amount = parseInt(amount.plus(trs.fee.toString()).toFixed(), 10);
743743

744744
this.scope.account.merge(sender.address, {
745745
balance: amount,
@@ -783,7 +783,7 @@ Transaction.prototype.applyUnconfirmed = function (trs, sender, requester, cb) {
783783
return cb(senderBalance.error);
784784
}
785785

786-
amount = amount.toNumber();
786+
amount = parseInt(amount.toFixed(), 10);
787787

788788
this.scope.account.merge(sender.address, {u_balance: -amount}, function (err, sender) {
789789
if (err) {
@@ -808,7 +808,7 @@ Transaction.prototype.applyUnconfirmed = function (trs, sender, requester, cb) {
808808
//
809809
Transaction.prototype.undoUnconfirmed = function (trs, sender, cb) {
810810
var amount = bignum(trs.amount.toString());
811-
amount = amount.plus(trs.fee.toString()).toNumber();
811+
amount = parseInt(amount.plus(trs.fee.toString()).toFixed(), 10);
812812

813813
this.scope.account.merge(sender.address, {u_balance: amount}, function (err, sender) {
814814
if (err) {

0 commit comments

Comments
 (0)