diff --git a/src/js/ripple/amount.js b/src/js/ripple/amount.js index 7f02a164..b887d131 100644 --- a/src/js/ripple/amount.js +++ b/src/js/ripple/amount.js @@ -1,7 +1,5 @@ 'use strict'; - /*eslint-disable new-cap*/ - // Represent Ripple amounts and currencies. // - Numbers in hex are big-endian. @@ -137,7 +135,7 @@ Amount.prototype.add = function(addend) { var addendAmount = Amount.from_json(addend); if (!this.is_comparable(addendAmount)) { - return Amount.NaN(); + return new Amount(NaN); } return this._copy(this._value.plus(addendAmount._value)); @@ -207,11 +205,11 @@ Amount.prototype.ratio_human = function(denominator, opts) { // If either operand is NaN, the result is NaN. if (!numerator.is_valid() || !denominator.is_valid()) { - return Amount.NaN(); + return new Amount(NaN); } if (denominator.is_zero()) { - return Amount.NaN(); + return new Amount(NaN); } // Apply interest/demurrage @@ -267,7 +265,7 @@ Amount.prototype.product_human = function(factor, opts) { // If either operand is NaN, the result is NaN. if (!this.is_valid() || !factor.is_valid()) { - return Amount.NaN(); + return new Amount(NaN); } // Apply interest/demurrage @@ -388,7 +386,7 @@ Amount.prototype._copy = function(value) { Amount.prototype.compareTo = function(to) { var toAmount = Amount.from_json(to); if (!this.is_comparable(toAmount)) { - return Amount.NaN(); + return new Amount(NaN); } return this._value.comparedTo(toAmount._value); }; @@ -507,7 +505,7 @@ Amount.prototype.parse_human = function(j, opts) { value = words[0].slice(0, -3); currency = words[0].slice(-3); if (!(isNumber(value) && currency.match(currency_RE))) { - return Amount.NaN(); + return new Amount(NaN); } } } else if (words.length === 2) { @@ -521,10 +519,10 @@ Amount.prototype.parse_human = function(j, opts) { value = words[0]; currency = words[1]; } else { - return Amount.NaN(); + return new Amount(NaN); } } else { - return Amount.NaN(); + return new Amount(NaN); } currency = currency.toUpperCase(); diff --git a/src/js/ripple/serializedtypes.js b/src/js/ripple/serializedtypes.js index 74c53cc0..7f4ecdff 100644 --- a/src/js/ripple/serializedtypes.js +++ b/src/js/ripple/serializedtypes.js @@ -242,6 +242,37 @@ function serialize(so, field_name, value) { exports.serialize = exports.serialize_whatever = serialize; +// Take the serialized object, figure out what type/field it is, and return the +// parsing of that. + +function parse(so) { + var tag_byte = so.read(1)[0]; + var type_bits = tag_byte >> 4; + + if (type_bits === 0) { + type_bits = so.read(1)[0]; + } + + var field_bits = tag_byte & 0x0f; + var field_name = (field_bits === 0) + ? field_name = binformat.fields[type_bits][so.read(1)[0]] + : field_name = binformat.fields[type_bits][field_bits]; + + assert(field_name, 'Unknown field - header byte is 0x' + + tag_byte.toString(16)); + + // Get the parser class (ST...) for a field based on the type bits. + var type = (field_name === 'Memo') + ? exports.STMemo + : exports[binformat.types[type_bits]]; + + assert(type, 'Unknown type - header byte is 0x' + tag_byte.toString(16)); + + return [field_name, type.parse(so)]; // key, value +} + +exports.parse = exports.parse_whatever = parse; + var STInt16 = exports.Int16 = new SerializedType({ serialize: function (so, val) { so.append(convertIntegerToByteArray(val, 2)); @@ -765,37 +796,6 @@ exports.STMemo = new SerializedType({ }); -// Take the serialized object, figure out what type/field it is, and return the -// parsing of that. - -function parse(so) { - var tag_byte = so.read(1)[0]; - var type_bits = tag_byte >> 4; - - if (type_bits === 0) { - type_bits = so.read(1)[0]; - } - - var field_bits = tag_byte & 0x0f; - var field_name = (field_bits === 0) - ? field_name = binformat.fields[type_bits][so.read(1)[0]] - : field_name = binformat.fields[type_bits][field_bits]; - - assert(field_name, 'Unknown field - header byte is 0x' - + tag_byte.toString(16)); - - // Get the parser class (ST...) for a field based on the type bits. - var type = (field_name === 'Memo') - ? exports.STMemo - : exports[binformat.types[type_bits]]; - - assert(type, 'Unknown type - header byte is 0x' + tag_byte.toString(16)); - - return [field_name, type.parse(so)]; // key, value -} - -exports.parse = exports.parse_whatever = parse; - var STObject = exports.Object = new SerializedType({ serialize: function (so, val, no_marker) { var keys = []; diff --git a/test/serializedobject-test.js b/test/serializedobject-test.js index cc8a17ba..13e8a150 100644 --- a/test/serializedobject-test.js +++ b/test/serializedobject-test.js @@ -5,6 +5,7 @@ /* eslint-disable no-spaced-func*/ /* eslint-disable space-before-blocks*/ /* eslint-disable space-unary-ops*/ +/* eslint-disable no-multi-spaces*/ /* eslint-disable no-void*/ /* eslint-disable semi*/ /* eslint-disable no-unused-vars*/