Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Add #[view] annotation to object::is_owner function #15294

Open
mshakeg opened this issue Nov 16, 2024 · 0 comments
Open

[Feature Request]: Add #[view] annotation to object::is_owner function #15294

mshakeg opened this issue Nov 16, 2024 · 0 comments
Labels
enhancement New feature or request stale-exempt Prevents issues from being automatically marked and closed as stale

Comments

@mshakeg
Copy link

mshakeg commented Nov 16, 2024

🚀 Feature Request

Add the #[view] annotation to the is_owner function in the aptos_framework::object module to enable off-chain querying of object ownership status.

Motivation

Is your feature request related to a problem? Please describe.

The is_owner function in the object module is a read-only function that checks if a given address is the owner of a specific object. However, it currently lacks the #[view] annotation, which means it cannot be used in view functions or called directly from off-chain applications to check ownership status.

This limitation forces developers to either:

  1. Write additional wrapper functions with the #[view] annotation
  2. Make unnecessary transactions just to check ownership
  3. Implement their own ownership checking logic off-chain

Adding the #[view] annotation would allow for more efficient and direct ownership queries without requiring state modifications or additional gas costs.

Pitch

Describe the solution you'd like
Add the #[view] annotation to the existing is_owner function:

/// Return true if the provided address is the current owner.
#[view]
public fun is_owner<T: key>(object: Object<T>, owner: address): bool acquires ObjectCore {
    owner(object) == owner
}

This change would:

  • Enable direct off-chain queries for object ownership
  • Reduce unnecessary transaction costs for ownership checks
  • Improve developer experience when building applications that need to verify object ownership
  • Maintain consistency with other read-only functions in the framework

Describe alternatives you've considered

  1. Creating a separate view function specifically for ownership checks
  2. Implementing ownership verification through events and indexing
  3. Building client-side ownership tracking

However, adding the #[view] annotation to the existing function is the most straightforward and maintainable solution, as it:

  • Requires minimal code changes
  • Maintains single source of truth for ownership checks
  • Doesn't introduce additional complexity or maintenance burden

Are you willing to open a pull request?

Yes, I can open a pull request for this change if the feature request is approved.

Additional context

This change aligns with Aptos' goal of improving developer experience and reducing unnecessary transaction costs. Similar read-only functions in other modules (like account::exists_at) already use the #[view] annotation, making this change consistent with existing patterns in the framework.

@mshakeg mshakeg added the enhancement New feature or request label Nov 16, 2024
@brmataptos brmataptos added the stale-exempt Prevents issues from being automatically marked and closed as stale label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale-exempt Prevents issues from being automatically marked and closed as stale
Projects
None yet
Development

No branches or pull requests

2 participants