Skip to content

Remove event emission from allowance() view function in learn-token #179

Description

@DeFiVC

What

The allowance() public getter function emits an allowance_expired event when an expired allowance is queried, producing side effects in what should be a read-only view.

Why

Callers who only want to check the current allowance may inadvertently trigger event emission. This can produce duplicate events if allowance() is called multiple times for the same expired pair, or if transfer_from also triggers the same event. It violates the principle that view functions should be side-effect-free.

Scope

  • Remove event emission from the allowance() getter
  • Keep the event emission in transfer_from, burn_from, and prune_expired_allowance where it's intentional

Technical Context

  • File: contracts/learn-token/src/lib.rs (lines ~241-250)
  • The allowance() function checks expiry and emits allowance_expired before returning 0
  • Other functions (transfer_from, etc.) already emit the same event when they encounter expired allowances

Acceptance Criteria

  • allowance() no longer emits events
  • transfer_from and other mutation functions still emit allowance_expired when appropriate
  • Existing tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    mediumFunctionality impaired but workaround exists, edge case, partial feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions