mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
Merge pull request #665 from clark800/fix-quality
Fix parsing of quality for getTrustlines
This commit is contained in:
@@ -24,8 +24,8 @@ function parseAccountTrustline(trustline: Trustline): AccountTrustline {
|
|||||||
limit: trustline.limit,
|
limit: trustline.limit,
|
||||||
currency: trustline.currency,
|
currency: trustline.currency,
|
||||||
counterparty: trustline.account,
|
counterparty: trustline.account,
|
||||||
qualityIn: trustline.quality_in || undefined,
|
qualityIn: utils.parseQuality(trustline.quality_in) || undefined,
|
||||||
qualityOut: trustline.quality_out || undefined,
|
qualityOut: utils.parseQuality(trustline.quality_out) || undefined,
|
||||||
ripplingDisabled: trustline.no_ripple || undefined,
|
ripplingDisabled: trustline.no_ripple || undefined,
|
||||||
frozen: trustline.freeze || undefined,
|
frozen: trustline.freeze || undefined,
|
||||||
authorized: trustline.authorized || undefined
|
authorized: trustline.authorized || undefined
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const flags = utils.txFlags.TrustSet;
|
const flags = utils.txFlags.TrustSet;
|
||||||
const BigNumber = require('bignumber.js');
|
|
||||||
|
|
||||||
function parseFlag(flagsValue, trueValue, falseValue) {
|
function parseFlag(flagsValue, trueValue, falseValue) {
|
||||||
if (flagsValue & trueValue) {
|
if (flagsValue & trueValue) {
|
||||||
@@ -15,13 +14,6 @@ function parseFlag(flagsValue, trueValue, falseValue) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseQuality(quality?: number) {
|
|
||||||
if (typeof quality === 'number') {
|
|
||||||
return (new BigNumber(quality)).shift(-9).toNumber();
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseTrustline(tx: Object): Object {
|
function parseTrustline(tx: Object): Object {
|
||||||
assert(tx.TransactionType === 'TrustSet');
|
assert(tx.TransactionType === 'TrustSet');
|
||||||
|
|
||||||
@@ -29,8 +21,8 @@ function parseTrustline(tx: Object): Object {
|
|||||||
limit: tx.LimitAmount.value,
|
limit: tx.LimitAmount.value,
|
||||||
currency: tx.LimitAmount.currency,
|
currency: tx.LimitAmount.currency,
|
||||||
counterparty: tx.LimitAmount.issuer,
|
counterparty: tx.LimitAmount.issuer,
|
||||||
qualityIn: parseQuality(tx.QualityIn),
|
qualityIn: utils.parseQuality(tx.QualityIn),
|
||||||
qualityOut: parseQuality(tx.QualityOut),
|
qualityOut: utils.parseQuality(tx.QualityOut),
|
||||||
ripplingDisabled: parseFlag(
|
ripplingDisabled: parseFlag(
|
||||||
tx.Flags, flags.SetNoRipple, flags.ClearNoRipple),
|
tx.Flags, flags.SetNoRipple, flags.ClearNoRipple),
|
||||||
frozen: parseFlag(tx.Flags, flags.SetFreeze, flags.ClearFreeze),
|
frozen: parseFlag(tx.Flags, flags.SetFreeze, flags.ClearFreeze),
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ function adjustQualityForXRP(
|
|||||||
(new BigNumber(quality)).shift(shift).toString();
|
(new BigNumber(quality)).shift(shift).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseQuality(quality: ?number) {
|
||||||
|
if (typeof quality === 'number') {
|
||||||
|
return (new BigNumber(quality)).shift(-9).toNumber();
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function parseTimestamp(rippleTime: number): string | void {
|
function parseTimestamp(rippleTime: number): string | void {
|
||||||
return rippleTime ? utils.common.rippleTimeToISO8601(rippleTime) : undefined;
|
return rippleTime ? utils.common.rippleTimeToISO8601(rippleTime) : undefined;
|
||||||
}
|
}
|
||||||
@@ -80,6 +87,7 @@ function parseMemos(tx: Object): ?Array<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
parseQuality,
|
||||||
parseOutcome,
|
parseOutcome,
|
||||||
parseMemos,
|
parseMemos,
|
||||||
hexToString,
|
hexToString,
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
"specification": {
|
"specification": {
|
||||||
"limit": "0",
|
"limit": "0",
|
||||||
"currency": "ASP",
|
"currency": "ASP",
|
||||||
"counterparty": "r3vi7mWxru9rJCxETCyA1CHvzL96eZWx5z"
|
"counterparty": "r3vi7mWxru9rJCxETCyA1CHvzL96eZWx5z",
|
||||||
|
"qualityIn": 1
|
||||||
},
|
},
|
||||||
"counterparty": {
|
"counterparty": {
|
||||||
"limit": "10"
|
"limit": "10"
|
||||||
|
|||||||
2
test/fixtures/rippled/account-lines.js
vendored
2
test/fixtures/rippled/account-lines.js
vendored
@@ -22,7 +22,7 @@ module.exports.normal = function(request, options = {}) {
|
|||||||
currency: 'ASP',
|
currency: 'ASP',
|
||||||
limit: '0',
|
limit: '0',
|
||||||
limit_peer: '10',
|
limit_peer: '10',
|
||||||
quality_in: 0,
|
quality_in: 1000000000,
|
||||||
quality_out: 0
|
quality_out: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user