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(template_lib)!: new access rules macro #1176

Merged
merged 18 commits into from
Oct 21, 2024

Conversation

mrnaveira
Copy link
Collaborator

@mrnaveira mrnaveira commented Oct 17, 2024

Description

  • Created a new rule! macro in tari_template_lib to build AccessRule enums
  • Updated all usages of access rules construction to use the new macro, including builtin templates (e.g. account and account_nft)

Motivation and Context

We want a better way of constructing AccessRules. For example, to restrict a resource to be minted only by a specific component, we need something like:

ResourceBuilder::fungible()
                .mintable(AccessRule::Restricted(RestrictedAccessRule::Require(
                    RequireRule::Require(address.into()),
                )))

Instead, we want a new macro that allows us to build access rules in simpler and more readable way:

ResourceBuilder::fungible()
                .mintable(rule!(component(address)))

This PR adds a new macro rule! for this purpose. All variants of rules can be build as follows:

  • rule!(allow_all)
  • rule!(deny_all)
  • rule!(component(address))
  • rule!(resource(address))
  • rule!(template(address))
  • rule!(non_fungible(address))
  • rule!(any_of(component(c_address)), template(t_address)))

How Has This Been Tested?

  • New unit test that covers all possible outputs of the new macro
  • Existing templates (e.g. account) now use the new macro and all the related tests still pass

What process can a PR reviewer use to test or verify this change?

See previous section

Breaking Changes

  • None
  • Requires data directory to be deleted
  • Other - As the tari_template_lib crate changes, all the builtin templates (e.g. account) also change.

Copy link

github-actions bot commented Oct 17, 2024

Test Results (CI)

571 tests  +1   570 ✅ +1   3h 15m 47s ⏱️ - 2m 28s
 64 suites ±0     0 💤 ±0 
  2 files   ±0     1 ❌ ±0 

For more details on these failures, see this check.

Results for commit 352baae. ± Comparison against base commit 39c638b.

♻️ This comment has been updated with latest results.

@mrnaveira mrnaveira marked this pull request as ready for review October 20, 2024 22:30
Copy link
Member

@sdbondi sdbondi left a comment

Choose a reason for hiding this comment

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

Nice utACK

@sdbondi sdbondi added this pull request to the merge queue Oct 21, 2024
Merged via the queue into tari-project:development with commit 50e7b8c Oct 21, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants