mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-01 01:25:48 +00:00
refactor: reorganize/rename flags interfaces (#1700)
* refactor: reorganize/rename flags interfaces
This commit is contained in:
@@ -9,7 +9,7 @@ import type {
|
||||
TxResponse,
|
||||
} from '..'
|
||||
import type { Amount } from '../models/common'
|
||||
import { PaymentTransactionFlags, Transaction } from '../models/transactions'
|
||||
import { PaymentFlags, Transaction } from '../models/transactions'
|
||||
import type TransactionMetadata from '../models/transactions/metadata'
|
||||
import { isFlagEnabled } from '../models/utils'
|
||||
|
||||
@@ -54,7 +54,7 @@ function isPartialPayment(
|
||||
|
||||
const tfPartial =
|
||||
typeof tx.Flags === 'number'
|
||||
? isFlagEnabled(tx.Flags, PaymentTransactionFlags.tfPartialPayment)
|
||||
? isFlagEnabled(tx.Flags, PaymentFlags.tfPartialPayment)
|
||||
: tx.Flags?.tfPartialPayment
|
||||
|
||||
if (!tfPartial) {
|
||||
|
||||
@@ -19,7 +19,7 @@ export default interface AccountRoot extends BaseLedgerEntry {
|
||||
TransferRate?: number
|
||||
}
|
||||
|
||||
export enum AccountRootLedgerFlags {
|
||||
export enum AccountRootFlags {
|
||||
lsfPasswordSpent = 0x00010000,
|
||||
lsfRequireDestTag = 0x00020000,
|
||||
lsfRequireAuth = 0x00040000,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable import/no-unused-modules -- Needs to export all ledger objects */
|
||||
import AccountRoot, { AccountRootLedgerFlags } from './accountRoot'
|
||||
import AccountRoot, { AccountRootFlags } from './accountRoot'
|
||||
import Amendments from './amendments'
|
||||
import Check from './check'
|
||||
import DepositPreauth from './depositPreauth'
|
||||
@@ -10,15 +10,15 @@ import Ledger from './ledger'
|
||||
import LedgerEntry from './ledgerEntry'
|
||||
import LedgerHashes from './ledgerHashes'
|
||||
import NegativeUNL from './negativeUNL'
|
||||
import Offer, { OfferLedgerFlags } from './offer'
|
||||
import Offer, { OfferFlags } from './offer'
|
||||
import PayChannel from './payChannel'
|
||||
import RippleState, { RippleStateLedgerFlags } from './rippleState'
|
||||
import SignerList, { SignerListLedgerFlags } from './signerList'
|
||||
import RippleState, { RippleStateFlags } from './rippleState'
|
||||
import SignerList, { SignerListFlags } from './signerList'
|
||||
import Ticket from './ticket'
|
||||
|
||||
export {
|
||||
AccountRoot,
|
||||
AccountRootLedgerFlags,
|
||||
AccountRootFlags,
|
||||
Amendments,
|
||||
Check,
|
||||
DepositPreauth,
|
||||
@@ -30,11 +30,11 @@ export {
|
||||
LedgerHashes,
|
||||
NegativeUNL,
|
||||
Offer,
|
||||
OfferLedgerFlags,
|
||||
OfferFlags,
|
||||
PayChannel,
|
||||
RippleState,
|
||||
RippleStateLedgerFlags,
|
||||
RippleStateFlags,
|
||||
SignerList,
|
||||
SignerListLedgerFlags,
|
||||
SignerListFlags,
|
||||
Ticket,
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export default interface Offer extends BaseLedgerEntry {
|
||||
Expiration?: number
|
||||
}
|
||||
|
||||
export enum OfferLedgerFlags {
|
||||
export enum OfferFlags {
|
||||
lsfPassive = 0x00010000,
|
||||
lsfSell = 0x00020000,
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export default interface RippleState extends BaseLedgerEntry {
|
||||
HighQualityOut?: number
|
||||
}
|
||||
|
||||
export enum RippleStateLedgerFlags {
|
||||
export enum RippleStateFlags {
|
||||
// True, if entry counts toward reserve.
|
||||
lsfLowReserve = 0x00010000,
|
||||
lsfHighReserve = 0x00020000,
|
||||
|
||||
@@ -18,7 +18,7 @@ export default interface SignerList extends BaseLedgerEntry {
|
||||
SignerQuorum: number
|
||||
}
|
||||
|
||||
export enum SignerListLedgerFlags {
|
||||
export enum SignerListFlags {
|
||||
// True, uses only one OwnerCount
|
||||
lsfOneOwnerCount = 0x00010000,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ValidationError } from '../../errors'
|
||||
|
||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||
|
||||
export enum AccountSetFlags {
|
||||
export enum AccountSetAsfFlags {
|
||||
asfRequireDest = 1,
|
||||
asfRequireAuth = 2,
|
||||
asfDisallowXRP = 3,
|
||||
@@ -15,7 +15,7 @@ export enum AccountSetFlags {
|
||||
asfDepositAuth = 9,
|
||||
}
|
||||
|
||||
export enum AccountSetTransactionFlags {
|
||||
export enum AccountSetTfFlags {
|
||||
tfRequireDestTag = 0x00010000,
|
||||
tfOptionalDestTag = 0x00020000,
|
||||
tfRequireAuth = 0x00040000,
|
||||
@@ -40,7 +40,7 @@ export interface AccountSet extends BaseTransaction {
|
||||
Domain?: string
|
||||
EmailHash?: string
|
||||
MessageKey?: string
|
||||
SetFlag?: AccountSetFlags
|
||||
SetFlag?: AccountSetAsfFlags
|
||||
TransferRate?: number
|
||||
TickSize?: number
|
||||
}
|
||||
@@ -62,7 +62,7 @@ export function validateAccountSet(tx: Record<string, unknown>): void {
|
||||
if (typeof tx.ClearFlag !== 'number') {
|
||||
throw new ValidationError('AccountSet: invalid ClearFlag')
|
||||
}
|
||||
if (!Object.values(AccountSetFlags).includes(tx.ClearFlag)) {
|
||||
if (!Object.values(AccountSetAsfFlags).includes(tx.ClearFlag)) {
|
||||
throw new ValidationError('AccountSet: invalid ClearFlag')
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ export function validateAccountSet(tx: Record<string, unknown>): void {
|
||||
if (typeof tx.SetFlag !== 'number') {
|
||||
throw new ValidationError('AccountSet: invalid SetFlag')
|
||||
}
|
||||
if (!Object.values(AccountSetFlags).includes(tx.SetFlag)) {
|
||||
if (!Object.values(AccountSetAsfFlags).includes(tx.SetFlag)) {
|
||||
throw new ValidationError('AccountSet: invalid SetFlag')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
isAmount,
|
||||
} from './common'
|
||||
|
||||
export enum OfferCreateTransactionFlags {
|
||||
export enum OfferCreateFlags {
|
||||
tfPassive = 0x00010000,
|
||||
tfImmediateOrCancel = 0x00020000,
|
||||
tfFillOrKill = 0x00040000,
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
validateBaseTransaction,
|
||||
} from './common'
|
||||
|
||||
export enum PaymentTransactionFlags {
|
||||
export enum PaymentFlags {
|
||||
tfNoDirectRipple = 0x00010000,
|
||||
tfPartialPayment = 0x00020000,
|
||||
tfLimitQuality = 0x00040000,
|
||||
@@ -95,7 +95,7 @@ function checkPartialPayment(tx: Record<string, unknown>): void {
|
||||
const flags = tx.Flags as number | PaymentFlagsInterface
|
||||
const isTfPartialPayment =
|
||||
typeof flags === 'number'
|
||||
? isFlagEnabled(flags, PaymentTransactionFlags.tfPartialPayment)
|
||||
? isFlagEnabled(flags, PaymentFlags.tfPartialPayment)
|
||||
: flags.tfPartialPayment ?? false
|
||||
|
||||
if (!isTfPartialPayment) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ValidationError } from '../../errors'
|
||||
|
||||
import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
|
||||
|
||||
export enum PaymentChannelClaimTransactionFlags {
|
||||
export enum PaymentChannelClaimFlags {
|
||||
tfRenew = 0x00010000,
|
||||
tfClose = 0x00020000,
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import { AccountDelete, validateAccountDelete } from './accountDelete'
|
||||
import {
|
||||
AccountSet,
|
||||
validateAccountSet,
|
||||
AccountSetFlags,
|
||||
AccountSetTransactionFlags,
|
||||
AccountSetAsfFlags,
|
||||
AccountSetTfFlags,
|
||||
} from './accountSet'
|
||||
import { CheckCancel, validateCheckCancel } from './checkCancel'
|
||||
import { CheckCash, validateCheckCash } from './checkCash'
|
||||
@@ -26,13 +26,13 @@ import { OfferCancel, validateOfferCancel } from './offerCancel'
|
||||
import {
|
||||
OfferCreate,
|
||||
validateOfferCreate,
|
||||
OfferCreateTransactionFlags,
|
||||
OfferCreateFlags,
|
||||
} from './offerCreate'
|
||||
import { Payment, validatePayment, PaymentTransactionFlags } from './payment'
|
||||
import { Payment, validatePayment, PaymentFlags } from './payment'
|
||||
import {
|
||||
PaymentChannelClaim,
|
||||
validatePaymentChannelClaim,
|
||||
PaymentChannelClaimTransactionFlags,
|
||||
PaymentChannelClaimFlags,
|
||||
} from './paymentChannelClaim'
|
||||
import {
|
||||
PaymentChannelCreate,
|
||||
@@ -45,11 +45,7 @@ import {
|
||||
import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
|
||||
import { SignerListSet, validateSignerListSet } from './signerListSet'
|
||||
import { TicketCreate, validateTicketCreate } from './ticketCreate'
|
||||
import {
|
||||
TrustSet,
|
||||
validateTrustSet,
|
||||
TrustSetTransactionFlags,
|
||||
} from './trustSet'
|
||||
import { TrustSet, validateTrustSet, TrustSetFlags } from './trustSet'
|
||||
|
||||
export type Transaction =
|
||||
| AccountDelete
|
||||
@@ -188,10 +184,10 @@ export function validate(transaction: Record<string, unknown>): void {
|
||||
}
|
||||
|
||||
export {
|
||||
AccountSetFlags,
|
||||
AccountSetTransactionFlags,
|
||||
OfferCreateTransactionFlags,
|
||||
PaymentTransactionFlags,
|
||||
PaymentChannelClaimTransactionFlags,
|
||||
TrustSetTransactionFlags,
|
||||
AccountSetAsfFlags,
|
||||
AccountSetTfFlags,
|
||||
OfferCreateFlags,
|
||||
PaymentFlags,
|
||||
PaymentChannelClaimFlags,
|
||||
TrustSetFlags,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
validateBaseTransaction,
|
||||
} from './common'
|
||||
|
||||
export enum TrustSetTransactionFlags {
|
||||
export enum TrustSetFlags {
|
||||
tfSetfAuth = 0x00010000,
|
||||
tfSetNoRipple = 0x00020000,
|
||||
tfClearNoRipple = 0x00040000,
|
||||
|
||||
@@ -4,26 +4,20 @@
|
||||
import { ValidationError } from '../../errors'
|
||||
import {
|
||||
AccountSetFlagsInterface,
|
||||
AccountSetTransactionFlags,
|
||||
AccountSetTfFlags,
|
||||
} from '../transactions/accountSet'
|
||||
import { GlobalFlags } from '../transactions/common'
|
||||
import {
|
||||
OfferCreateFlagsInterface,
|
||||
OfferCreateTransactionFlags,
|
||||
OfferCreateFlags,
|
||||
} from '../transactions/offerCreate'
|
||||
import {
|
||||
PaymentFlagsInterface,
|
||||
PaymentTransactionFlags,
|
||||
} from '../transactions/payment'
|
||||
import { PaymentFlagsInterface, PaymentFlags } from '../transactions/payment'
|
||||
import {
|
||||
PaymentChannelClaimFlagsInterface,
|
||||
PaymentChannelClaimTransactionFlags,
|
||||
PaymentChannelClaimFlags,
|
||||
} from '../transactions/paymentChannelClaim'
|
||||
import type { Transaction } from '../transactions/transaction'
|
||||
import {
|
||||
TrustSetFlagsInterface,
|
||||
TrustSetTransactionFlags,
|
||||
} from '../transactions/trustSet'
|
||||
import { TrustSetFlagsInterface, TrustSetFlags } from '../transactions/trustSet'
|
||||
|
||||
/**
|
||||
* Sets a transaction's flags to its numeric representation.
|
||||
@@ -63,29 +57,29 @@ export default function setTransactionFlagsToNumber(tx: Transaction): void {
|
||||
function convertAccountSetFlagsToNumber(
|
||||
flags: AccountSetFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, AccountSetTransactionFlags)
|
||||
return reduceFlags(flags, AccountSetTfFlags)
|
||||
}
|
||||
|
||||
function convertOfferCreateFlagsToNumber(
|
||||
flags: OfferCreateFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, OfferCreateTransactionFlags)
|
||||
return reduceFlags(flags, OfferCreateFlags)
|
||||
}
|
||||
|
||||
function convertPaymentChannelClaimFlagsToNumber(
|
||||
flags: PaymentChannelClaimFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, PaymentChannelClaimTransactionFlags)
|
||||
return reduceFlags(flags, PaymentChannelClaimFlags)
|
||||
}
|
||||
|
||||
function convertPaymentTransactionFlagsToNumber(
|
||||
flags: PaymentFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, PaymentTransactionFlags)
|
||||
return reduceFlags(flags, PaymentFlags)
|
||||
}
|
||||
|
||||
function convertTrustSetFlagsToNumber(flags: TrustSetFlagsInterface): number {
|
||||
return reduceFlags(flags, TrustSetTransactionFlags)
|
||||
return reduceFlags(flags, TrustSetFlags)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum
|
||||
|
||||
@@ -4,7 +4,7 @@ import _ from 'lodash'
|
||||
|
||||
import type { Client } from '../client'
|
||||
import { LedgerIndex } from '../models/common'
|
||||
import { OfferLedgerFlags } from '../models/ledger/offer'
|
||||
import { OfferFlags } from '../models/ledger/offer'
|
||||
import {
|
||||
BookOffer,
|
||||
BookOffersRequest,
|
||||
@@ -80,7 +80,7 @@ async function getOrderbook(
|
||||
const sell: BookOffer[] = []
|
||||
orders.forEach((order) => {
|
||||
// eslint-disable-next-line no-bitwise -- necessary for flags check
|
||||
if ((order.Flags & OfferLedgerFlags.lsfSell) === 0) {
|
||||
if ((order.Flags & OfferFlags.lsfSell) === 0) {
|
||||
buy.push(order)
|
||||
} else {
|
||||
sell.push(order)
|
||||
|
||||
@@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js'
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { BookOffersRequest, ValidationError } from '../../src'
|
||||
import { OfferLedgerFlags } from '../../src/models/ledger/offer'
|
||||
import { OfferFlags } from '../../src/models/ledger/offer'
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
@@ -169,11 +169,11 @@ describe('client.getOrderbook', function () {
|
||||
requests.getOrderbook.normal.takerGets,
|
||||
)
|
||||
assert.strictEqual(
|
||||
response.buy.every((item) => item.Flags !== OfferLedgerFlags.lsfSell),
|
||||
response.buy.every((item) => item.Flags !== OfferFlags.lsfSell),
|
||||
true,
|
||||
)
|
||||
assert.strictEqual(
|
||||
response.sell.every((item) => item.Flags === OfferLedgerFlags.lsfSell),
|
||||
response.sell.every((item) => item.Flags === OfferFlags.lsfSell),
|
||||
true,
|
||||
)
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ import { assert } from 'chai'
|
||||
import {
|
||||
validatePayment,
|
||||
validate,
|
||||
PaymentTransactionFlags,
|
||||
PaymentFlags,
|
||||
ValidationError,
|
||||
} from 'xrpl-local'
|
||||
|
||||
@@ -158,7 +158,7 @@ describe('Payment', function () {
|
||||
|
||||
it(`verifies valid DeliverMin with tfPartialPayment flag set as a number`, function () {
|
||||
paymentTransaction.DeliverMin = '10000'
|
||||
paymentTransaction.Flags = PaymentTransactionFlags.tfPartialPayment
|
||||
paymentTransaction.Flags = PaymentFlags.tfPartialPayment
|
||||
assert.doesNotThrow(() => validatePayment(paymentTransaction))
|
||||
assert.doesNotThrow(() => validate(paymentTransaction))
|
||||
})
|
||||
|
||||
@@ -4,13 +4,13 @@ import { assert } from 'chai'
|
||||
import {
|
||||
DepositPreauth,
|
||||
OfferCreate,
|
||||
OfferCreateTransactionFlags,
|
||||
OfferCreateFlags,
|
||||
PaymentChannelClaim,
|
||||
PaymentChannelClaimTransactionFlags,
|
||||
PaymentChannelClaimFlags,
|
||||
Payment,
|
||||
PaymentTransactionFlags,
|
||||
PaymentFlags,
|
||||
TrustSet,
|
||||
TrustSetTransactionFlags,
|
||||
TrustSetFlags,
|
||||
} from 'xrpl-local'
|
||||
import { isFlagEnabled } from 'xrpl-local/models/utils'
|
||||
import setTransactionFlagsToNumber from 'xrpl-local/models/utils/flags'
|
||||
@@ -63,7 +63,7 @@ describe('Models Utils', function () {
|
||||
},
|
||||
}
|
||||
|
||||
const { tfPassive, tfFillOrKill } = OfferCreateTransactionFlags
|
||||
const { tfPassive, tfFillOrKill } = OfferCreateFlags
|
||||
const expected: number = tfPassive | tfFillOrKill
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
@@ -82,7 +82,7 @@ describe('Models Utils', function () {
|
||||
},
|
||||
}
|
||||
|
||||
const { tfRenew } = PaymentChannelClaimTransactionFlags
|
||||
const { tfRenew } = PaymentChannelClaimFlags
|
||||
const expected: number = tfRenew
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
@@ -102,7 +102,7 @@ describe('Models Utils', function () {
|
||||
},
|
||||
}
|
||||
|
||||
const { tfPartialPayment, tfLimitQuality } = PaymentTransactionFlags
|
||||
const { tfPartialPayment, tfLimitQuality } = PaymentFlags
|
||||
const expected: number = tfPartialPayment | tfLimitQuality
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
@@ -129,8 +129,7 @@ describe('Models Utils', function () {
|
||||
},
|
||||
}
|
||||
|
||||
const { tfSetfAuth, tfClearNoRipple, tfClearFreeze } =
|
||||
TrustSetTransactionFlags
|
||||
const { tfSetfAuth, tfClearNoRipple, tfClearFreeze } = TrustSetFlags
|
||||
const expected: number = tfSetfAuth | tfClearNoRipple | tfClearFreeze
|
||||
|
||||
setTransactionFlagsToNumber(tx)
|
||||
|
||||
Reference in New Issue
Block a user