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
Merge requests
!48
add pallet treasury
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
add pallet treasury
elois-treasury
into
master
Overview
0
Commits
1
Pipelines
0
Changes
17
Merged
Éloïs
requested to merge
elois-treasury
into
master
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
version 2
version 2
b1b44b9b
2 years ago
version 1
ed61c345
2 years ago
master (base)
and
latest version
latest version
66ffb479
1 commit,
2 years ago
version 2
b1b44b9b
1 commit,
2 years ago
version 1
ed61c345
1 commit,
2 years ago
Show latest version
2 files
+
120
−
48
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
pallets/duniter-account/src/lib.rs
+
53
−
46
Options
@@ -129,12 +129,16 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super)
fn
deposit_event)]
pub
enum
Event
<
T
:
Config
>
{
/// Force the destruction of an account because its free balance is insufficient to pay
/// the account creation price.
/// [who, balance]
ForceDestroy
{
who
:
T
::
AccountId
,
balance
:
T
::
Balance
,
},
/// Random id assigned
/// [account_id, random_id]
RandomIdAssigned
{
account_id
:
T
::
AccountId
,
random_id
:
H256
,
},
RandomIdAssigned
{
who
:
T
::
AccountId
,
random_id
:
H256
},
}
// HOOKS //
@@ -156,55 +160,58 @@ pub mod pallet {
total_weight
+=
100_000
;
}
else
{
// If the account is not self-sufficient, it must pay the account creation fees
frame_system
::
Pallet
::
<
T
>
::
inc_providers
(
&
account_id
);
let
res
=
<
pallet_balances
::
Pallet
<
T
>
as
Currency
<
T
::
AccountId
>>
::
withdraw
(
&
account_id
,
T
::
NewAccountPrice
::
get
(),
frame_support
::
traits
::
WithdrawReasons
::
FEE
,
ExistenceRequirement
::
KeepAlive
,
);
if
let
Ok
(
imbalance
)
=
res
{
// The fees have been succesfully collected, we should:
// 1. Increment consumers to prevent the destruction of the account before
let
account_data
=
frame_system
::
Pallet
::
<
T
>
::
get
(
&
account_id
);
let
price
=
T
::
NewAccountPrice
::
get
();
if
account_data
.free
>
price
{
// The account can pay the new account price, we should:
// 1. Increment providers to create the account for frame_system point of view
// 2. Withdraw the "new account price" amount
// 3. 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
);
let
request_id
=
pallet_provide_randomness
::
Pallet
::
<
T
>
::
force_request
(
pallet_provide_randomness
::
RandomnessType
::
RandomnessFromTwoEpochsAgo
,
H256
(
T
::
AccountIdToSalt
::
convert
(
account_id
.clone
())),
);
PendingRandomIdAssignments
::
<
T
>
::
insert
(
request_id
,
account_id
);
total_weight
+=
200_000
;
}
else
{
// The charges could not be deducted, we slash the account
let
res
=
frame_system
::
Pallet
::
<
T
>
::
dec_providers
(
&
account_id
);
debug_assert!
(
res
.is_ok
(),
"Cannot fail because providers are incremented just before"
);
let
account_data
=
frame_system
::
Pallet
::
<
T
>
::
get
(
&
account_id
);
// 4. Manage the funds collected
// 5. Submit random id generation request
// 6. Save the id of the random generation request.
frame_system
::
Pallet
::
<
T
>
::
inc_providers
(
&
account_id
);
let
res
=
<
pallet_balances
::
Pallet
<
T
>
as
Currency
<
T
::
AccountId
>>
::
withdraw
(
&
account_id
,
account_data
.free
.saturating_add
(
account_data
.reserved
)
,
price
,
frame_support
::
traits
::
WithdrawReasons
::
FEE
,
ExistenceRequirement
::
AllowDeath
,
ExistenceRequirement
::
KeepAlive
,
);
debug_assert!
(
res
.is_ok
(),
"Cannot fail because we checked that the free balance was sufficient"
);
if
let
Ok
(
imbalance
)
=
res
{
T
::
OnUnbalanced
::
on_unbalanced
(
imbalance
);
}
else
{
log
::
warn
!
(
"Unexpected withdraw fail to destroy account {:?}"
,
&
account_id
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
);
let
request_id
=
pallet_provide_randomness
::
Pallet
::
<
T
>
::
force_request
(
pallet_provide_randomness
::
RandomnessType
::
RandomnessFromTwoEpochsAgo
,
H256
(
T
::
AccountIdToSalt
::
convert
(
account_id
.clone
())),
);
PendingRandomIdAssignments
::
<
T
>
::
insert
(
request_id
,
account_id
);
total_weight
+=
200_000
;
}
}
else
{
// The charges could not be deducted, we slash the account
let
balance_to_suppr
=
account_data
.free
.saturating_add
(
account_data
.reserved
);
// Force account data supression
frame_system
::
Account
::
<
T
>
::
mutate
(
&
account_id
,
|
a
|
{
a
.data
.set_balances
(
Default
::
default
())
});
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
+=
300_000
;
}
}
@@ -225,7 +232,7 @@ where
account
.data.random_id
=
Some
(
randomness
);
});
Self
::
deposit_event
(
Event
::
RandomIdAssigned
{
account_id
,
who
:
account_id
,
random_id
:
randomness
,
});
200_000
Loading