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
9bcb14ca
Commit
9bcb14ca
authored
1 year ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
WIP: seems PendingNewAccounts has no more meaning
parent
373c1ce8
No related branches found
No related tags found
No related merge requests found
Pipeline
#35779
failed
1 year ago
Stage: labels
Stage: quality
Stage: build
Stage: tests
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pallets/duniter-account/src/lib.rs
+0
-97
0 additions, 97 deletions
pallets/duniter-account/src/lib.rs
with
0 additions
and
97 deletions
pallets/duniter-account/src/lib.rs
+
0
−
97
View file @
9bcb14ca
...
@@ -82,13 +82,6 @@ pub mod pallet {
...
@@ -82,13 +82,6 @@ pub mod pallet {
type
Refund
:
pallet_quota
::
traits
::
RefundFee
<
Self
>
;
type
Refund
:
pallet_quota
::
traits
::
RefundFee
<
Self
>
;
}
}
// STORAGE //
#[pallet::storage]
#[pallet::getter(fn
pending_new_accounts)]
pub
type
PendingNewAccounts
<
T
:
Config
>
=
StorageMap
<
_
,
Blake2_128Concat
,
T
::
AccountId
,
(),
OptionQuery
>
;
// GENESIS STUFF //
// GENESIS STUFF //
#[pallet::genesis_config]
#[pallet::genesis_config]
...
@@ -225,71 +218,6 @@ pub mod pallet {
...
@@ -225,71 +218,6 @@ pub mod pallet {
Ok
(())
Ok
(())
}
}
}
}
// HOOKS //
#[pallet::hooks]
impl
<
T
:
Config
>
Hooks
<
BlockNumberFor
<
T
>>
for
Pallet
<
T
>
{
// on initialize, withdraw account creation tax
fn
on_initialize
(
_
:
T
::
BlockNumber
)
->
Weight
{
let
mut
total_weight
=
Weight
::
zero
();
for
account_id
in
PendingNewAccounts
::
<
T
>
::
iter_keys
()
.drain
()
.take
(
T
::
MaxNewAccountsPerBlock
::
get
()
as
usize
)
{
if
frame_system
::
Pallet
::
<
T
>
::
sufficients
(
&
account_id
)
>
0
{
// If the account is self-sufficient, it is exempt from account creation fees
total_weight
+=
<
T
as
pallet
::
Config
>
::
WeightInfo
::
on_initialize_sufficient
(
T
::
MaxNewAccountsPerBlock
::
get
(),
);
}
else
{
// If the account is not self-sufficient, it must pay the account creation fees
let
account_data
=
frame_system
::
Pallet
::
<
T
>
::
get
(
&
account_id
);
let
price
=
T
::
NewAccountPrice
::
get
();
if
account_data
.free
>=
T
::
ExistentialDeposit
::
get
()
+
price
{
// The account can pay the new account price, we should:
// 1. Withdraw the "new account price" amount
// TODO: supprimer 2. Increment consumers to prevent the destruction of the account before the random id is assigned
// 3. Manage the funds collected
let
res
=
<
pallet_balances
::
Pallet
<
T
>
as
Currency
<
T
::
AccountId
>>
::
withdraw
(
&
account_id
,
price
,
frame_support
::
traits
::
WithdrawReasons
::
FEE
,
ExistenceRequirement
::
KeepAlive
,
);
debug_assert!
(
res
.is_ok
(),
"Cannot fail because we checked that the free balance was sufficient"
);
if
let
Ok
(
imbalance
)
=
res
{
// TODO: decrement consumers?
T
::
OnUnbalanced
::
on_unbalanced
(
imbalance
);
total_weight
+=
<
T
as
pallet
::
Config
>
::
WeightInfo
::
on_initialize_with_balance
(
T
::
MaxNewAccountsPerBlock
::
get
(),
);
}
}
else
{
// The charges could not be deducted, we must destroy the account
let
balance_to_suppr
=
account_data
.free
.saturating_add
(
account_data
.reserved
);
// Force account data supression
frame_system
::
Account
::
<
T
>
::
remove
(
&
account_id
);
Self
::
deposit_event
(
Event
::
ForceDestroy
{
who
:
account_id
,
balance
:
balance_to_suppr
,
});
T
::
OnUnbalanced
::
on_unbalanced
(
pallet_balances
::
NegativeImbalance
::
new
(
balance_to_suppr
,
));
total_weight
+=
<
T
as
pallet
::
Config
>
::
WeightInfo
::
on_initialize_no_balance
(
T
::
MaxNewAccountsPerBlock
::
get
(),
);
}
}
}
total_weight
}
}
}
}
// implement account linker
// implement account linker
...
@@ -344,31 +272,6 @@ where
...
@@ -344,31 +272,6 @@ where
None
None
};
};
let
result
=
f
(
&
mut
some_data
)
?
;
let
result
=
f
(
&
mut
some_data
)
?
;
let
is_providing
=
some_data
.is_some
();
match
(
was_providing
,
is_providing
)
{
// the account has just been created, increment its provider
(
false
,
true
)
=>
{
frame_system
::
Pallet
::
<
T
>
::
inc_providers
(
account_id
);
PendingNewAccounts
::
<
T
>
::
insert
(
account_id
,
());
}
// the account was existing but is not anymore, decrement the provider
(
true
,
false
)
=>
{
match
frame_system
::
Pallet
::
<
T
>
::
dec_providers
(
account_id
)
?
{
frame_system
::
DecRefStatus
::
Reaped
=>
return
Ok
(
result
),
frame_system
::
DecRefStatus
::
Exists
=>
{
// Update value as normal
}
}
}
// mutation on unprovided account
(
false
,
false
)
=>
{
return
Ok
(
result
);
}
// mutation on provided account
(
true
,
true
)
=>
{
// Update value as normal
}
}
// do mutate the account by setting the balances
// do mutate the account by setting the balances
frame_system
::
Account
::
<
T
>
::
mutate
(
account_id
,
|
a
|
{
frame_system
::
Account
::
<
T
>
::
mutate
(
account_id
,
|
a
|
{
a
.data
.set_balances
(
some_data
.unwrap_or_default
())
a
.data
.set_balances
(
some_data
.unwrap_or_default
())
...
...
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