-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mnaamani/permissions
Permissions Layer for Versioned store
- Loading branch information
Showing
9 changed files
with
1,907 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
**/target/ | ||
|
||
# Cargo lock file for native runtime - only used for cargo test | ||
./Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# JetBrains IDEs | ||
.idea | ||
|
||
# Vim | ||
.*.sw* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[package] | ||
name = 'substrate-versioned-store-permissions-module' | ||
version = '1.0.0' | ||
authors = ['Mokhtar Naamani <mokhtar.naamani@gmail.com>'] | ||
edition = '2018' | ||
|
||
[dependencies] | ||
hex-literal = '0.1.0' | ||
serde = { version = '1.0', optional = true } | ||
serde_derive = { version = '1.0', optional = true } | ||
codec = { package = 'parity-scale-codec', version = '1.0.0', default-features = false, features = ['derive'] } | ||
rstd = { package = 'sr-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
runtime-primitives = { package = 'sr-primitives', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
srml-support = { package = 'srml-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
srml-support-procedural = { package = 'srml-support-procedural', git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
system = { package = 'srml-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
timestamp = { package = 'srml-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
|
||
[dependencies.versioned-store] | ||
default_features = false | ||
package ='substrate-versioned-store' | ||
git = 'https://github.com/joystream/substrate-versioned-store-module' | ||
rev = 'd0c68722405355404840512edf3064d5ced3e1fe' | ||
|
||
[dev-dependencies] | ||
runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
primitives = { package = 'substrate-primitives', git = 'https://github.com/paritytech/substrate.git', rev = '0e3001a1ad6fa3d1ba7da7342a8d0d3b3facb2f3'} | ||
|
||
[features] | ||
default = ['std'] | ||
std = [ | ||
'serde', | ||
'serde_derive', | ||
'codec/std', | ||
'rstd/std', | ||
'runtime-io/std', | ||
'runtime-primitives/std', | ||
'srml-support/std', | ||
'system/std', | ||
'timestamp/std', | ||
'versioned-store/std', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use codec::{Decode, Encode}; | ||
use rstd::collections::btree_set::BTreeSet; | ||
|
||
/// Reference to a specific property of a specific class. | ||
#[derive(Encode, Decode, Eq, PartialEq, Ord, PartialOrd, Clone, Debug)] | ||
pub struct PropertyOfClass<ClassId, PropertyIndex> { | ||
pub class_id: ClassId, | ||
pub property_index: PropertyIndex, | ||
} | ||
|
||
/// The type of constraint imposed on referencing a class via class property of type "Internal". | ||
#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] | ||
pub enum ReferenceConstraint<ClassId: Ord, PropertyIndex: Ord> { | ||
/// No property can reference the class. | ||
NoReferencingAllowed, | ||
|
||
/// Any property of any class may reference the class. | ||
NoConstraint, | ||
|
||
/// Only a set of properties of specific classes can reference the class. | ||
Restricted(BTreeSet<PropertyOfClass<ClassId, PropertyIndex>>), | ||
} | ||
|
||
impl<ClassId: Ord, PropertyIndex: Ord> Default for ReferenceConstraint<ClassId, PropertyIndex> { | ||
fn default() -> Self { | ||
ReferenceConstraint::NoReferencingAllowed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use codec::{Decode, Encode}; | ||
use rstd::collections::btree_set::BTreeSet; | ||
use rstd::prelude::*; | ||
|
||
#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)] | ||
pub struct CredentialSet<Credential>(BTreeSet<Credential>); | ||
|
||
impl<Credential> From<Vec<Credential>> for CredentialSet<Credential> | ||
where | ||
Credential: Ord, | ||
{ | ||
fn from(v: Vec<Credential>) -> CredentialSet<Credential> { | ||
let mut set = CredentialSet(BTreeSet::new()); | ||
for credential in v.into_iter() { | ||
set.insert(credential); | ||
} | ||
set | ||
} | ||
} | ||
|
||
/// Default CredentialSet set is just an empty set. | ||
impl<Credential: Ord> Default for CredentialSet<Credential> { | ||
fn default() -> Self { | ||
CredentialSet(BTreeSet::new()) | ||
} | ||
} | ||
|
||
impl<Credential: Ord> CredentialSet<Credential> { | ||
pub fn new() -> Self { | ||
Self(BTreeSet::new()) | ||
} | ||
|
||
pub fn insert(&mut self, value: Credential) -> bool { | ||
self.0.insert(value) | ||
} | ||
|
||
pub fn contains(&self, value: &Credential) -> bool { | ||
self.0.contains(value) | ||
} | ||
|
||
pub fn is_empty(&self) -> bool { | ||
self.0.is_empty() | ||
} | ||
} | ||
|
||
/// Type, derived from dispatchable call, identifies the caller | ||
#[derive(Encode, Decode, Eq, PartialEq, Ord, PartialOrd, Clone, Debug)] | ||
pub enum AccessLevel<Credential> { | ||
/// ROOT origin | ||
System, | ||
/// Caller identified as the entity maintainer | ||
EntityMaintainer, // Maybe enclose EntityId? | ||
/// Verified Credential | ||
Credential(Credential), | ||
/// In cases where a signed extrinsic doesn't provide a Credential | ||
Unspecified, | ||
} |
Oops, something went wrong.