mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-04 13:05:49 +00:00
export transaction type map from definitions
This commit is contained in:
@@ -19,6 +19,7 @@ const Field = DEFAULT_DEFINITIONS.field
|
||||
* @brief: All valid transaction types
|
||||
*/
|
||||
const TRANSACTION_TYPES = DEFAULT_DEFINITIONS.transactionNames
|
||||
const TRANSACTION_TYPE_MAP = DEFAULT_DEFINITIONS.transactionMap
|
||||
|
||||
export {
|
||||
Bytes,
|
||||
@@ -31,4 +32,5 @@ export {
|
||||
TransactionResult,
|
||||
TransactionType,
|
||||
TRANSACTION_TYPES,
|
||||
TRANSACTION_TYPE_MAP,
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ class XrplDefinitionsBase {
|
||||
transactionType: BytesLookup
|
||||
// Valid transaction names
|
||||
transactionNames: string[]
|
||||
// Valid transaction names
|
||||
transactionMap: Record<string, number>
|
||||
// Maps serializable types to their TypeScript class implementation
|
||||
dataTypes: Record<string, typeof SerializedType>
|
||||
|
||||
@@ -68,10 +70,20 @@ class XrplDefinitionsBase {
|
||||
enums.FIELDS as Array<[string, FieldInfo]>,
|
||||
enums.TYPES,
|
||||
)
|
||||
|
||||
this.transactionNames = Object.entries(enums.TRANSACTION_TYPES)
|
||||
.filter(([_key, value]) => value >= 0)
|
||||
.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.associateTypes(types)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { JsonObject } from './types/serialized-type'
|
||||
import {
|
||||
XrplDefinitionsBase,
|
||||
TRANSACTION_TYPES,
|
||||
TRANSACTION_TYPE_MAP,
|
||||
DEFAULT_DEFINITIONS,
|
||||
} from './enums'
|
||||
import { XrplDefinitions } from './enums/xrpl-definitions'
|
||||
@@ -134,6 +135,7 @@ export {
|
||||
decodeQuality,
|
||||
decodeLedgerData,
|
||||
TRANSACTION_TYPES,
|
||||
TRANSACTION_TYPE_MAP,
|
||||
XrplDefinitions,
|
||||
XrplDefinitionsBase,
|
||||
DEFAULT_DEFINITIONS,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- Required
|
||||
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 { HookParameter } from '../models/common'
|
||||
@@ -35,6 +35,9 @@ export type TTS = typeof tts
|
||||
export function calculateHookOn(arr: Array<keyof TTS>): string {
|
||||
let hash = '0x3e3ff5bf'
|
||||
arr.forEach((nth) => {
|
||||
if (!TRANSACTION_TYPE_MAP) {
|
||||
throw new XrplError(`TRANSACTION_TYPE_MAP malformed or undefined`)
|
||||
}
|
||||
if (typeof nth !== 'string') {
|
||||
throw new XrplError(`HookOn transaction type must be string`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user