export transaction type map from definitions

This commit is contained in:
Denis Angell
2023-03-27 18:31:22 +00:00
parent f6a90a31c4
commit f19466cabe
4 changed files with 20 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ const Field = DEFAULT_DEFINITIONS.field
* @brief: All valid transaction types * @brief: All valid transaction types
*/ */
const TRANSACTION_TYPES = DEFAULT_DEFINITIONS.transactionNames const TRANSACTION_TYPES = DEFAULT_DEFINITIONS.transactionNames
const TRANSACTION_TYPE_MAP = DEFAULT_DEFINITIONS.transactionMap
export { export {
Bytes, Bytes,
@@ -31,4 +32,5 @@ export {
TransactionResult, TransactionResult,
TransactionType, TransactionType,
TRANSACTION_TYPES, TRANSACTION_TYPES,
TRANSACTION_TYPE_MAP,
} }

View File

@@ -33,6 +33,8 @@ class XrplDefinitionsBase {
transactionType: BytesLookup transactionType: BytesLookup
// Valid transaction names // Valid transaction names
transactionNames: string[] transactionNames: string[]
// Valid transaction names
transactionMap: Record<string, number>
// Maps serializable types to their TypeScript class implementation // Maps serializable types to their TypeScript class implementation
dataTypes: Record<string, typeof SerializedType> dataTypes: Record<string, typeof SerializedType>
@@ -68,10 +70,20 @@ class XrplDefinitionsBase {
enums.FIELDS as Array<[string, FieldInfo]>, enums.FIELDS as Array<[string, FieldInfo]>,
enums.TYPES, enums.TYPES,
) )
this.transactionNames = Object.entries(enums.TRANSACTION_TYPES) this.transactionNames = Object.entries(enums.TRANSACTION_TYPES)
.filter(([_key, value]) => value >= 0) .filter(([_key, value]) => value >= 0)
.map(([key, _value]) => key) .map(([key, _value]) => key)
const ignoreList = ['EnableAmendment', 'SetFee', 'UNLModify', 'EmitFailure']
this.transactionMap = Object.assign(
{},
...Object.entries(enums.TRANSACTION_TYPES)
.filter(([_key, _value]) => _value >= 0 || ignoreList.includes(_key))
.map(([key, value]) => ({ [key]: value })),
)
this.dataTypes = {} // Filled in via associateTypes this.dataTypes = {} // Filled in via associateTypes
this.associateTypes(types) this.associateTypes(types)
} }

View File

@@ -6,6 +6,7 @@ import { JsonObject } from './types/serialized-type'
import { import {
XrplDefinitionsBase, XrplDefinitionsBase,
TRANSACTION_TYPES, TRANSACTION_TYPES,
TRANSACTION_TYPE_MAP,
DEFAULT_DEFINITIONS, DEFAULT_DEFINITIONS,
} from './enums' } from './enums'
import { XrplDefinitions } from './enums/xrpl-definitions' import { XrplDefinitions } from './enums/xrpl-definitions'
@@ -134,6 +135,7 @@ export {
decodeQuality, decodeQuality,
decodeLedgerData, decodeLedgerData,
TRANSACTION_TYPES, TRANSACTION_TYPES,
TRANSACTION_TYPE_MAP,
XrplDefinitions, XrplDefinitions,
XrplDefinitionsBase, XrplDefinitionsBase,
DEFAULT_DEFINITIONS, DEFAULT_DEFINITIONS,

View File

@@ -6,7 +6,7 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports -- Required // eslint-disable-next-line @typescript-eslint/no-require-imports -- Required
import createHash = require('create-hash') import createHash = require('create-hash')
import { TRANSACTION_TYPE_MAP, TRANSACTION_TYPES } from 'ripple-binary-codec' import { TRANSACTION_TYPES, TRANSACTION_TYPE_MAP } from 'ripple-binary-codec'
import { XrplError } from '../errors' import { XrplError } from '../errors'
import { HookParameter } from '../models/common' import { HookParameter } from '../models/common'
@@ -35,6 +35,9 @@ export type TTS = typeof tts
export function calculateHookOn(arr: Array<keyof TTS>): string { export function calculateHookOn(arr: Array<keyof TTS>): string {
let hash = '0x3e3ff5bf' let hash = '0x3e3ff5bf'
arr.forEach((nth) => { arr.forEach((nth) => {
if (!TRANSACTION_TYPE_MAP) {
throw new XrplError(`TRANSACTION_TYPE_MAP malformed or undefined`)
}
if (typeof nth !== 'string') { if (typeof nth !== 'string') {
throw new XrplError(`HookOn transaction type must be string`) throw new XrplError(`HookOn transaction type must be string`)
} }