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
f1c6e12b
Unverified
Commit
f1c6e12b
authored
2 months ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
refactore double queries
parent
093a7258
No related branches found
No related tags found
1 merge request
!319
Fix #291
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pallets/smith-members/src/lib.rs
+23
-30
23 additions, 30 deletions
pallets/smith-members/src/lib.rs
with
23 additions
and
30 deletions
pallets/smith-members/src/lib.rs
+
23
−
30
View file @
f1c6e12b
...
...
@@ -589,46 +589,39 @@ impl<T: Config> Pallet<T> {
/// Handle the event when a Smith goes online.
pub
fn
on_smith_goes_online
(
idty_index
:
T
::
IdtyIndex
)
{
if
let
Some
(
smith_meta
)
=
Smiths
::
<
T
>
::
get
(
idty_index
)
{
if
smith_meta
.expires_on
.is_some
()
{
Smiths
::
<
T
>
::
mutate
(
idty_index
,
|
maybe_smith_meta
|
{
if
let
Some
(
smith_meta
)
=
maybe_smith_meta
{
// As long as the smith is online, it cannot expire
smith_meta
.expires_on
=
None
;
smith_meta
.last_online
=
None
;
}
});
Smiths
::
<
T
>
::
mutate
(
idty_index
,
|
maybe_smith_meta
|
{
if
let
Some
(
smith_meta
)
=
maybe_smith_meta
{
if
smith_meta
.expires_on
.is_some
()
{
// As long as the smith is online, it cannot expire
smith_meta
.expires_on
=
None
;
smith_meta
.last_online
=
None
;
}
}
}
}
);
}
/// Handle the event when a Smith goes offline.
pub
fn
on_smith_goes_offline
(
idty_index
:
T
::
IdtyIndex
)
{
if
let
Some
(
smith_meta
)
=
Smiths
::
<
T
>
::
get
(
idty_index
)
{
// Smith can go offline after main membership expiry
// in this case, there is no scheduled expiry since it is already excluded
if
smith_meta
.status
!=
SmithStatus
::
Excluded
{
Smiths
::
<
T
>
::
mutate
(
idty_index
,
|
maybe_smith_meta
|
{
if
let
Some
(
smith_meta
)
=
maybe_smith_meta
{
// schedule expiry
let
new_expires_on
=
CurrentSession
::
<
T
>
::
get
()
+
T
::
SmithInactivityMaxDuration
::
get
();
smith_meta
.expires_on
=
Some
(
new_expires_on
);
let
block_number
=
frame_system
::
pallet
::
Pallet
::
<
T
>
::
block_number
();
smith_meta
.last_online
=
Some
(
block_number
);
ExpiresOn
::
<
T
>
::
append
(
new_expires_on
,
idty_index
);
}
});
Smiths
::
<
T
>
::
mutate
(
idty_index
,
|
maybe_smith_meta
|
{
if
let
Some
(
smith_meta
)
=
maybe_smith_meta
{
// Smith can go offline after main membership expiry
// in this case, there is no scheduled expiry since it is already excluded
if
smith_meta
.status
!=
SmithStatus
::
Excluded
{
// schedule expiry
let
new_expires_on
=
CurrentSession
::
<
T
>
::
get
()
+
T
::
SmithInactivityMaxDuration
::
get
();
smith_meta
.expires_on
=
Some
(
new_expires_on
);
let
block_number
=
frame_system
::
pallet
::
Pallet
::
<
T
>
::
block_number
();
smith_meta
.last_online
=
Some
(
block_number
);
ExpiresOn
::
<
T
>
::
append
(
new_expires_on
,
idty_index
);
}
}
}
}
);
}
/// Provide whether the given identity index is a Smith.
fn
provide_is_member
(
idty_id
:
&
T
::
IdtyIndex
)
->
bool
{
let
Some
(
smith
)
=
Smiths
::
<
T
>
::
get
(
idty_id
)
else
{
return
false
;
};
smith
.status
==
SmithStatus
::
Smith
Smiths
::
<
T
>
::
get
(
idty_id
)
.map_or
(
false
,
|
smith
|
smith
.status
==
SmithStatus
::
Smith
)
}
}
...
...
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