mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
Add serialization of XRP as an IOU if explicitly asked for.
Unfortunately, there are some transactions in the history that use this format, so we need to support it in order to be able to verify historic ledgers.
This commit is contained in:
@@ -278,14 +278,14 @@ STHash160.id = 17;
|
|||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
var STCurrency = new SerializedType({
|
var STCurrency = new SerializedType({
|
||||||
serialize: function (so, val) {
|
serialize: function (so, val, xrp_as_ascii) {
|
||||||
var currency = val.to_json().toUpperCase();
|
var currency = val.to_json().toUpperCase();
|
||||||
|
|
||||||
if (!isCurrencyString(currency)) {
|
if (!isCurrencyString(currency)) {
|
||||||
throw new Error('Tried to serialize invalid/unimplemented currency type.');
|
throw new Error('Tried to serialize invalid/unimplemented currency type.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currency === 'XRP') {
|
if (currency === 'XRP' && !xrp_as_ascii) {
|
||||||
serialize_hex(so, UInt160.HEX_ZERO, true);
|
serialize_hex(so, UInt160.HEX_ZERO, true);
|
||||||
} else {
|
} else {
|
||||||
var currencyCode = currency.toUpperCase();
|
var currencyCode = currency.toUpperCase();
|
||||||
@@ -361,7 +361,7 @@ var STAmount = exports.Amount = new SerializedType({
|
|||||||
if (!amount.is_native()) {
|
if (!amount.is_native()) {
|
||||||
// Currency (160-bit hash)
|
// Currency (160-bit hash)
|
||||||
var currency = amount.currency();
|
var currency = amount.currency();
|
||||||
STCurrency.serialize(so, currency);
|
STCurrency.serialize(so, currency, true);
|
||||||
|
|
||||||
// Issuer (160-bit hash)
|
// Issuer (160-bit hash)
|
||||||
so.append(amount.issuer().to_bytes());
|
so.append(amount.issuer().to_bytes());
|
||||||
|
|||||||
@@ -494,6 +494,17 @@ describe('Serialized types', function() {
|
|||||||
types.Amount.serialize(so, '-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
types.Amount.serialize(so, '-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||||
assert.strictEqual(so.to_hex(), '94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
assert.strictEqual(so.to_hex(), '94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||||
});
|
});
|
||||||
|
it('Serialize 15/XRP/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||||
|
// This actually appears in the ledger, so we need to be able to serialize
|
||||||
|
// Transaction #A2AD66C93C7B7277CD5AEB718A4E82D88C7099129948BC66A394EE38B34657A9
|
||||||
|
var so = new SerializedObject();
|
||||||
|
types.Amount.serialize(so, {
|
||||||
|
"value":"1000",
|
||||||
|
"currency":"XRP",
|
||||||
|
"issuer":"rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo"
|
||||||
|
});
|
||||||
|
assert.strictEqual(so.to_hex(), 'D5438D7EA4C680000000000000000000000000005852500000000000E4FE687C90257D3D2D694C8531CDEECBE84F3367');
|
||||||
|
});
|
||||||
it('Parse 1 XRP', function () {
|
it('Parse 1 XRP', function () {
|
||||||
var so = new SerializedObject('4000000000000001');
|
var so = new SerializedObject('4000000000000001');
|
||||||
assert.strictEqual(types.Amount.parse(so).to_json(), '1');
|
assert.strictEqual(types.Amount.parse(so).to_json(), '1');
|
||||||
|
|||||||
Reference in New Issue
Block a user