mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Merge branch 'develop' of https://github.com/ripple/ripple-lib into develop
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<keys.length; i++) {
|
||||
var key = keys[i];
|
||||
var value = thing[key]
|
||||
output += "\""+ key + "\":" + jsonify_structure(value);
|
||||
output += ","
|
||||
var value = thing[key];
|
||||
output[key] = jsonify_structure(value);
|
||||
}
|
||||
output = output.slice(0,-1);
|
||||
output += "}";
|
||||
}
|
||||
} else {
|
||||
output = thing;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -254,10 +254,14 @@ var STCurrency = new SerializedType({
|
||||
}
|
||||
},
|
||||
parse: function (so) {
|
||||
var currency = Currency.from_bytes(so.read(20));
|
||||
if (!currency.is_valid()) {
|
||||
throw new Error("Invalid currency");
|
||||
}
|
||||
var bytes = so.read(20);
|
||||
var currency = Currency.from_bytes(bytes);
|
||||
// XXX Disabled check. Theoretically, the Currency class should support any
|
||||
// UInt160 value and consider it valid. But it doesn't, so for the
|
||||
// deserialization to be usable, we need to allow invalid results for now.
|
||||
//if (!currency.is_valid()) {
|
||||
// throw new Error("Invalid currency: "+convert_bytes_to_hex(bytes));
|
||||
//}
|
||||
return currency;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user