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
d149ce46
Commit
d149ce46
authored
3 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
fix(account): forbid account destruction until random id assignment
parent
168228a5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!36
feat(runtimes): add account random id & provide randomness calls
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pallets/duniter-account/src/lib.rs
+19
-14
19 additions, 14 deletions
pallets/duniter-account/src/lib.rs
with
19 additions
and
14 deletions
pallets/duniter-account/src/lib.rs
+
19
−
14
View file @
d149ce46
...
@@ -134,8 +134,18 @@ pub mod pallet {
...
@@ -134,8 +134,18 @@ pub mod pallet {
ExistenceRequirement
::
KeepAlive
,
ExistenceRequirement
::
KeepAlive
,
);
);
if
let
Ok
(
imbalance
)
=
res
{
if
let
Ok
(
imbalance
)
=
res
{
// The fees have been collected, we handle the collected amount and we
// The fees have been succesfully collected, we should:
// request the random id
// 1. Increment consumers to prevent the destruction of the account before
// the random id is assigned
// 2. Manage the funds collected
// 3. Submit random id generation request
// 4. Save the id of the random generation request.
let
res
=
frame_system
::
Pallet
::
<
T
>
::
inc_consumers_without_limit
(
&
account_id
);
debug_assert!
(
res
.is_ok
(),
"Cannot fail because providers are incremented just before"
);
T
::
OnUnbalanced
::
on_unbalanced
(
imbalance
);
T
::
OnUnbalanced
::
on_unbalanced
(
imbalance
);
let
request_id
=
pallet_provide_randomness
::
Pallet
::
<
T
>
::
force_request
(
let
request_id
=
pallet_provide_randomness
::
Pallet
::
<
T
>
::
force_request
(
pallet_provide_randomness
::
RandomnessType
::
RandomnessFromTwoEpochsAgo
,
pallet_provide_randomness
::
RandomnessType
::
RandomnessFromTwoEpochsAgo
,
...
@@ -167,19 +177,14 @@ where
...
@@ -167,19 +177,14 @@ where
{
{
fn
on_filled_randomness
(
request_id
:
RequestId
,
randomness
:
H256
)
->
Weight
{
fn
on_filled_randomness
(
request_id
:
RequestId
,
randomness
:
H256
)
->
Weight
{
if
let
Some
(
account_id
)
=
PendingRandomIdAssignments
::
<
T
>
::
take
(
request_id
)
{
if
let
Some
(
account_id
)
=
PendingRandomIdAssignments
::
<
T
>
::
take
(
request_id
)
{
// Can only fail if the account has been deleted in the meantime,
frame_system
::
Account
::
<
T
>
::
mutate
(
&
account_id
,
|
account
|
{
// but this case does not require any processing
account
.consumers
=
account
.consumers
.saturating_sub
(
1
);
let
res
=
frame_system
::
Pallet
::
<
T
>
::
mutate_exists
(
&
account_id
,
|
maybe_account_data
|
{
account
.data.random_id
=
Some
(
randomness
);
if
let
Some
(
ref
mut
account_data
)
=
maybe_account_data
{
});
account_data
.random_id
=
Some
(
randomness
);
Self
::
deposit_event
(
Event
::
RandomIdAssigned
{
}
account_id
,
random_id
:
randomness
,
});
});
if
res
.is_ok
()
{
Self
::
deposit_event
(
Event
::
RandomIdAssigned
{
account_id
,
random_id
:
randomness
,
});
}
200_000
200_000
}
else
{
}
else
{
100_000
100_000
...
...
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