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

Add ACL to near-token-factory #24

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 100 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ base64 = "0.13.0"
borsh = "0.9"
ethabi = "17.2"
hex = "0.4"
near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", tag = "v0.0.1" }
near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", tag = "v0.0.2" }
near-contract-standards = "4.0.0"
near-sdk = "4.0.0"
near-sdk = "4.1.0"
near-token-common = { path = "near-token-common" }
serde = "1"
serde_json = "1"
Expand Down
16 changes: 11 additions & 5 deletions near-token-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ impl Contract {
/// Method is payable since the factory needs to pay the storage to be
/// registered automatically.
///
///Optionally an account can be provided that is made access control super
///admin. If `super_admin` is `None`, then the factory itself is made super
///admin.
/// Optionally an account can be provided that is made access control super
/// admin. If `super_admin` is `None`, then the factory itself is made super
/// admin.
///
///It grants [`AclRole::MetadataUpdater`] to the factory to enable a
///trustless workflow for metadata updates, see [`Self::update_metadata`].
/// It grants [`AclRole::MetadataUpdater`] to the factory to enable a
/// trustless workflow for metadata updates, see [`Self::update_metadata`].
#[init]
#[payable]
pub fn new(super_admin: Option<AccountId>) -> Self {
Expand All @@ -93,10 +93,16 @@ impl Contract {

// Set up access control.
let super_admin = super_admin.unwrap_or_else(env::predecessor_account_id);

// Grant super admin role to the provided account.
require!(
contract.acl_init_super_admin(super_admin),
"Failed to add factory as initial acl super-admin",
);

// Grant MetadataUpdater role to the factory. This enables a trustless setup to set
// the metadata by any user. Super admin is responsible for adding a new user account
// with this role to provide icon and extra metadata.
mooori marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +103 to +105
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Grant MetadataUpdater role to the factory. This enables a trustless setup to set
// the metadata by any user. Super admin is responsible for adding a new user account
// with this role to provide icon and extra metadata.
// Grant MetadataUpdater role to the factory. This enables a trustless setup as
// described in [`Self::update_metadata`].

I think the description of update_metadata is a bit easier to follow than the comment here.

Anyway, maybe we want to describe the idea only in one place? Then there's no risk of two descriptions getting out of sync.

require!(
contract
.__acl
Expand Down
1 change: 1 addition & 0 deletions near-token-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib"]

[dependencies]
hex.workspace = true
near-plugins.workspace = true
near-sdk.workspace = true
near-token-common.workspace = true
uint.workspace = true
Expand Down
Loading