feat(icrc-ledger-types): add ICRC-123 block schema validators#9981
feat(icrc-ledger-types): add ICRC-123 block schema validators#9981
Conversation
gregorydemay
left a comment
There was a problem hiding this comment.
Thanks @bogwar I mostly have some understanding questions but otherwise code LGTM
| /// * `btype` – block type identifier | ||
| /// * `strict` – when `true`, `caller`, `mthd`, and `ts` (in tx) are required (ICRC-153); | ||
| /// when `false` they are optional (ICRC-123). | ||
| fn account_block_validator(btype: &'static str, strict: bool) -> ValuePredicate { |
There was a problem hiding this comment.
nit: this seems to be almost the same as principal_block_validator. If you want to keep the expressivity (2 different method names) I would refactor so that they delegate to a common internal method.
There was a problem hiding this comment.
The two functions differ only in the required tx field (account with is_account() vs principal with is_principal()). I could extract a common helper that takes the field name and predicate as parameters, but it would add indirection for very little deduplication — the outer block structure (phash, btype, ts, tx) is the same but the tx field predicates are different. Happy to refactor if you feel strongly.
There was a problem hiding this comment.
On reflection, I'd rather keep them separate. The deduplication gain is minimal (one line differs) and a shared helper with field name + predicate parameters would be harder to read. Keeping them explicit makes it clear at a glance what each block type expects.
| /// tx: { account: Account, caller?: Principal, mthd?: Text, ts?: Nat, | ||
| /// reason?: Text, policy_ref?: Text } } | ||
| /// ``` | ||
| pub fn validate_freeze_account(block: &Value) -> Result<(), ValuePredicateFailures> { |
There was a problem hiding this comment.
understanding question: the ICRC number appears in certain methods, like validate_153_freeze_account but not all, like this one (validate_freeze_account). Is there a reason?
There was a problem hiding this comment.
Good point — renamed all permissive validators to include the standard number: validate_123_freeze_account, validate_123_unfreeze_account, etc. The convention is now: validate_123_* = permissive (ICRC-123 block standard), validate_153_* = strict (ICRC-153 endpoint standard). Created DEFI-2791 to apply the same rename to the ICRC-122 module (validate_mint → validate_122_mint).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c789755 to
827be7f
Compare
Phase 1 of ICRC-123/153 implementation. Adds ICRC-123 block schema validators for 4 block types with permissive and strict validation modes.