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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
0b75ae3f
Unverified
Commit
0b75ae3f
authored
1 year ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
optimize AccountLinker
parent
54d8caf9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pallets/duniter-account/src/lib.rs
+6
-10
6 additions, 10 deletions
pallets/duniter-account/src/lib.rs
pallets/identity/src/lib.rs
+3
-3
3 additions, 3 deletions
pallets/identity/src/lib.rs
pallets/identity/src/traits.rs
+2
-2
2 additions, 2 deletions
pallets/identity/src/traits.rs
with
11 additions
and
15 deletions
pallets/duniter-account/src/lib.rs
+
6
−
10
View file @
0b75ae3f
...
@@ -219,22 +219,18 @@ pub mod pallet {
...
@@ -219,22 +219,18 @@ pub mod pallet {
/// link account to identity
/// link account to identity
pub
fn
do_link_identity
(
pub
fn
do_link_identity
(
account_id
:
T
::
AccountId
,
account_id
:
&
T
::
AccountId
,
idty_id
:
IdtyIdOf
<
T
>
,
idty_id
:
IdtyIdOf
<
T
>
,
)
->
Result
<
(),
DispatchError
>
{
)
->
Result
<
(),
DispatchError
>
{
// Check that account exist
// Check that account exist
ensure!
(
ensure!
(
(
frame_system
::
Account
::
<
T
>
::
get
(
&
account_id
)
.providers
>=
1
)
(
frame_system
::
Account
::
<
T
>
::
get
(
account_id
)
.providers
>=
1
)
||
(
frame_system
::
Account
::
<
T
>
::
get
(
&
account_id
)
.sufficients
>=
1
),
||
(
frame_system
::
Account
::
<
T
>
::
get
(
account_id
)
.sufficients
>=
1
),
pallet_identity
::
Error
::
<
T
>
::
AccountNotExist
pallet_identity
::
Error
::
<
T
>
::
AccountNotExist
);
);
// no-op if identity does not change
// no-op if identity does not change
if
frame_system
::
Account
::
<
T
>
::
get
(
&
account_id
)
if
frame_system
::
Account
::
<
T
>
::
get
(
account_id
)
.data.linked_idty
!=
Some
(
idty_id
)
{
.data
frame_system
::
Account
::
<
T
>
::
mutate
(
account_id
,
|
account
|
{
.linked_idty
!=
Some
(
idty_id
)
{
frame_system
::
Account
::
<
T
>
::
mutate
(
&
account_id
,
|
account
|
{
account
.data.linked_idty
=
Some
(
idty_id
);
account
.data.linked_idty
=
Some
(
idty_id
);
Self
::
deposit_event
(
Event
::
AccountLinked
{
Self
::
deposit_event
(
Event
::
AccountLinked
{
who
:
account_id
.clone
(),
who
:
account_id
.clone
(),
...
@@ -335,7 +331,7 @@ impl<T> pallet_identity::traits::LinkIdty<T::AccountId, IdtyIdOf<T>> for Pallet<
...
@@ -335,7 +331,7 @@ impl<T> pallet_identity::traits::LinkIdty<T::AccountId, IdtyIdOf<T>> for Pallet<
where
where
T
:
Config
,
T
:
Config
,
{
{
fn
link_identity
(
account_id
:
T
::
AccountId
,
idty_id
:
IdtyIdOf
<
T
>
)
->
Result
<
(),
DispatchError
>
{
fn
link_identity
(
account_id
:
&
T
::
AccountId
,
idty_id
:
IdtyIdOf
<
T
>
)
->
Result
<
(),
DispatchError
>
{
Self
::
do_link_identity
(
account_id
,
idty_id
)
Self
::
do_link_identity
(
account_id
,
idty_id
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
pallets/identity/src/lib.rs
+
3
−
3
View file @
0b75ae3f
...
@@ -328,7 +328,7 @@ pub mod pallet {
...
@@ -328,7 +328,7 @@ pub mod pallet {
idty_index
,
idty_index
,
owner_key
:
owner_key
.clone
(),
owner_key
:
owner_key
.clone
(),
});
});
T
::
AccountLinker
::
link_identity
(
owner_key
.clone
()
,
idty_index
)
?
;
T
::
AccountLinker
::
link_identity
(
&
owner_key
,
idty_index
)
?
;
T
::
OnIdtyChange
::
on_idty_change
(
T
::
OnIdtyChange
::
on_idty_change
(
idty_index
,
idty_index
,
&
IdtyEvent
::
Created
{
&
IdtyEvent
::
Created
{
...
@@ -455,7 +455,7 @@ pub mod pallet {
...
@@ -455,7 +455,7 @@ pub mod pallet {
frame_system
::
Pallet
::
<
T
>
::
inc_sufficients
(
&
idty_value
.owner_key
);
frame_system
::
Pallet
::
<
T
>
::
inc_sufficients
(
&
idty_value
.owner_key
);
IdentityIndexOf
::
<
T
>
::
insert
(
&
idty_value
.owner_key
,
idty_index
);
IdentityIndexOf
::
<
T
>
::
insert
(
&
idty_value
.owner_key
,
idty_index
);
Identities
::
<
T
>
::
insert
(
idty_index
,
idty_value
);
Identities
::
<
T
>
::
insert
(
idty_index
,
idty_value
);
T
::
AccountLinker
::
link_identity
(
new_key
.clone
()
,
idty_index
)
?
;
T
::
AccountLinker
::
link_identity
(
&
new_key
,
idty_index
)
?
;
Self
::
deposit_event
(
Event
::
IdtyChangedOwnerKey
{
Self
::
deposit_event
(
Event
::
IdtyChangedOwnerKey
{
idty_index
,
idty_index
,
new_owner_key
:
new_key
,
new_owner_key
:
new_key
,
...
@@ -586,7 +586,7 @@ pub mod pallet {
...
@@ -586,7 +586,7 @@ pub mod pallet {
Error
::
<
T
>
::
InvalidSignature
Error
::
<
T
>
::
InvalidSignature
);
);
// apply
// apply
T
::
AccountLinker
::
link_identity
(
account_id
,
idty_index
)
?
;
T
::
AccountLinker
::
link_identity
(
&
account_id
,
idty_index
)
?
;
Ok
(()
.into
())
Ok
(()
.into
())
}
}
...
...
This diff is collapsed.
Click to expand it.
pallets/identity/src/traits.rs
+
2
−
2
View file @
0b75ae3f
...
@@ -53,10 +53,10 @@ impl<T: Config> OnIdtyChange<T> for Tuple {
...
@@ -53,10 +53,10 @@ impl<T: Config> OnIdtyChange<T> for Tuple {
/// trait used to link an account to an identity
/// trait used to link an account to an identity
pub
trait
LinkIdty
<
AccountId
,
IdtyIndex
>
{
pub
trait
LinkIdty
<
AccountId
,
IdtyIndex
>
{
fn
link_identity
(
account_id
:
AccountId
,
idty_index
:
IdtyIndex
)
->
Result
<
(),
DispatchError
>
;
fn
link_identity
(
account_id
:
&
AccountId
,
idty_index
:
IdtyIndex
)
->
Result
<
(),
DispatchError
>
;
}
}
impl
<
AccountId
,
IdtyIndex
>
LinkIdty
<
AccountId
,
IdtyIndex
>
for
()
{
impl
<
AccountId
,
IdtyIndex
>
LinkIdty
<
AccountId
,
IdtyIndex
>
for
()
{
fn
link_identity
(
_
:
AccountId
,
_
:
IdtyIndex
)
->
Result
<
(),
DispatchError
>
{
fn
link_identity
(
_
:
&
AccountId
,
_
:
IdtyIndex
)
->
Result
<
(),
DispatchError
>
{
Ok
(())
Ok
(())
}
}
}
}
...
...
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