diff --git a/packages/xahau-binary-codec/src/enums/definitions.json b/packages/xahau-binary-codec/src/enums/definitions.json index 0f8ad010..e529ab5d 100644 --- a/packages/xahau-binary-codec/src/enums/definitions.json +++ b/packages/xahau-binary-codec/src/enums/definitions.json @@ -329,6 +329,16 @@ "type": "UInt16" } ], + [ + "HookStateScale", + { + "nth": 21, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt16" + } + ], [ "NetworkID", { @@ -2838,6 +2848,7 @@ "tecINSUF_RESERVE_SELLER": 187, "tecIMMUTABLE": 188, "tecTOO_MANY_REMARKS": 189, + "tecHAS_HOOK_STATE": 190, "tecLAST_POSSIBLE_ENTRY": 255 }, "TRANSACTION_TYPES": { diff --git a/packages/xahau/HISTORY.md b/packages/xahau/HISTORY.md index e39c9446..cfdb5960 100644 --- a/packages/xahau/HISTORY.md +++ b/packages/xahau/HISTORY.md @@ -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) diff --git a/packages/xahau/src/models/ledger/AccountRoot.ts b/packages/xahau/src/models/ledger/AccountRoot.ts index ca743273..c7547295 100644 --- a/packages/xahau/src/models/ledger/AccountRoot.ts +++ b/packages/xahau/src/models/ledger/AccountRoot.ts @@ -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 } diff --git a/packages/xahau/src/models/transactions/accountSet.ts b/packages/xahau/src/models/transactions/accountSet.ts index dde9b552..6c165523 100644 --- a/packages/xahau/src/models/transactions/accountSet.ts +++ b/packages/xahau/src/models/transactions/accountSet.ts @@ -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): void { validateBaseTransaction(tx) @@ -225,4 +231,14 @@ export function validateAccountSet(tx: Record): 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}`, + ) + } } diff --git a/packages/xahau/test/models/accountSet.test.ts b/packages/xahau/test/models/accountSet.test.ts index b3ce24ea..947615d4 100644 --- a/packages/xahau/test/models/accountSet.test.ts +++ b/packages/xahau/test/models/accountSet.test.ts @@ -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', + ) + }) })