diff --git a/src/api/common/schemas/payment.json b/src/api/common/schemas/payment.json index bb55eb80..ca0ae111 100644 --- a/src/api/common/schemas/payment.json +++ b/src/api/common/schemas/payment.json @@ -27,7 +27,8 @@ "noDirectRipple": { "description": "A boolean that can be set to true if paths are specified and the sender would like the Ripple Network to disregard any direct paths from the source_account to the destination_account. This may be used to take advantage of an arbitrage opportunity or by gateways wishing to issue balances from a hot wallet to a user who has mistakenly set a trustline directly to the hot wallet", "type": "boolean" - } + }, + "limitQuality": {"type": "boolean"} }, "required": ["source", "destination"], "additionalProperties": false diff --git a/src/api/ledger/parse/account-trustline.js b/src/api/ledger/parse/account-trustline.js index 2f69caf5..5b617792 100644 --- a/src/api/ledger/parse/account-trustline.js +++ b/src/api/ledger/parse/account-trustline.js @@ -10,16 +10,16 @@ function parseAccountTrustline(trustline) { counterparty: trustline.account, qualityIn: trustline.quality_in || undefined, qualityOut: trustline.quality_out || undefined, - disableRippling: trustline.no_ripple, - frozen: trustline.freeze, - authorized: trustline.authorized + ripplingDisabled: trustline.no_ripple || undefined, + frozen: trustline.freeze || undefined, + authorized: trustline.authorized || undefined }); // rippled doesn't provide the counterparty's qualities const counterparty = utils.removeUndefined({ limit: trustline.limit_peer, - disableRippling: trustline.no_ripple_peer, - frozen: trustline.freeze_peer, - authorized: trustline.peer_authorized + ripplingDisabled: trustline.no_ripple_peer || undefined, + frozen: trustline.freeze_peer || undefined, + authorized: trustline.peer_authorized || undefined }); const state = { balance: trustline.balance diff --git a/src/api/ledger/parse/payment.js b/src/api/ledger/parse/payment.js index bf8bba99..a563268b 100644 --- a/src/api/ledger/parse/payment.js +++ b/src/api/ledger/parse/payment.js @@ -13,6 +13,10 @@ function isNoDirectRipple(tx) { return (tx.Flags & Transaction.flags.Payment.NoRippleDirect) !== 0; } +function isQualityLimited(tx) { + return (tx.Flags & Transaction.flags.Payment.LimitQuality) !== 0; +} + function parsePaymentMemos(tx) { if (!Array.isArray(tx.Memos) || tx.Memos.length === 0) { return undefined; @@ -48,7 +52,8 @@ function parsePayment(tx: Object): Object { invoiceID: tx.InvoiceID, paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined, allowPartialPayment: isPartialPayment(tx) || undefined, - noDirectRipple: isNoDirectRipple(tx) || undefined + noDirectRipple: isNoDirectRipple(tx) || undefined, + limitQuality: isQualityLimited(tx) || undefined }); } diff --git a/src/api/ledger/parse/trustline.js b/src/api/ledger/parse/trustline.js index b1298a0b..6704b6af 100644 --- a/src/api/ledger/parse/trustline.js +++ b/src/api/ledger/parse/trustline.js @@ -4,19 +4,30 @@ const assert = require('assert'); const utils = require('./utils'); const flags = utils.core.Transaction.flags.TrustSet; +function parseFlag(flagsValue, trueValue, falseValue) { + if (flagsValue & trueValue) { + return true; + } + if (flagsValue & falseValue) { + return false; + } + return undefined; +} + function parseTrustline(tx: Object): Object { assert(tx.TransactionType === 'TrustSet'); - return { + return utils.removeUndefined({ limit: tx.LimitAmount.value, currency: tx.LimitAmount.currency, counterparty: tx.LimitAmount.issuer, qualityIn: tx.QualityIn, qualityOut: tx.QualityOut, - disableRippling: (tx.Flags & flags.NoRipple) !== 0, - frozen: (tx.Flags & flags.SetFreeze) !== 0, - authorized: (tx.Flags & flags.SetAuth) !== 0 - }; + ripplingDisabled: parseFlag( + tx.Flags, flags.SetNoRipple, flags.ClearNoRipple), + frozen: parseFlag(tx.Flags, flags.SetFreeze, flags.ClearFreeze), + authorized: parseFlag(tx.Flags, flags.SetAuth, 0) + }); } module.exports = parseTrustline; diff --git a/src/api/transaction/payment.js b/src/api/transaction/payment.js index 6a6d5db1..495f72d9 100644 --- a/src/api/transaction/payment.js +++ b/src/api/transaction/payment.js @@ -71,6 +71,9 @@ function createPaymentTransaction(account, payment) { if (payment.noDirectRipple) { transaction.setFlags(['NoRippleDirect']); } + if (payment.limitQuality) { + transaction.setFlags(['LimitQuality']); + } if (isSendMaxAllowed(payment)) { const maxValue = new BigNumber(payment.source.amount.value) .plus(payment.source.slippage || 0).toString(); diff --git a/test/fixtures/api/responses/get-transaction-trustline-set.json b/test/fixtures/api/responses/get-transaction-trustline-set.json index 6b6659cc..826e7d7a 100644 --- a/test/fixtures/api/responses/get-transaction-trustline-set.json +++ b/test/fixtures/api/responses/get-transaction-trustline-set.json @@ -9,9 +9,7 @@ "counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM", "qualityIn": 500000000, "qualityOut": 500000000, - "disableRippling": true, - "frozen": false, - "authorized": false + "ripplingDisabled": true }, "outcome": { "result": "tesSUCCESS", diff --git a/test/fixtures/api/responses/get-trustlines.json b/test/fixtures/api/responses/get-trustlines.json index 59902bfa..5a86ae53 100644 --- a/test/fixtures/api/responses/get-trustlines.json +++ b/test/fixtures/api/responses/get-trustlines.json @@ -4,7 +4,7 @@ "limit": "5", "currency": "USD", "counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "disableRippling": true, + "ripplingDisabled": true, "frozen": true }, "counterparty": { @@ -45,7 +45,7 @@ "limit": "1", "currency": "USD", "counterparty": "r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X", - "disableRippling": true + "ripplingDisabled": true }, "counterparty": { "limit": "0" @@ -59,7 +59,7 @@ "limit": "500", "currency": "USD", "counterparty": "rfF3PNkwkq1DygW2wum2HK3RGfgkJjdPVD", - "disableRippling": true + "ripplingDisabled": true }, "counterparty": { "limit": "0" @@ -76,7 +76,7 @@ }, "counterparty": { "limit": "100", - "disableRippling": true + "ripplingDisabled": true }, "state": { "balance": "0"