-
Notifications
You must be signed in to change notification settings - Fork 40
feat: use proposed contracttrait type
#350
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
Changes from all commits
56f0362
7bfbf45
708b79b
0549f3b
650920c
c378927
aa6bde6
2753916
80a7d3b
5880dff
f98d0a4
4d8287e
9bc9170
20ff3ec
ef977bc
756a790
e322e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,66 +6,66 @@ | |
| //! accounts. | ||
| use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, String}; | ||
| use stellar_access::access_control::{self as access_control, AccessControl}; | ||
| use stellar_macros::{default_impl, only_role}; | ||
| use stellar_access::{AccessControl, AccessController}; | ||
| use stellar_macros::only_role; | ||
| use stellar_tokens::fungible::{ | ||
| allowlist::{AllowList, FungibleAllowList}, | ||
| burnable::FungibleBurnable, | ||
| Base, FungibleToken, | ||
| FungibleToken, | ||
| }; | ||
|
|
||
| #[contract] | ||
| pub struct ExampleContract; | ||
|
|
||
| #[contractimpl] | ||
| impl ExampleContract { | ||
| pub fn __constructor(e: &Env, admin: Address, manager: Address, initial_supply: i128) { | ||
| Base::set_metadata( | ||
| pub fn __constructor(e: &Env, admin: &Address, manager: &Address, initial_supply: i128) { | ||
| Self::set_metadata( | ||
| e, | ||
| 18, | ||
| String::from_str(e, "AllowList Token"), | ||
| String::from_str(e, "ALT"), | ||
| ); | ||
|
|
||
| access_control::set_admin(e, &admin); | ||
| Self::init_admin(e, admin); | ||
|
|
||
| // create a role "manager" and grant it to `manager` | ||
| access_control::grant_role_no_auth(e, &admin, &manager, &symbol_short!("manager")); | ||
| Self::grant_role_no_auth(e, admin, manager, &symbol_short!("manager")); | ||
|
|
||
| // Allow the admin to transfer tokens | ||
| AllowList::allow_user(e, &admin); | ||
| Self::allow_user_no_auth(e, admin); | ||
|
|
||
| // Mint initial supply to the admin | ||
| Base::mint(e, &admin, initial_supply); | ||
| Self::internal_mint(e, admin, initial_supply); | ||
| } | ||
| } | ||
|
|
||
| #[default_impl] | ||
| #[contractimpl] | ||
| impl FungibleToken for ExampleContract { | ||
| type ContractType = AllowList; | ||
| type Impl = AllowList; | ||
|
Comment on lines
-46
to
+45
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Me:
Willem:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah I give you that :D I don't think
I disagree. It is the associated type. The implementation of the contract is happening elsewhere, this is just the indicator type. I can go with |
||
| } | ||
|
|
||
| #[contractimpl] | ||
| impl FungibleBurnable for ExampleContract { | ||
| type Impl = AllowList; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Me:
Willem:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are specific reasons that we didn't want to provide default implementations for some modules, like The reason for the existence of the I'd say this change is contradicting with 2 critical design choices of our library. |
||
| } | ||
|
|
||
| #[contractimpl] | ||
| impl AccessControl for ExampleContract { | ||
| type Impl = AccessController; | ||
| } | ||
|
|
||
| #[contractimpl] | ||
| impl FungibleAllowList for ExampleContract { | ||
| fn allowed(e: &Env, account: Address) -> bool { | ||
| AllowList::allowed(e, &account) | ||
| } | ||
| type Impl = AllowList; | ||
|
|
||
| #[only_role(operator, "manager")] | ||
| fn allow_user(e: &Env, user: Address, operator: Address) { | ||
| AllowList::allow_user(e, &user) | ||
| fn allow_user(e: &Env, user: &Address, operator: &Address) { | ||
| Self::Impl::allow_user(e, user, operator) | ||
| } | ||
|
|
||
| #[only_role(operator, "manager")] | ||
| fn disallow_user(e: &Env, user: Address, operator: Address) { | ||
| AllowList::disallow_user(e, &user) | ||
| fn disallow_user(e: &Env, user: &Address, operator: &Address) { | ||
| Self::Impl::disallow_user(e, user, operator) | ||
| } | ||
| } | ||
|
|
||
| #[default_impl] | ||
| #[contractimpl] | ||
| impl AccessControl for ExampleContract {} | ||
|
|
||
| #[default_impl] | ||
| #[contractimpl] | ||
| impl FungibleBurnable for ExampleContract {} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me:
Willem:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I fully get it, could you elaborate on that a bit more @willemneal ?