Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
22863c31
Commit
22863c31
authored
2 years ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
doc identity
parent
f4c15a0d
No related branches found
No related tags found
No related merge requests found
Pipeline
#18710
passed
2 years ago
Stage: labels
Stage: quality
Stage: build
Stage: tests
Stage: deploy
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pallets/identity/src/lib.rs
+15
-0
15 additions, 0 deletions
pallets/identity/src/lib.rs
pallets/identity/src/types.rs
+26
-0
26 additions, 0 deletions
pallets/identity/src/types.rs
with
41 additions
and
0 deletions
pallets/identity/src/lib.rs
+
15
−
0
View file @
22863c31
...
@@ -312,6 +312,7 @@ pub mod pallet {
...
@@ -312,6 +312,7 @@ pub mod pallet {
T
::
OnIdtyChange
::
on_idty_change
(
idty_index
,
&
IdtyEvent
::
Created
{
creator
});
T
::
OnIdtyChange
::
on_idty_change
(
idty_index
,
&
IdtyEvent
::
Created
{
creator
});
Ok
(()
.into
())
Ok
(()
.into
())
}
}
/// Confirm the creation of an identity and give it a name
/// Confirm the creation of an identity and give it a name
///
///
/// - `idty_name`: the name uniquely associated to this identity. Must match the validation rules defined by the runtime.
/// - `idty_name`: the name uniquely associated to this identity. Must match the validation rules defined by the runtime.
...
@@ -355,7 +356,9 @@ pub mod pallet {
...
@@ -355,7 +356,9 @@ pub mod pallet {
T
::
OnIdtyChange
::
on_idty_change
(
idty_index
,
&
IdtyEvent
::
Confirmed
);
T
::
OnIdtyChange
::
on_idty_change
(
idty_index
,
&
IdtyEvent
::
Confirmed
);
Ok
(()
.into
())
Ok
(()
.into
())
}
}
#[pallet::weight(
1_000_000_000
)]
#[pallet::weight(
1_000_000_000
)]
/// validate the owned identity (must meet the main wot requirements)
pub
fn
validate_identity
(
pub
fn
validate_identity
(
origin
:
OriginFor
<
T
>
,
origin
:
OriginFor
<
T
>
,
idty_index
:
T
::
IdtyIndex
,
idty_index
:
T
::
IdtyIndex
,
...
@@ -517,6 +520,7 @@ pub mod pallet {
...
@@ -517,6 +520,7 @@ pub mod pallet {
}
}
#[pallet::weight(
1_000_000_000
)]
#[pallet::weight(
1_000_000_000
)]
/// remove an identity from storage
pub
fn
remove_identity
(
pub
fn
remove_identity
(
origin
:
OriginFor
<
T
>
,
origin
:
OriginFor
<
T
>
,
idty_index
:
T
::
IdtyIndex
,
idty_index
:
T
::
IdtyIndex
,
...
@@ -533,6 +537,7 @@ pub mod pallet {
...
@@ -533,6 +537,7 @@ pub mod pallet {
}
}
#[pallet::weight(
1_000_000_000
)]
#[pallet::weight(
1_000_000_000
)]
/// remove identity names from storage
pub
fn
prune_item_identities_names
(
pub
fn
prune_item_identities_names
(
origin
:
OriginFor
<
T
>
,
origin
:
OriginFor
<
T
>
,
names
:
Vec
<
IdtyName
>
,
names
:
Vec
<
IdtyName
>
,
...
@@ -547,6 +552,7 @@ pub mod pallet {
...
@@ -547,6 +552,7 @@ pub mod pallet {
}
}
#[pallet::weight(
1_000_000_000
)]
#[pallet::weight(
1_000_000_000
)]
/// change sufficient ref count for given key
pub
fn
fix_sufficients
(
pub
fn
fix_sufficients
(
origin
:
OriginFor
<
T
>
,
origin
:
OriginFor
<
T
>
,
owner_key
:
T
::
AccountId
,
owner_key
:
T
::
AccountId
,
...
@@ -625,6 +631,7 @@ pub mod pallet {
...
@@ -625,6 +631,7 @@ pub mod pallet {
// INTERNAL FUNCTIONS //
// INTERNAL FUNCTIONS //
impl
<
T
:
Config
>
Pallet
<
T
>
{
impl
<
T
:
Config
>
Pallet
<
T
>
{
/// perform identity removal
pub
(
super
)
fn
do_remove_identity
(
idty_index
:
T
::
IdtyIndex
)
->
Weight
{
pub
(
super
)
fn
do_remove_identity
(
idty_index
:
T
::
IdtyIndex
)
->
Weight
{
if
let
Some
(
idty_val
)
=
Identities
::
<
T
>
::
get
(
idty_index
)
{
if
let
Some
(
idty_val
)
=
Identities
::
<
T
>
::
get
(
idty_index
)
{
let
_
=
T
::
RemoveIdentityConsumers
::
remove_idty_consumers
(
idty_index
);
let
_
=
T
::
RemoveIdentityConsumers
::
remove_idty_consumers
(
idty_index
);
...
@@ -645,6 +652,7 @@ pub mod pallet {
...
@@ -645,6 +652,7 @@ pub mod pallet {
}
}
Weight
::
zero
()
Weight
::
zero
()
}
}
/// incremental counter for identity index
fn
get_next_idty_index
()
->
T
::
IdtyIndex
{
fn
get_next_idty_index
()
->
T
::
IdtyIndex
{
if
let
Ok
(
next_index
)
=
<
NextIdtyIndex
<
T
>>
::
try_get
()
{
if
let
Ok
(
next_index
)
=
<
NextIdtyIndex
<
T
>>
::
try_get
()
{
<
NextIdtyIndex
<
T
>>
::
put
(
next_index
.saturating_add
(
T
::
IdtyIndex
::
one
()));
<
NextIdtyIndex
<
T
>>
::
put
(
next_index
.saturating_add
(
T
::
IdtyIndex
::
one
()));
...
@@ -654,6 +662,7 @@ pub mod pallet {
...
@@ -654,6 +662,7 @@ pub mod pallet {
T
::
IdtyIndex
::
one
()
T
::
IdtyIndex
::
one
()
}
}
}
}
/// remove identities planned for removal at the given block if their status did not change
fn
prune_identities
(
block_number
:
T
::
BlockNumber
)
->
Weight
{
fn
prune_identities
(
block_number
:
T
::
BlockNumber
)
->
Weight
{
let
mut
total_weight
=
Weight
::
zero
();
let
mut
total_weight
=
Weight
::
zero
();
...
@@ -670,16 +679,21 @@ pub mod pallet {
...
@@ -670,16 +679,21 @@ pub mod pallet {
}
}
}
}
// implement getting owner key of identity index
impl
<
T
:
Config
>
sp_runtime
::
traits
::
Convert
<
T
::
IdtyIndex
,
Option
<
T
::
AccountId
>>
for
Pallet
<
T
>
{
impl
<
T
:
Config
>
sp_runtime
::
traits
::
Convert
<
T
::
IdtyIndex
,
Option
<
T
::
AccountId
>>
for
Pallet
<
T
>
{
fn
convert
(
idty_index
:
T
::
IdtyIndex
)
->
Option
<
T
::
AccountId
>
{
fn
convert
(
idty_index
:
T
::
IdtyIndex
)
->
Option
<
T
::
AccountId
>
{
Identities
::
<
T
>
::
get
(
idty_index
)
.map
(|
idty_val
|
idty_val
.owner_key
)
Identities
::
<
T
>
::
get
(
idty_index
)
.map
(|
idty_val
|
idty_val
.owner_key
)
}
}
}
}
// implement StoredMap trait for this pallet
impl
<
T
>
frame_support
::
traits
::
StoredMap
<
T
::
AccountId
,
T
::
IdtyData
>
for
Pallet
<
T
>
impl
<
T
>
frame_support
::
traits
::
StoredMap
<
T
::
AccountId
,
T
::
IdtyData
>
for
Pallet
<
T
>
where
where
T
:
Config
,
T
:
Config
,
{
{
/// get identity data for an account id
fn
get
(
key
:
&
T
::
AccountId
)
->
T
::
IdtyData
{
fn
get
(
key
:
&
T
::
AccountId
)
->
T
::
IdtyData
{
if
let
Some
(
idty_index
)
=
Self
::
identity_index_of
(
key
)
{
if
let
Some
(
idty_index
)
=
Self
::
identity_index_of
(
key
)
{
if
let
Some
(
idty_val
)
=
Identities
::
<
T
>
::
get
(
idty_index
)
{
if
let
Some
(
idty_val
)
=
Identities
::
<
T
>
::
get
(
idty_index
)
{
...
@@ -691,6 +705,7 @@ where
...
@@ -691,6 +705,7 @@ where
Default
::
default
()
Default
::
default
()
}
}
}
}
/// mutate an account fiven a function of its data
fn
try_mutate_exists
<
R
,
E
:
From
<
sp_runtime
::
DispatchError
>>
(
fn
try_mutate_exists
<
R
,
E
:
From
<
sp_runtime
::
DispatchError
>>
(
key
:
&
T
::
AccountId
,
key
:
&
T
::
AccountId
,
f
:
impl
FnOnce
(
&
mut
Option
<
T
::
IdtyData
>
)
->
Result
<
R
,
E
>
,
f
:
impl
FnOnce
(
&
mut
Option
<
T
::
IdtyData
>
)
->
Result
<
R
,
E
>
,
...
...
This diff is collapsed.
Click to expand it.
pallets/identity/src/types.rs
+
26
−
0
View file @
22863c31
...
@@ -23,17 +23,25 @@ use scale_info::TypeInfo;
...
@@ -23,17 +23,25 @@ use scale_info::TypeInfo;
use
serde
::{
Deserialize
,
Serialize
};
use
serde
::{
Deserialize
,
Serialize
};
use
sp_std
::
vec
::
Vec
;
use
sp_std
::
vec
::
Vec
;
/// events related to identity
pub
enum
IdtyEvent
<
T
:
crate
::
Config
>
{
pub
enum
IdtyEvent
<
T
:
crate
::
Config
>
{
/// creation of a new identity by an other
Created
{
creator
:
T
::
IdtyIndex
},
Created
{
creator
:
T
::
IdtyIndex
},
/// confirmation of an identity (with a given name)
Confirmed
,
Confirmed
,
/// validation of an identity
Validated
,
Validated
,
/// changing the owner key of the identity
ChangedOwnerKey
{
new_owner_key
:
T
::
AccountId
},
ChangedOwnerKey
{
new_owner_key
:
T
::
AccountId
},
/// removing an identity
Removed
{
status
:
IdtyStatus
},
Removed
{
status
:
IdtyStatus
},
}
}
/// name of the identity, ascii encoded
#[derive(Encode,
Decode,
Default,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
RuntimeDebug)]
#[derive(Encode,
Decode,
Default,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
RuntimeDebug)]
pub
struct
IdtyName
(
pub
Vec
<
u8
>
);
pub
struct
IdtyName
(
pub
Vec
<
u8
>
);
/// implement scale string typeinfo for encoding
impl
scale_info
::
TypeInfo
for
IdtyName
{
impl
scale_info
::
TypeInfo
for
IdtyName
{
type
Identity
=
str
;
type
Identity
=
str
;
...
@@ -65,6 +73,8 @@ impl<'de> serde::Deserialize<'de> for IdtyName {
...
@@ -65,6 +73,8 @@ impl<'de> serde::Deserialize<'de> for IdtyName {
}
}
}
}
/// status of the identity
/// used for temporary period before validation
#[cfg_attr(feature
=
"std"
,
derive(Deserialize,
Serialize))]
#[cfg_attr(feature
=
"std"
,
derive(Deserialize,
Serialize))]
#[derive(Encode,
Decode,
Clone,
Copy,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo)]
#[derive(Encode,
Decode,
Clone,
Copy,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo)]
pub
enum
IdtyStatus
{
pub
enum
IdtyStatus
{
...
@@ -78,28 +88,44 @@ impl Default for IdtyStatus {
...
@@ -78,28 +88,44 @@ impl Default for IdtyStatus {
}
}
}
}
/// identity value (as in key/value)
#[cfg_attr(feature
=
"std"
,
derive(Debug,
Deserialize,
Serialize))]
#[cfg_attr(feature
=
"std"
,
derive(Debug,
Deserialize,
Serialize))]
#[derive(Encode,
Decode,
Clone,
PartialEq,
Eq,
TypeInfo)]
#[derive(Encode,
Decode,
Clone,
PartialEq,
Eq,
TypeInfo)]
pub
struct
IdtyValue
<
BlockNumber
,
AccountId
,
IdtyData
>
{
pub
struct
IdtyValue
<
BlockNumber
,
AccountId
,
IdtyData
>
{
/// data shared between pallets defined by runtime
/// only contains first_eligible_ud in our case
pub
data
:
IdtyData
,
pub
data
:
IdtyData
,
/// block before which creating a new identity is not allowed
pub
next_creatable_identity_on
:
BlockNumber
,
pub
next_creatable_identity_on
:
BlockNumber
,
/// previous owner key of this identity (optional)
pub
old_owner_key
:
Option
<
(
AccountId
,
BlockNumber
)
>
,
pub
old_owner_key
:
Option
<
(
AccountId
,
BlockNumber
)
>
,
/// current owner key of this identity
pub
owner_key
:
AccountId
,
pub
owner_key
:
AccountId
,
/// block before which this identity can not be removed
/// used only for temporary period before validation
/// equals 0 for a validated identity
pub
removable_on
:
BlockNumber
,
pub
removable_on
:
BlockNumber
,
/// current status of the identity (until validation)
pub
status
:
IdtyStatus
,
pub
status
:
IdtyStatus
,
}
}
/// payload to define a new owner key
#[derive(Clone,
Copy,
Encode,
RuntimeDebug)]
#[derive(Clone,
Copy,
Encode,
RuntimeDebug)]
pub
struct
NewOwnerKeyPayload
<
'a
,
AccountId
,
IdtyIndex
,
Hash
>
{
pub
struct
NewOwnerKeyPayload
<
'a
,
AccountId
,
IdtyIndex
,
Hash
>
{
/// hash of the genesis block
// Avoid replay attack between networks
// Avoid replay attack between networks
pub
genesis_hash
:
&
'a
Hash
,
pub
genesis_hash
:
&
'a
Hash
,
/// identity index
pub
idty_index
:
IdtyIndex
,
pub
idty_index
:
IdtyIndex
,
/// old owner key of the identity
pub
old_owner_key
:
&
'a
AccountId
,
pub
old_owner_key
:
&
'a
AccountId
,
}
}
#[derive(Clone,
Copy,
Encode,
Decode,
PartialEq,
Eq,
TypeInfo,
RuntimeDebug)]
#[derive(Clone,
Copy,
Encode,
Decode,
PartialEq,
Eq,
TypeInfo,
RuntimeDebug)]
pub
struct
RevocationPayload
<
IdtyIndex
,
Hash
>
{
pub
struct
RevocationPayload
<
IdtyIndex
,
Hash
>
{
/// hash of the genesis block
// Avoid replay attack between networks
// Avoid replay attack between networks
pub
genesis_hash
:
Hash
,
pub
genesis_hash
:
Hash
,
/// identity index
pub
idty_index
:
IdtyIndex
,
pub
idty_index
:
IdtyIndex
,
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment