mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
update hook
update hook add test and validation add estimate fee func fix estimated fee error add hook utils
This commit is contained in:
@@ -17,6 +17,7 @@ export interface SetHook extends BaseTransaction {
|
||||
}
|
||||
|
||||
const MAX_HOOKS = 4
|
||||
const HEX_REGEX = /^[0-9A-Fa-f]{64}$/u
|
||||
|
||||
/**
|
||||
* Verify the form and type of an SetHook at runtime.
|
||||
@@ -27,21 +28,29 @@ const MAX_HOOKS = 4
|
||||
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`,
|
||||
)
|
||||
}
|
||||
|
||||
for (const hook of tx.Hooks) {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Should be a Hook
|
||||
const hookObject = hook as Hook
|
||||
const { HookOn, HookNamespace } = hookObject.Hook
|
||||
if (HookOn !== undefined && !HEX_REGEX.test(HookOn)) {
|
||||
throw new ValidationError(
|
||||
`SetHook: HookOn in Hook must be a 256-bit (32-byte) hexadecimal value`,
|
||||
)
|
||||
}
|
||||
if (HookNamespace !== undefined && !HEX_REGEX.test(HookNamespace)) {
|
||||
throw new ValidationError(
|
||||
`SetHook: HookNamespace in Hook must be a 256-bit (32-byte) hexadecimal value`,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user