Support ExtendedHookState (#34)

This commit is contained in:
tequ
2025-11-12 20:01:45 +09:00
committed by GitHub
parent 8bbc84057c
commit ac33a1584d
5 changed files with 57 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
### Added
* Support for Cron Amendment
* Support for ExtendedHookState Amendment
## 4.0.1 (2025-10-03)

View File

@@ -84,6 +84,7 @@ export default interface AccountRoot extends BaseLedgerEntry, HasPreviousTxnID {
GovernanceMarks?: string
AccountIndex?: number
TouchCount?: number
HookStateScale?: number
/* The cron job that is associated with this account. */
Cron?: string
}

View File

@@ -4,6 +4,7 @@ import {
Account,
BaseTransaction,
isAccount,
isNumber,
validateBaseTransaction,
validateOptionalField,
} from './common'
@@ -163,10 +164,15 @@ export interface AccountSet extends BaseTransaction {
* account's behalf using NFTokenMint's `Issuer` field.
*/
NFTokenMinter?: Account
/**
* The allowed scale of the hook state.
*/
HookStateScale?: number
}
const MIN_TICK_SIZE = 3
const MAX_TICK_SIZE = 15
const MAX_HOOK_STATE_SCALE = 16
/**
* Verify the form and type of an AccountSet at runtime.
@@ -174,7 +180,7 @@ const MAX_TICK_SIZE = 15
* @param tx - An AccountSet Transaction.
* @throws When the AccountSet is Malformed.
*/
// eslint-disable-next-line max-lines-per-function -- okay for this method, only a little over
// eslint-disable-next-line max-lines-per-function, max-statements -- okay for this method, only a little over
export function validateAccountSet(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
@@ -225,4 +231,14 @@ export function validateAccountSet(tx: Record<string, unknown>): void {
throw new ValidationError('AccountSet: invalid TickSize')
}
}
validateOptionalField(tx, 'HookStateScale', isNumber)
if (
typeof tx.HookStateScale === 'number' &&
tx.HookStateScale > MAX_HOOK_STATE_SCALE
) {
throw new ValidationError(
`AccountSet: HookStateScale must be less than ${MAX_HOOK_STATE_SCALE}`,
)
}
}

View File

@@ -163,4 +163,31 @@ describe('AccountSet', function () {
'AccountSet: invalid field NFTokenMinter',
)
})
it(`throws w/ invalid HookStateScale`, function () {
account.HookStateScale = ''
assert.throws(
() => validateAccountSet(account),
ValidationError,
'AccountSet: invalid field HookStateScale',
)
assert.throws(
() => validate(account),
ValidationError,
'AccountSet: invalid field HookStateScale',
)
account.HookStateScale = 17
assert.throws(
() => validateAccountSet(account),
ValidationError,
'AccountSet: HookStateScale must be less than 16',
)
assert.throws(
() => validate(account),
ValidationError,
'AccountSet: HookStateScale must be less than 16',
)
})
})