Don't show flags that are set to false

This commit is contained in:
Chris Clark
2015-07-17 15:53:23 -07:00
parent d9eca203ed
commit ddd83d10fa
7 changed files with 38 additions and 20 deletions

View File

@@ -27,7 +27,8 @@
"noDirectRipple": { "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", "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" "type": "boolean"
} },
"limitQuality": {"type": "boolean"}
}, },
"required": ["source", "destination"], "required": ["source", "destination"],
"additionalProperties": false "additionalProperties": false

View File

@@ -10,16 +10,16 @@ function parseAccountTrustline(trustline) {
counterparty: trustline.account, counterparty: trustline.account,
qualityIn: trustline.quality_in || undefined, qualityIn: trustline.quality_in || undefined,
qualityOut: trustline.quality_out || undefined, qualityOut: trustline.quality_out || undefined,
disableRippling: trustline.no_ripple, ripplingDisabled: trustline.no_ripple || undefined,
frozen: trustline.freeze, frozen: trustline.freeze || undefined,
authorized: trustline.authorized authorized: trustline.authorized || undefined
}); });
// rippled doesn't provide the counterparty's qualities // rippled doesn't provide the counterparty's qualities
const counterparty = utils.removeUndefined({ const counterparty = utils.removeUndefined({
limit: trustline.limit_peer, limit: trustline.limit_peer,
disableRippling: trustline.no_ripple_peer, ripplingDisabled: trustline.no_ripple_peer || undefined,
frozen: trustline.freeze_peer, frozen: trustline.freeze_peer || undefined,
authorized: trustline.peer_authorized authorized: trustline.peer_authorized || undefined
}); });
const state = { const state = {
balance: trustline.balance balance: trustline.balance

View File

@@ -13,6 +13,10 @@ function isNoDirectRipple(tx) {
return (tx.Flags & Transaction.flags.Payment.NoRippleDirect) !== 0; return (tx.Flags & Transaction.flags.Payment.NoRippleDirect) !== 0;
} }
function isQualityLimited(tx) {
return (tx.Flags & Transaction.flags.Payment.LimitQuality) !== 0;
}
function parsePaymentMemos(tx) { function parsePaymentMemos(tx) {
if (!Array.isArray(tx.Memos) || tx.Memos.length === 0) { if (!Array.isArray(tx.Memos) || tx.Memos.length === 0) {
return undefined; return undefined;
@@ -48,7 +52,8 @@ function parsePayment(tx: Object): Object {
invoiceID: tx.InvoiceID, invoiceID: tx.InvoiceID,
paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined, paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined,
allowPartialPayment: isPartialPayment(tx) || undefined, allowPartialPayment: isPartialPayment(tx) || undefined,
noDirectRipple: isNoDirectRipple(tx) || undefined noDirectRipple: isNoDirectRipple(tx) || undefined,
limitQuality: isQualityLimited(tx) || undefined
}); });
} }

View File

@@ -4,19 +4,30 @@ const assert = require('assert');
const utils = require('./utils'); const utils = require('./utils');
const flags = utils.core.Transaction.flags.TrustSet; 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 { function parseTrustline(tx: Object): Object {
assert(tx.TransactionType === 'TrustSet'); assert(tx.TransactionType === 'TrustSet');
return { return utils.removeUndefined({
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: tx.QualityIn, qualityIn: tx.QualityIn,
qualityOut: tx.QualityOut, qualityOut: tx.QualityOut,
disableRippling: (tx.Flags & flags.NoRipple) !== 0, ripplingDisabled: parseFlag(
frozen: (tx.Flags & flags.SetFreeze) !== 0, tx.Flags, flags.SetNoRipple, flags.ClearNoRipple),
authorized: (tx.Flags & flags.SetAuth) !== 0 frozen: parseFlag(tx.Flags, flags.SetFreeze, flags.ClearFreeze),
}; authorized: parseFlag(tx.Flags, flags.SetAuth, 0)
});
} }
module.exports = parseTrustline; module.exports = parseTrustline;

View File

@@ -71,6 +71,9 @@ function createPaymentTransaction(account, payment) {
if (payment.noDirectRipple) { if (payment.noDirectRipple) {
transaction.setFlags(['NoRippleDirect']); transaction.setFlags(['NoRippleDirect']);
} }
if (payment.limitQuality) {
transaction.setFlags(['LimitQuality']);
}
if (isSendMaxAllowed(payment)) { if (isSendMaxAllowed(payment)) {
const maxValue = new BigNumber(payment.source.amount.value) const maxValue = new BigNumber(payment.source.amount.value)
.plus(payment.source.slippage || 0).toString(); .plus(payment.source.slippage || 0).toString();

View File

@@ -9,9 +9,7 @@
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM", "counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM",
"qualityIn": 500000000, "qualityIn": 500000000,
"qualityOut": 500000000, "qualityOut": 500000000,
"disableRippling": true, "ripplingDisabled": true
"frozen": false,
"authorized": false
}, },
"outcome": { "outcome": {
"result": "tesSUCCESS", "result": "tesSUCCESS",

View File

@@ -4,7 +4,7 @@
"limit": "5", "limit": "5",
"currency": "USD", "currency": "USD",
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", "counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
"disableRippling": true, "ripplingDisabled": true,
"frozen": true "frozen": true
}, },
"counterparty": { "counterparty": {
@@ -45,7 +45,7 @@
"limit": "1", "limit": "1",
"currency": "USD", "currency": "USD",
"counterparty": "r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X", "counterparty": "r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X",
"disableRippling": true "ripplingDisabled": true
}, },
"counterparty": { "counterparty": {
"limit": "0" "limit": "0"
@@ -59,7 +59,7 @@
"limit": "500", "limit": "500",
"currency": "USD", "currency": "USD",
"counterparty": "rfF3PNkwkq1DygW2wum2HK3RGfgkJjdPVD", "counterparty": "rfF3PNkwkq1DygW2wum2HK3RGfgkJjdPVD",
"disableRippling": true "ripplingDisabled": true
}, },
"counterparty": { "counterparty": {
"limit": "0" "limit": "0"
@@ -76,7 +76,7 @@
}, },
"counterparty": { "counterparty": {
"limit": "100", "limit": "100",
"disableRippling": true "ripplingDisabled": true
}, },
"state": { "state": {
"balance": "0" "balance": "0"