diff --git a/src/js/ripple/currency.js b/src/js/ripple/currency.js index 54ca01ac..a3f6b4ff 100644 --- a/src/js/ripple/currency.js +++ b/src/js/ripple/currency.js @@ -92,7 +92,7 @@ Currency.prototype.parse_bytes = function (byte_array) { } if (isZeroExceptInStandardPositions) { var currencyCode = String.fromCharCode(byte_array[12]) + String.fromCharCode(byte_array[13]) + String.fromCharCode(byte_array[14]); - if (/^[A-Z]{3}$/.test(currencyCode) && currencyCode !== "XRP" ) { + if (/^[A-Z0-9]{3}$/.test(currencyCode) && currencyCode !== "XRP" ) { this._value = currencyCode; } else if (currencyCode === "\0\0\0") { this._value = 0; diff --git a/src/js/ripple/serializedobject.js b/src/js/ripple/serializedobject.js index c6d85217..a5744d2d 100644 --- a/src/js/ripple/serializedobject.js +++ b/src/js/ripple/serializedobject.js @@ -116,13 +116,12 @@ var TRANSACTION_TYPES = { SerializedObject.prototype.to_json = function() { var old_pointer = this.pointer; this.resetPointer(); - var output = "{"; + var output = {}; while (true) { var key_and_value = stypes.parse_whatever(this); var key = key_and_value[0]; var value = key_and_value[1]; - output += ("\"" + key + "\":" + jsonify_structure(value,key)); - output += ","; + output[key] = jsonify_structure(value,key); if (this.pointer == this.buffer.length) { break; } else if (this.pointer > this.buffer.length) { @@ -130,59 +129,48 @@ SerializedObject.prototype.to_json = function() { break; } } - output = output.slice(0,-1); - output += "}"; this.pointer = old_pointer; - output = JSON.parse(output); return output; } function jsonify_structure(thing,field_name) { var output; var typeof_thing = typeof thing; - if (typeof_thing === "number") { //Special codes + if ("number" === typeof thing) { //Special codes if (field_name) { if (field_name === "LedgerEntryType") { output = thing; //TODO: Do we have special codes for LedgerEntryType? } else if (field_name === "TransactionType") { - output = "\""+TRANSACTION_TYPES[thing]+"\"" || thing; + output = TRANSACTION_TYPES[thing] || thing; } else { output = thing; } } else { output = thing; } - } else if (typeof_thing === "boolean") { - output = thing; - } else if (typeof_thing === "string") { - output = "\"" + thing + "\""; - } else if ( "function" === typeof thing.to_json ) { - output = JSON.stringify(thing.to_json()); + } else if ("object" === typeof thing && + "function" === typeof thing.to_json) { + output = thing.to_json(); } else if (Array.isArray(thing)) { //console.log("here2"); //iterate over array [] - output = "["; + output = []; for (var i=0; i< thing.length; i++) { - output += jsonify_structure(thing[i]); - output += ","; + output.push(jsonify_structure(thing[i])); } - output = output.slice(0,-1); - output += "]"; - } else { + } else if ("object" === typeof thing) { //console.log("here1", thing); //iterate over object {} - output = "{"; + output = {}; var keys = Object.keys(thing); - //console.log(keys); for (var i=0; i