From 863e0486b9b37c32120af8ae8e1b762ad105ca71 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 13:06:32 -0500 Subject: [PATCH 01/30] remove setTransactions and any reference to modifying a transaction parameter --- packages/xrpl/src/models/utils/flags.ts | 69 ++++++++++++------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index 81fba1aee7..f6ef4be79f 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign -- param reassign is safe */ /* eslint-disable no-bitwise -- flags require bitwise operations */ import { ValidationError } from '../../errors' import { @@ -8,7 +7,6 @@ import { import { AccountSetTfFlags } from '../transactions/accountSet' import { AMMDepositFlags } from '../transactions/AMMDeposit' import { AMMWithdrawFlags } from '../transactions/AMMWithdraw' -import { GlobalFlags } from '../transactions/common' import { NFTokenCreateOfferFlags } from '../transactions/NFTokenCreateOffer' import { NFTokenMintFlags } from '../transactions/NFTokenMint' import { OfferCreateFlags } from '../transactions/offerCreate' @@ -58,36 +56,33 @@ const txToFlag = { } /** - * Sets a transaction's flags to its numeric representation. + * Returns a transaction's flags as its numeric representation. * - * @param tx - A transaction to set its flags to its numeric representation. + * @param tx - A transaction to parse flags for + * @returns A numerical representation of a transaction's flags */ -export function setTransactionFlagsToNumber(tx: Transaction): void { - if (tx.Flags == null) { - tx.Flags = 0 - return - } +export function convertTxFlagsToNumber(tx: Transaction): number { if (typeof tx.Flags === 'number') { - return + return tx.Flags } - tx.Flags = txToFlag[tx.TransactionType] - ? convertFlagsToNumber(tx.Flags, txToFlag[tx.TransactionType]) - : 0 -} + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- safe member access + const flagEnum = txToFlag[tx.TransactionType] -// eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum -function convertFlagsToNumber(flags: GlobalFlags, flagEnum: any): number { - return Object.keys(flags).reduce((resultFlags, flag) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access - if (flagEnum[flag] == null) { - throw new ValidationError( - `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`, - ) - } - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access - return flags[flag] ? resultFlags | flagEnum[flag] : resultFlags - }, 0) + if (flagEnum && tx.Flags) { + return Object.keys(tx.Flags).reduce((resultFlags, flag) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access + if (flagEnum[flag] == null) { + throw new ValidationError( + `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`, + ) + } + + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access + return tx.Flags?.[flag] ? resultFlags | flagEnum[flag] : resultFlags + }, 0) + } + return 0 } /** @@ -97,22 +92,24 @@ function convertFlagsToNumber(flags: GlobalFlags, flagEnum: any): number { * @returns A map with all flags as booleans. */ export function parseTransactionFlags(tx: Transaction): object { - setTransactionFlagsToNumber(tx) - if (typeof tx.Flags !== 'number' || !tx.Flags || tx.Flags === 0) { + const flags = convertTxFlagsToNumber(tx) + if (flags === 0) { return {} } - const flags = tx.Flags - const flagsMap = {} + const booleanFlagMap = {} // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- safe member access - const flagEnum = txToFlag[tx.TransactionType] - Object.values(flagEnum).forEach((flag) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access - if (typeof flag === 'string' && isFlagEnabled(flags, flagEnum[flag])) { - flagsMap[flag] = true + const transactionTypeFlags = txToFlag[tx.TransactionType] + Object.values(transactionTypeFlags).forEach((flag) => { + if ( + typeof flag === 'string' && + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access + isFlagEnabled(flags, transactionTypeFlags[flag]) + ) { + booleanFlagMap[flag] = true } }) - return flagsMap + return booleanFlagMap } From 95f46ce91e305cb514045dbf2391b2b31da83c3c Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 13:11:17 -0500 Subject: [PATCH 02/30] remove use of setter in autofill --- packages/xrpl/src/client/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 722b169f2a..0afaa29b72 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -47,7 +47,7 @@ import type { OnEventToListenerMap, } from '../models/methods/subscribe' import type { SubmittableTransaction } from '../models/transactions' -import { setTransactionFlagsToNumber } from '../models/utils/flags' +import { convertTxFlagsToNumber } from '../models/utils/flags' import { ensureClassicAddress, submitRequest, @@ -665,7 +665,7 @@ class Client extends EventEmitter { const tx = { ...transaction } setValidAddresses(tx) - setTransactionFlagsToNumber(tx) + tx.Flags = convertTxFlagsToNumber(tx) const promises: Array> = [] if (tx.NetworkID == null) { From 0f3e67d62f5be7337931bf28cf70873cef305826 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 13:54:28 -0500 Subject: [PATCH 03/30] changelog and test fixes --- packages/xrpl/HISTORY.md | 3 +++ packages/xrpl/test/models/utils.test.ts | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index da384a908c..fa27ea8177 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -3,6 +3,9 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release. ## Unreleased Changes +* Fix for parseTransactionFlags to no longer modify a passed in transaction when returning a parsed mapping +* Remove setTransactionFlagsToNumber +* Add convertTxFlagsToNumber as a utility function in xrpl to return the number conversion of a transaction's flags ### Added * parseTransactionFlags as a utility function in the xrpl package to streamline transactions flags-to-map conversion diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index c4313610b7..562790f83b 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -15,7 +15,7 @@ import { import { AccountRootFlags } from '../../src/models/ledger' import { isFlagEnabled } from '../../src/models/utils' import { - setTransactionFlagsToNumber, + convertTxFlagsToNumber, parseAccountRootFlags, parseTransactionFlags, } from '../../src/models/utils/flags' @@ -71,8 +71,8 @@ describe('Models Utils', function () { const { tfPassive, tfFillOrKill } = OfferCreateFlags const expected: number = tfPassive | tfFillOrKill - setTransactionFlagsToNumber(tx) - assert.strictEqual(tx.Flags, expected) + const flagNum = convertTxFlagsToNumber(tx) + assert.strictEqual(flagNum, expected) }) it('sets PaymentChannelClaimFlags to its numeric value', function () { @@ -90,8 +90,8 @@ describe('Models Utils', function () { const { tfRenew } = PaymentChannelClaimFlags const expected: number = tfRenew - setTransactionFlagsToNumber(tx) - assert.strictEqual(tx.Flags, expected) + const flagNum = convertTxFlagsToNumber(tx) + assert.strictEqual(flagNum, expected) }) it('sets PaymentTransactionFlags to its numeric value', function () { @@ -110,8 +110,8 @@ describe('Models Utils', function () { const { tfPartialPayment, tfLimitQuality } = PaymentFlags const expected: number = tfPartialPayment | tfLimitQuality - setTransactionFlagsToNumber(tx) - assert.strictEqual(tx.Flags, expected) + const flagNum = convertTxFlagsToNumber(tx) + assert.strictEqual(flagNum, expected) }) it('sets TrustSetFlags to its numeric value', function () { @@ -137,8 +137,8 @@ describe('Models Utils', function () { const { tfSetfAuth, tfClearNoRipple, tfClearFreeze } = TrustSetFlags const expected: number = tfSetfAuth | tfClearNoRipple | tfClearFreeze - setTransactionFlagsToNumber(tx) - assert.strictEqual(tx.Flags, expected) + const flagNum = convertTxFlagsToNumber(tx) + assert.strictEqual(flagNum, expected) }) it('sets other transaction types flags to its numeric value', function () { @@ -148,8 +148,8 @@ describe('Models Utils', function () { Flags: {}, } - setTransactionFlagsToNumber(tx) - assert.strictEqual(tx.Flags, 0) + const flagNum = convertTxFlagsToNumber(tx) + assert.strictEqual(flagNum, 0) }) // eslint-disable-next-line complexity -- Simpler to list them all out at once. From bf4a4ab07b1ec04a9bd5d2433d12191ded200512 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 14:03:33 -0500 Subject: [PATCH 04/30] add back deprecated function with warnings --- packages/xrpl/src/models/utils/flags.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index f6ef4be79f..b590a83b83 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -55,6 +55,25 @@ const txToFlag = { XChainModifyBridge: XChainModifyBridgeFlags, } +/** + * Sets a transaction's flags to its numeric representation. + * + * @deprecated + * This utility function is deprecated. + * Use convertTxFlagsToNumber() instead and use the returned value to modify the tx.Flags from the caller. + * + * @param tx - A transaction to set its flags to its numeric representation. + */ +export function setTransactionFlagsToNumber(tx: Transaction): void { + // eslint-disable-next-line no-console -- intended deprecation warning + console.warn( + 'This function is deprecated. Use convertTxFlagsToNumber() instead and use the returned value to modify the tx.Flags from the caller.', + ) + + // eslint-disable-next-line no-param-reassign -- intended param reassign in setter + tx.Flags = convertTxFlagsToNumber(tx) +} + /** * Returns a transaction's flags as its numeric representation. * From 36116295d1eccb6f6c7a15aeab0ad05c8b3a27cf Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 14:05:33 -0500 Subject: [PATCH 05/30] add new helper function to exported --- packages/xrpl/src/models/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/index.ts b/packages/xrpl/src/models/index.ts index 5c98faf82e..56212a9bc3 100644 --- a/packages/xrpl/src/models/index.ts +++ b/packages/xrpl/src/models/index.ts @@ -8,8 +8,9 @@ */ export * as LedgerEntry from './ledger' export { - setTransactionFlagsToNumber, parseAccountRootFlags, + setTransactionFlagsToNumber, + convertTxFlagsToNumber, parseTransactionFlags, } from './utils/flags' export * from './methods' From 951ba1925dda8fa866c41bad070e9570f04ab6cc Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 14:06:15 -0500 Subject: [PATCH 06/30] update readme with deprecated --- packages/xrpl/HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index fa27ea8177..695efce06d 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -4,7 +4,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ## Unreleased Changes * Fix for parseTransactionFlags to no longer modify a passed in transaction when returning a parsed mapping -* Remove setTransactionFlagsToNumber +* Deprecate setTransactionFlagsToNumber. Should use convertTxFlagsToNumber instead * Add convertTxFlagsToNumber as a utility function in xrpl to return the number conversion of a transaction's flags ### Added From 803b27dc5a0b0a9fbd73647df68e32d8ce5972fb Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 14:14:43 -0500 Subject: [PATCH 07/30] remove references to deprecated setter --- packages/xrpl/src/models/transactions/transaction.ts | 7 +++++-- packages/xrpl/test/models/utils.test.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index 0ddc719539..397f042393 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -4,7 +4,10 @@ import { ValidationError } from '../../errors' import { IssuedCurrencyAmount, Memo } from '../common' import { isHex } from '../utils' -import { setTransactionFlagsToNumber } from '../utils/flags' +import { + convertTxFlagsToNumber, + setTransactionFlagsToNumber, +} from '../utils/flags' import { AccountDelete, validateAccountDelete } from './accountDelete' import { AccountSet, validateAccountSet } from './accountSet' @@ -232,7 +235,7 @@ export function validate(transaction: Record): void { }) // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- okay here - setTransactionFlagsToNumber(tx as unknown as Transaction) + tx.Flags = convertTxFlagsToNumber(tx as unknown as Transaction) switch (tx.TransactionType) { case 'AMMBid': validateAMMBid(tx) diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index 562790f83b..eb97cc37ee 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -46,7 +46,7 @@ describe('Models Utils', function () { }) }) - describe('setTransactionFlagsToNumber', function () { + describe('convertTxFlagsToNumber', function () { it('sets OfferCreateFlags to its numeric value', function () { const tx: OfferCreate = { Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W', From 4078fb8571d772e501a062a5889476a047a1250b Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 14:24:05 -0500 Subject: [PATCH 08/30] fix changelog syntax --- packages/xrpl/HISTORY.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 695efce06d..7f9434c4c3 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -2,19 +2,20 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release. -## Unreleased Changes -* Fix for parseTransactionFlags to no longer modify a passed in transaction when returning a parsed mapping -* Deprecate setTransactionFlagsToNumber. Should use convertTxFlagsToNumber instead -* Add convertTxFlagsToNumber as a utility function in xrpl to return the number conversion of a transaction's flags +## Unreleased ### Added -* parseTransactionFlags as a utility function in the xrpl package to streamline transactions flags-to-map conversion +* `parseTransactionFlags` as a utility function in the xrpl package to streamline transactions flags-to-map conversion +* `convertTxFlagsToNumber` as a utility function in xrpl to return the number conversion of a transaction's flags ### Fixed * `TransactionStream` model supports APIv2 * `TransactionStream` model includes `close_time_iso` field * `Ledger` model includes `close_time_iso` field +### Changed +* Deprecated `setTransactionFlagsToNumber`. Start using convertTxFlagsToNumber instead + ## 4.0.0 (2024-07-15) ### BREAKING CHANGES From a1dcfe25f12e05ac7e991e9e977fca6582ac9b44 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 14:25:40 -0500 Subject: [PATCH 09/30] revert to test old functions --- packages/xrpl/test/models/utils.test.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index eb97cc37ee..c4313610b7 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -15,7 +15,7 @@ import { import { AccountRootFlags } from '../../src/models/ledger' import { isFlagEnabled } from '../../src/models/utils' import { - convertTxFlagsToNumber, + setTransactionFlagsToNumber, parseAccountRootFlags, parseTransactionFlags, } from '../../src/models/utils/flags' @@ -46,7 +46,7 @@ describe('Models Utils', function () { }) }) - describe('convertTxFlagsToNumber', function () { + describe('setTransactionFlagsToNumber', function () { it('sets OfferCreateFlags to its numeric value', function () { const tx: OfferCreate = { Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W', @@ -71,8 +71,8 @@ describe('Models Utils', function () { const { tfPassive, tfFillOrKill } = OfferCreateFlags const expected: number = tfPassive | tfFillOrKill - const flagNum = convertTxFlagsToNumber(tx) - assert.strictEqual(flagNum, expected) + setTransactionFlagsToNumber(tx) + assert.strictEqual(tx.Flags, expected) }) it('sets PaymentChannelClaimFlags to its numeric value', function () { @@ -90,8 +90,8 @@ describe('Models Utils', function () { const { tfRenew } = PaymentChannelClaimFlags const expected: number = tfRenew - const flagNum = convertTxFlagsToNumber(tx) - assert.strictEqual(flagNum, expected) + setTransactionFlagsToNumber(tx) + assert.strictEqual(tx.Flags, expected) }) it('sets PaymentTransactionFlags to its numeric value', function () { @@ -110,8 +110,8 @@ describe('Models Utils', function () { const { tfPartialPayment, tfLimitQuality } = PaymentFlags const expected: number = tfPartialPayment | tfLimitQuality - const flagNum = convertTxFlagsToNumber(tx) - assert.strictEqual(flagNum, expected) + setTransactionFlagsToNumber(tx) + assert.strictEqual(tx.Flags, expected) }) it('sets TrustSetFlags to its numeric value', function () { @@ -137,8 +137,8 @@ describe('Models Utils', function () { const { tfSetfAuth, tfClearNoRipple, tfClearFreeze } = TrustSetFlags const expected: number = tfSetfAuth | tfClearNoRipple | tfClearFreeze - const flagNum = convertTxFlagsToNumber(tx) - assert.strictEqual(flagNum, expected) + setTransactionFlagsToNumber(tx) + assert.strictEqual(tx.Flags, expected) }) it('sets other transaction types flags to its numeric value', function () { @@ -148,8 +148,8 @@ describe('Models Utils', function () { Flags: {}, } - const flagNum = convertTxFlagsToNumber(tx) - assert.strictEqual(flagNum, 0) + setTransactionFlagsToNumber(tx) + assert.strictEqual(tx.Flags, 0) }) // eslint-disable-next-line complexity -- Simpler to list them all out at once. From 1a2d37f5f14b380fd83fec332bc128ce441c0f82 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 14:29:27 -0500 Subject: [PATCH 10/30] lint --- packages/xrpl/src/models/transactions/transaction.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index 397f042393..824bb20f34 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -4,10 +4,7 @@ import { ValidationError } from '../../errors' import { IssuedCurrencyAmount, Memo } from '../common' import { isHex } from '../utils' -import { - convertTxFlagsToNumber, - setTransactionFlagsToNumber, -} from '../utils/flags' +import { convertTxFlagsToNumber } from '../utils/flags' import { AccountDelete, validateAccountDelete } from './accountDelete' import { AccountSet, validateAccountSet } from './accountSet' From 4b872ab84059170961adece6f83280001b620c52 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Wed, 13 Nov 2024 16:52:30 -0500 Subject: [PATCH 11/30] lint for deprecation --- packages/xrpl/src/models/utils/flags.ts | 6 ++++-- packages/xrpl/test/models/utils.test.ts | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index b590a83b83..0530ae1cee 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -70,8 +70,10 @@ export function setTransactionFlagsToNumber(tx: Transaction): void { 'This function is deprecated. Use convertTxFlagsToNumber() instead and use the returned value to modify the tx.Flags from the caller.', ) - // eslint-disable-next-line no-param-reassign -- intended param reassign in setter - tx.Flags = convertTxFlagsToNumber(tx) + if (tx.Flags) { + // eslint-disable-next-line no-param-reassign -- intended param reassign in setter + tx.Flags = convertTxFlagsToNumber(tx) + } } /** diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index c4313610b7..bec5d2b253 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable import/no-deprecated -- using deprecated setTransactionFlagsToNumbers to ensure no breaking changes */ /* eslint-disable no-bitwise -- flags require bitwise operations */ import { assert } from 'chai' From fa078fdbb5b9ac0920330fd265b47da1d23e6932 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Fri, 20 Dec 2024 15:51:29 -0500 Subject: [PATCH 12/30] remove unsafe assertions --- packages/xrpl/src/models/utils/flags.ts | 59 ++++++++++++++----------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index 0530ae1cee..4304fcc7e8 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -55,6 +55,12 @@ const txToFlag = { XChainModifyBridge: XChainModifyBridgeFlags, } +function istxToFlagKey( + transactionType: string, +): transactionType is keyof typeof txToFlag { + return transactionType in txToFlag +} + /** * Sets a transaction's flags to its numeric representation. * @@ -71,7 +77,7 @@ export function setTransactionFlagsToNumber(tx: Transaction): void { ) if (tx.Flags) { - // eslint-disable-next-line no-param-reassign -- intended param reassign in setter + // eslint-disable-next-line no-param-reassign -- intended param reassign in setter, retain old functionality for compatibility tx.Flags = convertTxFlagsToNumber(tx) } } @@ -87,22 +93,23 @@ export function convertTxFlagsToNumber(tx: Transaction): number { return tx.Flags } - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- safe member access - const flagEnum = txToFlag[tx.TransactionType] - - if (flagEnum && tx.Flags) { - return Object.keys(tx.Flags).reduce((resultFlags, flag) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access - if (flagEnum[flag] == null) { - throw new ValidationError( - `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`, - ) - } + if (istxToFlagKey(tx.TransactionType)) { + const flagEnum = txToFlag[tx.TransactionType] + if (tx.Flags) { + return Object.keys(tx.Flags).reduce((resultFlags, flag) => { + if (flagEnum[flag] == null) { + throw new ValidationError( + `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify( + flagEnum, + )}`, + ) + } - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access - return tx.Flags?.[flag] ? resultFlags | flagEnum[flag] : resultFlags - }, 0) + return tx.Flags?.[flag] ? resultFlags | flagEnum[flag] : resultFlags + }, 0) + } } + return 0 } @@ -120,17 +127,17 @@ export function parseTransactionFlags(tx: Transaction): object { const booleanFlagMap = {} - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- safe member access - const transactionTypeFlags = txToFlag[tx.TransactionType] - Object.values(transactionTypeFlags).forEach((flag) => { - if ( - typeof flag === 'string' && - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access - isFlagEnabled(flags, transactionTypeFlags[flag]) - ) { - booleanFlagMap[flag] = true - } - }) + if (istxToFlagKey(tx.TransactionType)) { + const transactionTypeFlags = txToFlag[tx.TransactionType] + Object.values(transactionTypeFlags).forEach((flag) => { + if ( + typeof flag === 'string' && + isFlagEnabled(flags, transactionTypeFlags[flag]) + ) { + booleanFlagMap[flag] = true + } + }) + } return booleanFlagMap } From 73eda68b725cc63c636e02daf890d5dd8df4d560 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Mon, 23 Dec 2024 13:08:33 -0500 Subject: [PATCH 13/30] separate null check --- packages/xrpl/src/models/utils/flags.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index 4304fcc7e8..25375431b2 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -89,25 +89,24 @@ export function setTransactionFlagsToNumber(tx: Transaction): void { * @returns A numerical representation of a transaction's flags */ export function convertTxFlagsToNumber(tx: Transaction): number { + if (!tx.Flags) { + return 0 + } if (typeof tx.Flags === 'number') { return tx.Flags } if (istxToFlagKey(tx.TransactionType)) { const flagEnum = txToFlag[tx.TransactionType] - if (tx.Flags) { - return Object.keys(tx.Flags).reduce((resultFlags, flag) => { - if (flagEnum[flag] == null) { - throw new ValidationError( - `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify( - flagEnum, - )}`, - ) - } - - return tx.Flags?.[flag] ? resultFlags | flagEnum[flag] : resultFlags - }, 0) - } + return Object.keys(tx.Flags).reduce((resultFlags, flag) => { + if (flagEnum[flag] == null) { + throw new ValidationError( + `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`, + ) + } + + return tx.Flags?.[flag] ? resultFlags | flagEnum[flag] : resultFlags + }, 0) } return 0 From 501b845626192d4e8e65fe08d671195f68d54ef1 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Mon, 23 Dec 2024 13:30:18 -0500 Subject: [PATCH 14/30] clean up tests --- packages/xrpl/test/models/utils.test.ts | 226 ++++++++++++++++++------ 1 file changed, 169 insertions(+), 57 deletions(-) diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index bec5d2b253..ea2cfb99fa 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -17,6 +17,7 @@ import { AccountRootFlags } from '../../src/models/ledger' import { isFlagEnabled } from '../../src/models/utils' import { setTransactionFlagsToNumber, + convertTxFlagsToNumber, parseAccountRootFlags, parseTransactionFlags, } from '../../src/models/utils/flags' @@ -47,6 +48,65 @@ describe('Models Utils', function () { }) }) + describe('parseAccountRootFlags', function () { + // eslint-disable-next-line complexity -- Simpler to list them all out at once. + it('parseAccountRootFlags all enabled', function () { + const accountRootFlags = + AccountRootFlags.lsfDefaultRipple | + AccountRootFlags.lsfDepositAuth | + AccountRootFlags.lsfDisableMaster | + AccountRootFlags.lsfDisallowXRP | + AccountRootFlags.lsfGlobalFreeze | + AccountRootFlags.lsfNoFreeze | + AccountRootFlags.lsfPasswordSpent | + AccountRootFlags.lsfRequireAuth | + AccountRootFlags.lsfRequireDestTag | + AccountRootFlags.lsfDisallowIncomingNFTokenOffer | + AccountRootFlags.lsfDisallowIncomingCheck | + AccountRootFlags.lsfDisallowIncomingPayChan | + AccountRootFlags.lsfDisallowIncomingTrustline | + AccountRootFlags.lsfAllowTrustLineClawback + + const parsed = parseAccountRootFlags(accountRootFlags) + + assert.isTrue( + parsed.lsfDefaultRipple && + parsed.lsfDepositAuth && + parsed.lsfDisableMaster && + parsed.lsfDisallowXRP && + parsed.lsfGlobalFreeze && + parsed.lsfNoFreeze && + parsed.lsfPasswordSpent && + parsed.lsfRequireAuth && + parsed.lsfRequireDestTag && + parsed.lsfDisallowIncomingNFTokenOffer && + parsed.lsfDisallowIncomingCheck && + parsed.lsfDisallowIncomingPayChan && + parsed.lsfDisallowIncomingTrustline && + parsed.lsfAllowTrustLineClawback, + ) + }) + + it('parseAccountFlags all false', function () { + const parsed = parseAccountRootFlags(0) + + assert.isUndefined(parsed.lsfDefaultRipple) + assert.isUndefined(parsed.lsfDepositAuth) + assert.isUndefined(parsed.lsfDisableMaster) + assert.isUndefined(parsed.lsfDisallowXRP) + assert.isUndefined(parsed.lsfGlobalFreeze) + assert.isUndefined(parsed.lsfNoFreeze) + assert.isUndefined(parsed.lsfPasswordSpent) + assert.isUndefined(parsed.lsfRequireAuth) + assert.isUndefined(parsed.lsfRequireDestTag) + assert.isUndefined(parsed.lsfDisallowIncomingNFTokenOffer) + assert.isUndefined(parsed.lsfDisallowIncomingCheck) + assert.isUndefined(parsed.lsfDisallowIncomingPayChan) + assert.isUndefined(parsed.lsfDisallowIncomingTrustline) + assert.isUndefined(parsed.lsfAllowTrustLineClawback) + }) + }) + describe('setTransactionFlagsToNumber', function () { it('sets OfferCreateFlags to its numeric value', function () { const tx: OfferCreate = { @@ -152,64 +212,9 @@ describe('Models Utils', function () { setTransactionFlagsToNumber(tx) assert.strictEqual(tx.Flags, 0) }) + }) - // eslint-disable-next-line complexity -- Simpler to list them all out at once. - it('parseAccountRootFlags all enabled', function () { - const accountRootFlags = - AccountRootFlags.lsfDefaultRipple | - AccountRootFlags.lsfDepositAuth | - AccountRootFlags.lsfDisableMaster | - AccountRootFlags.lsfDisallowXRP | - AccountRootFlags.lsfGlobalFreeze | - AccountRootFlags.lsfNoFreeze | - AccountRootFlags.lsfPasswordSpent | - AccountRootFlags.lsfRequireAuth | - AccountRootFlags.lsfRequireDestTag | - AccountRootFlags.lsfDisallowIncomingNFTokenOffer | - AccountRootFlags.lsfDisallowIncomingCheck | - AccountRootFlags.lsfDisallowIncomingPayChan | - AccountRootFlags.lsfDisallowIncomingTrustline | - AccountRootFlags.lsfAllowTrustLineClawback - - const parsed = parseAccountRootFlags(accountRootFlags) - - assert.isTrue( - parsed.lsfDefaultRipple && - parsed.lsfDepositAuth && - parsed.lsfDisableMaster && - parsed.lsfDisallowXRP && - parsed.lsfGlobalFreeze && - parsed.lsfNoFreeze && - parsed.lsfPasswordSpent && - parsed.lsfRequireAuth && - parsed.lsfRequireDestTag && - parsed.lsfDisallowIncomingNFTokenOffer && - parsed.lsfDisallowIncomingCheck && - parsed.lsfDisallowIncomingPayChan && - parsed.lsfDisallowIncomingTrustline && - parsed.lsfAllowTrustLineClawback, - ) - }) - - it('parseAccountFlags all false', function () { - const parsed = parseAccountRootFlags(0) - - assert.isUndefined(parsed.lsfDefaultRipple) - assert.isUndefined(parsed.lsfDepositAuth) - assert.isUndefined(parsed.lsfDisableMaster) - assert.isUndefined(parsed.lsfDisallowXRP) - assert.isUndefined(parsed.lsfGlobalFreeze) - assert.isUndefined(parsed.lsfNoFreeze) - assert.isUndefined(parsed.lsfPasswordSpent) - assert.isUndefined(parsed.lsfRequireAuth) - assert.isUndefined(parsed.lsfRequireDestTag) - assert.isUndefined(parsed.lsfDisallowIncomingNFTokenOffer) - assert.isUndefined(parsed.lsfDisallowIncomingCheck) - assert.isUndefined(parsed.lsfDisallowIncomingPayChan) - assert.isUndefined(parsed.lsfDisallowIncomingTrustline) - assert.isUndefined(parsed.lsfAllowTrustLineClawback) - }) - + describe('parseTransactionFlags', function () { it('parseTransactionFlags all enabled', function () { const tx: PaymentChannelClaim = { Account: 'r...', @@ -265,4 +270,111 @@ describe('Models Utils', function () { assert.notStrictEqual(flagsMap, expected) }) }) + + describe('convertTxFlagsToNumber', function () { + it('converts OfferCreateFlags to its numeric value', function () { + const tx: OfferCreate = { + Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W', + Fee: '10', + TakerGets: { + currency: 'DSH', + issuer: 'rcXY84C4g14iFp6taFXjjQGVeHqSCh9RX', + value: '43.11584856965009', + }, + TakerPays: '12928290425', + TransactionType: 'OfferCreate', + TxnSignature: + '3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91', + Flags: { + tfPassive: true, + tfImmediateOrCancel: false, + tfFillOrKill: true, + tfSell: false, + }, + } + + const { tfPassive, tfFillOrKill } = OfferCreateFlags + const expected: number = tfPassive | tfFillOrKill + + const result = convertTxFlagsToNumber(tx) + assert.strictEqual(result, expected) + }) + + it('converts PaymentChannelClaimFlags to its numeric value', function () { + const tx: PaymentChannelClaim = { + Account: 'r...', + TransactionType: 'PaymentChannelClaim', + Channel: + 'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198', + Flags: { + tfRenew: true, + tfClose: false, + }, + } + + const { tfRenew } = PaymentChannelClaimFlags + const expected: number = tfRenew + + const result = convertTxFlagsToNumber(tx) + assert.strictEqual(result, expected) + }) + + it('converts PaymentTransactionFlags to its numeric value', function () { + const tx: Payment = { + TransactionType: 'Payment', + Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', + Amount: '1234', + Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy', + Flags: { + tfNoRippleDirect: false, + tfPartialPayment: true, + tfLimitQuality: true, + }, + } + + const { tfPartialPayment, tfLimitQuality } = PaymentFlags + const expected: number = tfPartialPayment | tfLimitQuality + + const result = convertTxFlagsToNumber(tx) + assert.strictEqual(result, expected) + }) + + it('converts TrustSetFlags to its numeric value', function () { + const tx: TrustSet = { + TransactionType: 'TrustSet', + Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', + LimitAmount: { + currency: 'XRP', + issuer: 'rcXY84C4g14iFp6taFXjjQGVeHqSCh9RX', + value: '4329.23', + }, + QualityIn: 1234, + QualityOut: 4321, + Flags: { + tfSetfAuth: true, + tfSetNoRipple: false, + tfClearNoRipple: true, + tfSetFreeze: false, + tfClearFreeze: true, + }, + } + + const { tfSetfAuth, tfClearNoRipple, tfClearFreeze } = TrustSetFlags + const expected: number = tfSetfAuth | tfClearNoRipple | tfClearFreeze + + const result = convertTxFlagsToNumber(tx) + assert.strictEqual(result, expected) + }) + + it('converts other transaction types flags to its numeric value', function () { + const tx: DepositPreauth = { + TransactionType: 'DepositPreauth', + Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', + Flags: {}, + } + + const result = convertTxFlagsToNumber(tx) + assert.strictEqual(result, 0) + }) + }) }) From 89375a1a741eef4bf701feb06fd59c35ceae4b8a Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Fri, 3 Jan 2025 11:41:22 -0500 Subject: [PATCH 15/30] remove outdated logic --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index 25375431b2..31eab83bc8 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -105,7 +105,7 @@ export function convertTxFlagsToNumber(tx: Transaction): number { ) } - return tx.Flags?.[flag] ? resultFlags | flagEnum[flag] : resultFlags + return resultFlags | flagEnum[flag] }, 0) } From 30431b0b35e889eba57938bed664a68fcbc535e7 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Fri, 3 Jan 2025 11:45:45 -0500 Subject: [PATCH 16/30] fix history md --- packages/xrpl/HISTORY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 7f9434c4c3..75042f3ce5 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -5,7 +5,6 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ## Unreleased ### Added -* `parseTransactionFlags` as a utility function in the xrpl package to streamline transactions flags-to-map conversion * `convertTxFlagsToNumber` as a utility function in xrpl to return the number conversion of a transaction's flags ### Fixed From 583413fc0fc40ef4b1e750b7a8d698155ffe1828 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Fri, 3 Jan 2025 12:11:26 -0500 Subject: [PATCH 17/30] fix tests after merge conflicts --- packages/xrpl/src/models/utils/flags.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index bbbe43c60c..ac0ce0e682 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -7,7 +7,6 @@ import { import { AccountSetTfFlags } from '../transactions/accountSet' import { AMMDepositFlags } from '../transactions/AMMDeposit' import { AMMWithdrawFlags } from '../transactions/AMMWithdraw' -import { GlobalFlags } from '../transactions/common' import { MPTokenAuthorizeFlags } from '../transactions/MPTokenAuthorize' import { MPTokenIssuanceCreateFlags } from '../transactions/MPTokenIssuanceCreate' import { MPTokenIssuanceSetFlags } from '../transactions/MPTokenIssuanceSet' @@ -112,7 +111,7 @@ export function convertTxFlagsToNumber(tx: Transaction): number { ) } - return resultFlags | flagEnum[flag] + return tx.Flags?.[flag] ? resultFlags | flagEnum[flag] : resultFlags }, 0) } From 517a034e3142d04dcd3e79d0db63cba5ca1df260 Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:28:45 -0500 Subject: [PATCH 18/30] Update packages/xrpl/HISTORY.md Co-authored-by: Omar Khan --- packages/xrpl/HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 18a4024ce8..db958dab05 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -5,7 +5,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ## Unreleased ### Added -* `convertTxFlagsToNumber` as a utility function in xrpl to return the number conversion of a transaction's flags +* Adds utility function `convertTxFlagsToNumber` ### Changed * Deprecated `setTransactionFlagsToNumber`. Start using convertTxFlagsToNumber instead From 86138cc3bc94cda2643e04a22a980ae083d1310f Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:29:25 -0500 Subject: [PATCH 19/30] Update packages/xrpl/src/models/utils/flags.ts Co-authored-by: Omar Khan --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index ac0ce0e682..b0780bcc51 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -61,7 +61,7 @@ const txToFlag = { XChainModifyBridge: XChainModifyBridgeFlags, } -function istxToFlagKey( +function isTxToFlagKey( transactionType: string, ): transactionType is keyof typeof txToFlag { return transactionType in txToFlag From fc3a79f5ce21b75c853a1d6768710876fc7ee4d6 Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:29:48 -0500 Subject: [PATCH 20/30] Update packages/xrpl/src/models/utils/flags.ts Co-authored-by: Omar Khan --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index b0780bcc51..d38aa0ec56 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -72,7 +72,7 @@ function isTxToFlagKey( * * @deprecated * This utility function is deprecated. - * Use convertTxFlagsToNumber() instead and use the returned value to modify the tx.Flags from the caller. + * Use convertTxFlagsToNumber() instead and use the returned value to modify the Transaction.Flags from the caller. * * @param tx - A transaction to set its flags to its numeric representation. */ From 128dc2073290deede1fca367368705a9b52ee336 Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:30:45 -0500 Subject: [PATCH 21/30] Update packages/xrpl/src/models/utils/flags.ts Co-authored-by: Omar Khan --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index d38aa0ec56..a7b38b7d16 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -79,7 +79,7 @@ function isTxToFlagKey( export function setTransactionFlagsToNumber(tx: Transaction): void { // eslint-disable-next-line no-console -- intended deprecation warning console.warn( - 'This function is deprecated. Use convertTxFlagsToNumber() instead and use the returned value to modify the tx.Flags from the caller.', + 'This function is deprecated. Use convertTxFlagsToNumber() instead and use the returned value to modify the Transaction.Flags from the caller.', ) if (tx.Flags) { From 904c5e05fbc6b9240633708463d2ceb3d9578ef5 Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:31:08 -0500 Subject: [PATCH 22/30] Update packages/xrpl/src/models/utils/flags.ts Co-authored-by: Omar Khan --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index a7b38b7d16..7bc6d2bd74 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -89,7 +89,7 @@ export function setTransactionFlagsToNumber(tx: Transaction): void { } /** - * Returns a transaction's flags as its numeric representation. + * Returns a Transaction's Flags as its numeric representation. * * @param tx - A transaction to parse flags for * @returns A numerical representation of a transaction's flags From 642d313b3010b61963f6da686ca21a10c54d43d2 Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:31:15 -0500 Subject: [PATCH 23/30] Update packages/xrpl/src/models/utils/flags.ts Co-authored-by: Omar Khan --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index 7bc6d2bd74..df76bcab2e 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -91,7 +91,7 @@ export function setTransactionFlagsToNumber(tx: Transaction): void { /** * Returns a Transaction's Flags as its numeric representation. * - * @param tx - A transaction to parse flags for + * @param tx - A Transaction to parse Flags for * @returns A numerical representation of a transaction's flags */ export function convertTxFlagsToNumber(tx: Transaction): number { From 37b99afe58ec53c48904e697452d64bc138d655d Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:31:20 -0500 Subject: [PATCH 24/30] Update packages/xrpl/src/models/utils/flags.ts Co-authored-by: Omar Khan --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index df76bcab2e..0f11be39ea 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -92,7 +92,7 @@ export function setTransactionFlagsToNumber(tx: Transaction): void { * Returns a Transaction's Flags as its numeric representation. * * @param tx - A Transaction to parse Flags for - * @returns A numerical representation of a transaction's flags + * @returns A numerical representation of a Transaction's Flags */ export function convertTxFlagsToNumber(tx: Transaction): number { if (!tx.Flags) { From e501f0cb83ea74311366b00e34211bc5b1ead396 Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:31:32 -0500 Subject: [PATCH 25/30] Update packages/xrpl/src/models/utils/flags.ts Co-authored-by: Omar Khan --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index 0f11be39ea..776a427e8c 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -102,7 +102,7 @@ export function convertTxFlagsToNumber(tx: Transaction): number { return tx.Flags } - if (istxToFlagKey(tx.TransactionType)) { + if (isTxToFlagKey(tx.TransactionType)) { const flagEnum = txToFlag[tx.TransactionType] return Object.keys(tx.Flags).reduce((resultFlags, flag) => { if (flagEnum[flag] == null) { From dad7c2924700f2a21e519ae9f1f2716453d3cd17 Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:32:14 -0500 Subject: [PATCH 26/30] Update packages/xrpl/src/models/utils/flags.ts Co-authored-by: Omar Khan --- packages/xrpl/src/models/utils/flags.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index 776a427e8c..c0518d3990 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -107,7 +107,7 @@ export function convertTxFlagsToNumber(tx: Transaction): number { return Object.keys(tx.Flags).reduce((resultFlags, flag) => { if (flagEnum[flag] == null) { throw new ValidationError( - `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`, + Invalid flag ${flag}. Valid flags are ${JSON.stringify(flagEnum)}`, ) } From 5a77c628608daa947f6f25ef047ed675715e7a67 Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:36:07 -0500 Subject: [PATCH 27/30] Update packages/xrpl/test/models/utils.test.ts Co-authored-by: Omar Khan --- packages/xrpl/test/models/utils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index ea2cfb99fa..5284c924d2 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -50,7 +50,7 @@ describe('Models Utils', function () { describe('parseAccountRootFlags', function () { // eslint-disable-next-line complexity -- Simpler to list them all out at once. - it('parseAccountRootFlags all enabled', function () { + it('all flags enabled', function () { const accountRootFlags = AccountRootFlags.lsfDefaultRipple | AccountRootFlags.lsfDepositAuth | From 127e2169a512a0afce725a5addee54766c7c2cb5 Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Thu, 16 Jan 2025 11:49:50 -0500 Subject: [PATCH 28/30] rename a test per pr comment --- packages/xrpl/test/models/utils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index 5284c924d2..931f556e7d 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -87,7 +87,7 @@ describe('Models Utils', function () { ) }) - it('parseAccountFlags all false', function () { + it('all flags not set', function () { const parsed = parseAccountRootFlags(0) assert.isUndefined(parsed.lsfDefaultRipple) From fb67a1082911c0af689ce4709157c21b8ef1ffac Mon Sep 17 00:00:00 2001 From: Ashray Chowdhry Date: Thu, 16 Jan 2025 11:54:55 -0500 Subject: [PATCH 29/30] lint fixes --- packages/xrpl/src/models/utils/flags.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/utils/flags.ts b/packages/xrpl/src/models/utils/flags.ts index c0518d3990..c2a88662a7 100644 --- a/packages/xrpl/src/models/utils/flags.ts +++ b/packages/xrpl/src/models/utils/flags.ts @@ -107,7 +107,7 @@ export function convertTxFlagsToNumber(tx: Transaction): number { return Object.keys(tx.Flags).reduce((resultFlags, flag) => { if (flagEnum[flag] == null) { throw new ValidationError( - Invalid flag ${flag}. Valid flags are ${JSON.stringify(flagEnum)}`, + `Invalid flag ${flag}. Valid flags are ${JSON.stringify(flagEnum)}`, ) } @@ -132,7 +132,7 @@ export function parseTransactionFlags(tx: Transaction): object { const booleanFlagMap = {} - if (istxToFlagKey(tx.TransactionType)) { + if (isTxToFlagKey(tx.TransactionType)) { const transactionTypeFlags = txToFlag[tx.TransactionType] Object.values(transactionTypeFlags).forEach((flag) => { if ( From eb98875396c6933293f7e46c32fe7a81b8b70f9c Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 16 Jan 2025 11:55:12 -0500 Subject: [PATCH 30/30] Update packages/xrpl/test/models/utils.test.ts Co-authored-by: Omar Khan --- packages/xrpl/test/models/utils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index 931f556e7d..88d9286a0a 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -87,7 +87,7 @@ describe('Models Utils', function () { ) }) - it('all flags not set', function () { + it('no flags set', function () { const parsed = parseAccountRootFlags(0) assert.isUndefined(parsed.lsfDefaultRipple)