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

feat: highlight owner methods #61

Merged
merged 1 commit into from
Apr 13, 2022
Merged

feat: highlight owner methods #61

merged 1 commit into from
Apr 13, 2022

Conversation

chadoh
Copy link
Contributor

@chadoh chadoh commented Apr 1, 2022

The idea of the comments in the Rust is that they will eventually be
generated by a Rust macro that replaces all the assert_owner calls.
The macro can look like:

#[only(::owner, willem.near, ::admins, ::get_admin_contract_id::admins)]

Or maybe:

#[only(owner, "willem.near", admins, ::get_admin_contract_id::admins)]

The "owner" view method could be auto-generated from a derive on the
struct:

#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault, Ownable)]

While ::admins and ::get_admin_contract_id would be
explicitly-defined methods on this contract.

The methods specified here would all be expected to return AccountId | Vec<AccountId>

::get_admin_contract_id::admins specifies that any accounts returned by
this method on an external contract should be allowed calling the
specified method. This would be simple to handle on a frontend, but
implies that a cross-contract call with callback is generated by having
such a specification in the macro.

@github-actions
Copy link

github-actions bot commented Apr 12, 2022

PR Preview Action v1.1.1
Preview removed because the pull request was closed.
2022-04-13 17:42 UTC

@chadoh chadoh marked this pull request as ready for review April 13, 2022 13:23
Comment on lines +30 to +32
export const adminMethods = Object.keys(topLevelSchema.definitions).filter(m =>
allowsAdmin(m as MethodName)
) as MethodName[]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plans for a follow-up PR:

  • Since we want to make this form general-purpose for any contract, we should stop making assumptions about the permission system of a contract. Rather than have one group of admins, a contract could have, say, a group of legislators that can do some things and executives who can do others. Whatever. So the UI should just filter the list of Change Methods based on the current user's permissions.

The idea of the comments in the Rust is that they will eventually be
generated by a Rust macro that replaces all the `assert_owner` calls.
The macro can look like:

    #[only(::owner, willem.near, ::admins, ::get_admin_contract_id::admins)]

Or maybe:

    #[only(owner, "willem.near", admins, ::get_admin_contract_id::admins)]

The "owner" view method could be auto-generated from a `derive` on the
struct:

    #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault, Ownable)]

While `::admins` and `::get_admin_contract_id` would be
explicitly-defined methods on this contract.

The methods specified here would all be expected to return `AccountId |
Vec<AccountId>`

::get_admin_contract_id::admins specifies that any accounts returned by
this method on an external contract should be allowed calling the
specified method. This would be simple to handle on a frontend, but
implies that a cross-contract call with callback is generated by having
such a specification in the macro.
@chadoh chadoh requested a review from willemneal April 13, 2022 17:36
@chadoh chadoh merged commit 94b5ade into main Apr 13, 2022
@chadoh chadoh deleted the feat/owner-methods branch April 13, 2022 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant