update hookon transaction types

This commit is contained in:
Denis Angell
2023-03-03 03:22:12 -05:00
parent 16bd1ed34c
commit 263ee8a873
2 changed files with 26 additions and 29 deletions

View File

@@ -6,7 +6,9 @@
// 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 { XrplError } from '../errors'
import { HookParameter } from '../models/common'
/**
@@ -14,33 +16,8 @@ import { HookParameter } from '../models/common'
* @description
* Transaction types
*/
export const tts = {
ttPAYMENT: 0,
ttESCROW_CREATE: 1,
ttESCROW_FINISH: 2,
ttACCOUNT_SET: 3,
ttESCROW_CANCEL: 4,
ttREGULAR_KEY_SET: 5,
ttOFFER_CREATE: 7,
ttOFFER_CANCEL: 8,
ttTICKET_CREATE: 10,
ttSIGNER_LIST_SET: 12,
ttPAYCHAN_CREATE: 13,
ttPAYCHAN_FUND: 14,
ttPAYCHAN_CLAIM: 15,
ttCHECK_CREATE: 16,
ttCHECK_CASH: 17,
ttCHECK_CANCEL: 18,
ttDEPOSIT_PREAUTH: 19,
ttTRUST_SET: 20,
ttACCOUNT_DELETE: 21,
ttHOOK_SET: 22,
ttNFTOKEN_MINT: 25,
ttNFTOKEN_BURN: 26,
ttNFTOKEN_CREATE_OFFER: 27,
ttNFTOKEN_CANCEL_OFFER: 28,
ttNFTOKEN_ACCEPT_OFFER: 29,
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Required
export const tts = TRANSACTION_TYPE_MAP
/**
* @typedef TTS
@@ -58,8 +35,16 @@ export type TTS = typeof tts
export function calculateHookOn(arr: Array<keyof TTS>): string {
let hash = '0x3e3ff5bf'
arr.forEach((nth) => {
if (typeof nth !== 'string') {
throw new XrplError(`HookOn transaction type must be string`)
}
if (!TRANSACTION_TYPES.includes(String(nth))) {
throw new XrplError(
`invalid transaction type '${String(nth)}' in HookOn array`,
)
}
let value = BigInt(hash)
// eslint-disable-next-line no-bitwise -- Required
// eslint-disable-next-line no-bitwise, @typescript-eslint/no-unsafe-member-access -- Required
value ^= BigInt(1) << BigInt(tts[nth])
// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- Required
hash = `0x${value.toString(16)}`

View File

@@ -8,6 +8,18 @@ import {
} from '../../src'
describe('test hook on', function () {
it('invalid', function () {
const invokeOn: Array<keyof TTS> = [1]
expect(() => {
calculateHookOn(invokeOn)
}).toThrow('HookOn transaction type must be string')
})
it('invalid', function () {
const invokeOn: Array<keyof TTS> = ['AccountSet1']
expect(() => {
calculateHookOn(invokeOn)
}).toThrow("invalid transaction type 'AccountSet1' in HookOn array")
})
it('all', function () {
const result = calculateHookOn([])
assert.equal(
@@ -16,7 +28,7 @@ describe('test hook on', function () {
)
})
it('one', function () {
const invokeOn: Array<keyof TTS> = ['ttACCOUNT_SET']
const invokeOn: Array<keyof TTS> = ['AccountSet']
const result = calculateHookOn(invokeOn)
assert.equal(
result,