Skip to content

Commit 06b9ea0

Browse files
committed
Storagemap optimizations
and adds initial setup in RBAC readme
1 parent 6fcf792 commit 06b9ea0

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

pallets/gated-marketplace/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Create marketplaces that require previous authorization before placing sell and
99
- [Getters](#getters)
1010
- [Usage](#usage)
1111
- [Polkadot-js CLI](#polkadot-js-cli)
12+
- [Submit initial role setup (needs sudo](#submit-initial-role-setup-needs-sudo)
1213
- [Create a marketplace](#create-a-marketplace)
1314
- [Get a marketplace](#get-a-marketplace)
1415
- [Get what roles does an account have on a marketplace](#get-what-roles-does-an-account-have-on-a-marketplace)
@@ -34,6 +35,7 @@ Create marketplaces that require previous authorization before placing sell and
3435
- [Take sell offer - direct purchase](#take-sell-offer---direct-purchase)
3536
- [Take buy offer](#take-buy-offer)
3637
- [Polkadot-js api (javascript library)](#polkadot-js-api-javascript-library)
38+
- [Submit initial role setup (needs sudo)](#submit-initial-role-setup-needs-sudo-1)
3739
- [Create a marketplace](#create-a-marketplace-1)
3840
- [Get a marketplace](#get-a-marketplace-1)
3941
- [Get what roles does an account have on a marketplace](#get-what-roles-does-an-account-have-on-a-marketplace-1)
@@ -87,8 +89,10 @@ This module allows to:
8789
## Interface
8890

8991
### Dispachable functions
92+
93+
- `initial_setup` enables all the permission related functionality using the `RBAC` pallet, it can only be called by the sudo account or a majority of the Council (60%). It is essential to call this extrinsic before using other extrinsics.
9094
- `create_marketplace` creates an on-chain marketplace record, it takes a `label` and an account that will fulfill the role of `administrator`, the extrinsic origin will be set up automatically as the marketplace owner.
91-
- `apply` starts the process to enter the specidied `marketplace`.
95+
- `apply` starts the process to enter the specified `marketplace`.
9296
- `reapply` allows the applicant to apply again for the selected marketplace.
9397
- `enroll` is only callable by the marketplace owner or administrator, as it finishes the application process. It takes a `marketplace` identification, and `account` or `application` identification to enroll or reject, and an `approved` boolean flag which approves the application if set to `true`. Owner/admin can add a feedback regarding the user's application.
9498
- `add_authority` is only callable by the marketplace owner or administrator. As it name implies, adds a new user that will have special permission within the marketplace. It takes the `account` which will have the permissions, the type of `authority` it will have, and the `marketplace` identification in which the permissions will be enforced.
@@ -145,6 +149,11 @@ The following examples will be using these prefunded accounts and testing data:
145149

146150
### Polkadot-js CLI
147151

152+
#### Submit initial role setup (needs sudo
153+
```bash
154+
polkadot-js-api tx.gatedMarketplace.initialSetup --sudo --seed "//Alice"
155+
```
156+
148157
#### Create a marketplace
149158
```bash
150159
# Administrator account and marketplace label
@@ -401,7 +410,13 @@ polkadot-js-api tx.gatedMarketplace.takeBuyOffer "0x66fcfadc174a596d8f8dc1b06703
401410
```
402411

403412
### Polkadot-js api (javascript library)
404-
While most of the data flow is almost identical to its CLI counter part, the javascript library is much more versatile regarding queries. The API setup will be ommited.
413+
While most of the data flow is almost identical to its CLI counter part, the javascript library is much more versatile regarding queries.
414+
415+
416+
#### Submit initial role setup (needs sudo)
417+
```js
418+
const initial_set_up = await api.tx.sudo.sudo(api.tx.gatedMarketplace.initialSetup()).signAndSend(alice);
419+
```
405420

406421
#### Create a marketplace
407422
```js

pallets/rbac/src/lib.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub mod pallet {
5555
#[pallet::getter(fn scopes)]
5656
pub(super) type Scopes<T: Config> = StorageMap<
5757
_,
58-
Blake2_128Concat,
58+
Identity,
5959
PalletId, // pallet_id
6060
BoundedVec<ScopeId, T::MaxScopesPerPallet>, // scopes_id
6161
ValueQuery,
@@ -75,7 +75,7 @@ pub mod pallet {
7575
#[pallet::getter(fn pallet_roles)]
7676
pub(super) type PalletRoles<T: Config> = StorageMap<
7777
_,
78-
Blake2_128Concat,
78+
Identity,
7979
PalletId, // pallet_id
8080
BoundedVec<RoleId, T::MaxRolesPerPallet >, // role_id
8181
ValueQuery,
@@ -85,9 +85,9 @@ pub mod pallet {
8585
#[pallet::getter(fn permissions)]
8686
pub(super) type Permissions<T: Config> = StorageDoubleMap<
8787
_,
88-
Blake2_128Concat,
88+
Identity,
8989
PalletId, // pallet_id
90-
Blake2_128Concat,
90+
Identity,
9191
PermissionId, // permission_id
9292
BoundedVec<u8, T::PermissionMaxLen >, // permission str
9393
ValueQuery,
@@ -97,9 +97,9 @@ pub mod pallet {
9797
#[pallet::getter(fn permissions_by_role)]
9898
pub(super) type PermissionsByRole<T: Config> = StorageDoubleMap<
9999
_,
100-
Blake2_128Concat,
100+
Identity,
101101
PalletId, // pallet_id
102-
Blake2_128Concat,
102+
Identity,
103103
RoleId, // role_id
104104
BoundedVec<PermissionId, T::MaxPermissionsPerRole >, // permission_ids
105105
ValueQuery,
@@ -112,8 +112,8 @@ pub mod pallet {
112112
(
113113
NMapKey<Blake2_128Concat, T::AccountId>,// user
114114
// getting "the trait bound `usize: scale_info::TypeInfo` is not satisfied" errors
115-
NMapKey<Blake2_128Concat, PalletId>, // pallet_id
116-
NMapKey<Twox64Concat, ScopeId>, // scope_id
115+
NMapKey<Identity, PalletId>, // pallet_id
116+
NMapKey<Identity, ScopeId>, // scope_id
117117
),
118118
BoundedVec<RoleId, T::MaxRolesPerUser>, // roles (ids)
119119
ValueQuery,
@@ -126,9 +126,9 @@ pub mod pallet {
126126
(
127127
// getting "the trait bound `usize: scale_info::TypeInfo` is not satisfied" errors
128128
// on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes.
129-
NMapKey<Blake2_128Concat, PalletId>, // pallet_id
130-
NMapKey<Twox64Concat, ScopeId>, // scope_id
131-
NMapKey<Blake2_128Concat, RoleId>, // role_id
129+
NMapKey<Identity, PalletId>, // pallet_id
130+
NMapKey<Identity, ScopeId>, // scope_id
131+
NMapKey<Identity, RoleId>, // role_id
132132
),
133133
BoundedVec<T::AccountId, T::MaxUsersPerRole>, // users
134134
ValueQuery,
@@ -199,19 +199,5 @@ pub mod pallet {
199199

200200
#[pallet::call]
201201
impl<T: Config> Pallet<T> {
202-
203-
#[transactional]
204-
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
205-
pub fn get_pallet_id(
206-
origin: OriginFor<T>,
207-
) -> DispatchResult {
208-
let who = ensure_signed(origin.clone())?;
209-
let a = Self::index();
210-
log::info!("henlo {:?}", a);
211-
log::warn!("Name: {:?} Module Name: {:?}",Self::name(), Self::module_name());
212-
Self::deposit_event(Event::SomethingStored(a.try_into().unwrap(), who));
213-
214-
Ok(())
215-
}
216202
}
217203
}

pallets/rbac/src/tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::{mock::*, Error, types::{RoleBasedAccessControl, RoleId, ScopeId, PermissionId, IdOrVec}, Config, PermissionsByRole, Permissions};
2-
use codec::Encode;
32
use frame_support::{assert_noop, assert_ok, assert_err, BoundedVec, pallet_prelude::DispatchResult};
4-
use sp_io::hashing::blake2_256;
53

64
type AccountId = <Test as frame_system::Config>::AccountId;
75

0 commit comments

Comments
 (0)