Skip to content

🏗️ [Core Feature]: Pausable macros #3

@brozorec

Description

@brozorec

Overview

The Pausable module as spec'ed in #1 currently exposes when_paused and when_not_paused functions, which are used to control contract behavior based on its paused state. While functional, this approach requires explicit function calls within the contract code, potentially leading to verbose and less intuitive implementations.

Proposal

To improve developer experience and code readability, we propose introducing procedural macros for the Pausable functionality. These macros would allow developers to decorate functions directly, streamlining the implementation of pause-aware contract logic.

Implementation Details

  1. Convert the existing when_paused and when_not_paused functions into procedural macros.
  2. The new macros will be used as function decorators:
#[when_paused]
pub fn emergency_execution(e: Env) {
}

#[when_not_paused]
pub fn normal_execution(e: Env) {
}
  1. The macros will internally generate the necessary checks and logic, equivalent to calling the current functions at the very beginning of the function body.

Benefits

  1. Improved Readability: The pause-aware nature of functions becomes immediately apparent from their declarations.
  2. Reduced Boilerplate: Eliminates the need for explicit function calls within each pause-aware function.
  3. Consistency: Encourages a standardized approach to implementing pause-aware functionality across contracts.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions