mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
feature Hooks
update definitions add network id to base transaction add set hook update required update definitions make network id required
This commit is contained in:
47
packages/xrpl/src/models/transactions/setHook.ts
Normal file
47
packages/xrpl/src/models/transactions/setHook.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { ValidationError } from '../../errors'
|
||||
import { Hook } from '../common'
|
||||
|
||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @category Transaction Models
|
||||
*/
|
||||
export interface SetHook extends BaseTransaction {
|
||||
TransactionType: 'SetHook'
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Hooks: Hook[]
|
||||
}
|
||||
|
||||
const MAX_HOOKS = 4
|
||||
|
||||
/**
|
||||
* Verify the form and type of an SetHook at runtime.
|
||||
*
|
||||
* @param tx - An SetHook Transaction.
|
||||
* @throws When the SetHook is Malformed.
|
||||
*/
|
||||
export function validateSetHook(tx: Record<string, unknown>): void {
|
||||
validateBaseTransaction(tx)
|
||||
|
||||
if (tx.Hooks === undefined) {
|
||||
throw new ValidationError('SetHook: missing field Hooks')
|
||||
}
|
||||
|
||||
if (!Array.isArray(tx.Hooks)) {
|
||||
throw new ValidationError('SetHook: invalid Hooks')
|
||||
}
|
||||
|
||||
if (tx.Hooks.length === 0) {
|
||||
throw new ValidationError('SetHook: need at least 1 hook in Hooks')
|
||||
}
|
||||
|
||||
if (tx.Hooks.length > MAX_HOOKS) {
|
||||
throw new ValidationError(
|
||||
`SetHook: maximum of ${MAX_HOOKS} hooks allowed in Hooks`,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user