mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
refactor: convert flags to number
This commit is contained in:
@@ -6,30 +6,15 @@ import {
|
||||
AccountRootFlagsInterface,
|
||||
AccountRootFlags,
|
||||
} from '../ledger/AccountRoot'
|
||||
import {
|
||||
AccountSetFlagsInterface,
|
||||
AccountSetTfFlags,
|
||||
} from '../transactions/accountSet'
|
||||
import {
|
||||
AMMDepositFlags,
|
||||
AMMDepositFlagsInterface,
|
||||
} from '../transactions/AMMDeposit'
|
||||
import {
|
||||
AMMWithdrawFlags,
|
||||
AMMWithdrawFlagsInterface,
|
||||
} from '../transactions/AMMWithdraw'
|
||||
import { AccountSetTfFlags } from '../transactions/accountSet'
|
||||
import { AMMDepositFlags } from '../transactions/AMMDeposit'
|
||||
import { AMMWithdrawFlags } from '../transactions/AMMWithdraw'
|
||||
import { GlobalFlags } from '../transactions/common'
|
||||
import {
|
||||
OfferCreateFlagsInterface,
|
||||
OfferCreateFlags,
|
||||
} from '../transactions/offerCreate'
|
||||
import { PaymentFlagsInterface, PaymentFlags } from '../transactions/payment'
|
||||
import {
|
||||
PaymentChannelClaimFlagsInterface,
|
||||
PaymentChannelClaimFlags,
|
||||
} from '../transactions/paymentChannelClaim'
|
||||
import { OfferCreateFlags } from '../transactions/offerCreate'
|
||||
import { PaymentFlags } from '../transactions/payment'
|
||||
import { PaymentChannelClaimFlags } from '../transactions/paymentChannelClaim'
|
||||
import type { Transaction } from '../transactions/transaction'
|
||||
import { TrustSetFlagsInterface, TrustSetFlags } from '../transactions/trustSet'
|
||||
import { TrustSetFlags } from '../transactions/trustSet'
|
||||
|
||||
import { isFlagEnabled } from '.'
|
||||
|
||||
@@ -69,73 +54,33 @@ export function setTransactionFlagsToNumber(tx: Transaction): void {
|
||||
|
||||
switch (tx.TransactionType) {
|
||||
case 'AccountSet':
|
||||
tx.Flags = convertAccountSetFlagsToNumber(tx.Flags)
|
||||
tx.Flags = convertFlagsToNumber(tx.Flags, AccountSetTfFlags)
|
||||
return
|
||||
case 'AMMDeposit':
|
||||
tx.Flags = convertAMMDepositFlagsToNumber(tx.Flags)
|
||||
tx.Flags = convertFlagsToNumber(tx.Flags, AMMDepositFlags)
|
||||
return
|
||||
case 'AMMWithdraw':
|
||||
tx.Flags = convertAMMWithdrawFlagsToNumber(tx.Flags)
|
||||
tx.Flags = convertFlagsToNumber(tx.Flags, AMMWithdrawFlags)
|
||||
return
|
||||
case 'OfferCreate':
|
||||
tx.Flags = convertOfferCreateFlagsToNumber(tx.Flags)
|
||||
tx.Flags = convertFlagsToNumber(tx.Flags, OfferCreateFlags)
|
||||
return
|
||||
case 'PaymentChannelClaim':
|
||||
tx.Flags = convertPaymentChannelClaimFlagsToNumber(tx.Flags)
|
||||
tx.Flags = convertFlagsToNumber(tx.Flags, PaymentChannelClaimFlags)
|
||||
return
|
||||
case 'Payment':
|
||||
tx.Flags = convertPaymentTransactionFlagsToNumber(tx.Flags)
|
||||
tx.Flags = convertFlagsToNumber(tx.Flags, PaymentFlags)
|
||||
return
|
||||
case 'TrustSet':
|
||||
tx.Flags = convertTrustSetFlagsToNumber(tx.Flags)
|
||||
tx.Flags = convertFlagsToNumber(tx.Flags, TrustSetFlags)
|
||||
return
|
||||
default:
|
||||
tx.Flags = 0
|
||||
}
|
||||
}
|
||||
|
||||
function convertAccountSetFlagsToNumber(
|
||||
flags: AccountSetFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, AccountSetTfFlags)
|
||||
}
|
||||
|
||||
function convertAMMDepositFlagsToNumber(
|
||||
flags: AMMDepositFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, AMMDepositFlags)
|
||||
}
|
||||
|
||||
function convertAMMWithdrawFlagsToNumber(
|
||||
flags: AMMWithdrawFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, AMMWithdrawFlags)
|
||||
}
|
||||
|
||||
function convertOfferCreateFlagsToNumber(
|
||||
flags: OfferCreateFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, OfferCreateFlags)
|
||||
}
|
||||
|
||||
function convertPaymentChannelClaimFlagsToNumber(
|
||||
flags: PaymentChannelClaimFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, PaymentChannelClaimFlags)
|
||||
}
|
||||
|
||||
function convertPaymentTransactionFlagsToNumber(
|
||||
flags: PaymentFlagsInterface,
|
||||
): number {
|
||||
return reduceFlags(flags, PaymentFlags)
|
||||
}
|
||||
|
||||
function convertTrustSetFlagsToNumber(flags: TrustSetFlagsInterface): number {
|
||||
return reduceFlags(flags, TrustSetFlags)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum
|
||||
function reduceFlags(flags: GlobalFlags, flagEnum: any): number {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user