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,
|
AccountRootFlagsInterface,
|
||||||
AccountRootFlags,
|
AccountRootFlags,
|
||||||
} from '../ledger/AccountRoot'
|
} from '../ledger/AccountRoot'
|
||||||
import {
|
import { AccountSetTfFlags } from '../transactions/accountSet'
|
||||||
AccountSetFlagsInterface,
|
import { AMMDepositFlags } from '../transactions/AMMDeposit'
|
||||||
AccountSetTfFlags,
|
import { AMMWithdrawFlags } from '../transactions/AMMWithdraw'
|
||||||
} from '../transactions/accountSet'
|
|
||||||
import {
|
|
||||||
AMMDepositFlags,
|
|
||||||
AMMDepositFlagsInterface,
|
|
||||||
} from '../transactions/AMMDeposit'
|
|
||||||
import {
|
|
||||||
AMMWithdrawFlags,
|
|
||||||
AMMWithdrawFlagsInterface,
|
|
||||||
} from '../transactions/AMMWithdraw'
|
|
||||||
import { GlobalFlags } from '../transactions/common'
|
import { GlobalFlags } from '../transactions/common'
|
||||||
import {
|
import { OfferCreateFlags } from '../transactions/offerCreate'
|
||||||
OfferCreateFlagsInterface,
|
import { PaymentFlags } from '../transactions/payment'
|
||||||
OfferCreateFlags,
|
import { PaymentChannelClaimFlags } from '../transactions/paymentChannelClaim'
|
||||||
} from '../transactions/offerCreate'
|
|
||||||
import { PaymentFlagsInterface, PaymentFlags } from '../transactions/payment'
|
|
||||||
import {
|
|
||||||
PaymentChannelClaimFlagsInterface,
|
|
||||||
PaymentChannelClaimFlags,
|
|
||||||
} from '../transactions/paymentChannelClaim'
|
|
||||||
import type { Transaction } from '../transactions/transaction'
|
import type { Transaction } from '../transactions/transaction'
|
||||||
import { TrustSetFlagsInterface, TrustSetFlags } from '../transactions/trustSet'
|
import { TrustSetFlags } from '../transactions/trustSet'
|
||||||
|
|
||||||
import { isFlagEnabled } from '.'
|
import { isFlagEnabled } from '.'
|
||||||
|
|
||||||
@@ -69,73 +54,33 @@ export function setTransactionFlagsToNumber(tx: Transaction): void {
|
|||||||
|
|
||||||
switch (tx.TransactionType) {
|
switch (tx.TransactionType) {
|
||||||
case 'AccountSet':
|
case 'AccountSet':
|
||||||
tx.Flags = convertAccountSetFlagsToNumber(tx.Flags)
|
tx.Flags = convertFlagsToNumber(tx.Flags, AccountSetTfFlags)
|
||||||
return
|
return
|
||||||
case 'AMMDeposit':
|
case 'AMMDeposit':
|
||||||
tx.Flags = convertAMMDepositFlagsToNumber(tx.Flags)
|
tx.Flags = convertFlagsToNumber(tx.Flags, AMMDepositFlags)
|
||||||
return
|
return
|
||||||
case 'AMMWithdraw':
|
case 'AMMWithdraw':
|
||||||
tx.Flags = convertAMMWithdrawFlagsToNumber(tx.Flags)
|
tx.Flags = convertFlagsToNumber(tx.Flags, AMMWithdrawFlags)
|
||||||
return
|
return
|
||||||
case 'OfferCreate':
|
case 'OfferCreate':
|
||||||
tx.Flags = convertOfferCreateFlagsToNumber(tx.Flags)
|
tx.Flags = convertFlagsToNumber(tx.Flags, OfferCreateFlags)
|
||||||
return
|
return
|
||||||
case 'PaymentChannelClaim':
|
case 'PaymentChannelClaim':
|
||||||
tx.Flags = convertPaymentChannelClaimFlagsToNumber(tx.Flags)
|
tx.Flags = convertFlagsToNumber(tx.Flags, PaymentChannelClaimFlags)
|
||||||
return
|
return
|
||||||
case 'Payment':
|
case 'Payment':
|
||||||
tx.Flags = convertPaymentTransactionFlagsToNumber(tx.Flags)
|
tx.Flags = convertFlagsToNumber(tx.Flags, PaymentFlags)
|
||||||
return
|
return
|
||||||
case 'TrustSet':
|
case 'TrustSet':
|
||||||
tx.Flags = convertTrustSetFlagsToNumber(tx.Flags)
|
tx.Flags = convertFlagsToNumber(tx.Flags, TrustSetFlags)
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
tx.Flags = 0
|
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
|
// 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) => {
|
return Object.keys(flags).reduce((resultFlags, flag) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access
|
||||||
if (flagEnum[flag] == null) {
|
if (flagEnum[flag] == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user