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
f3a556ab
Commit
f3a556ab
authored
3 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
feat(universal-dividend): write ud history in offchain storage
parent
a624304b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pallets/universal-dividend/Cargo.toml
+6
-0
6 additions, 0 deletions
pallets/universal-dividend/Cargo.toml
pallets/universal-dividend/src/lib.rs
+14
-3
14 additions, 3 deletions
pallets/universal-dividend/src/lib.rs
with
20 additions
and
3 deletions
pallets/universal-dividend/Cargo.toml
+
6
−
0
View file @
f3a556ab
...
...
@@ -17,6 +17,7 @@ std = [
'frame-system/std'
,
'frame-benchmarking/std'
,
"sp-arithmetic/std"
,
"sp-io/std"
,
"sp-std/std"
,
]
try-runtime
=
[
'frame-support/try-runtime'
]
...
...
@@ -48,6 +49,11 @@ default-features = false
git
=
'https://github.com/paritytech/substrate.git'
tag
=
'monthly-2021-07'
[dependencies.sp-io]
default-features
=
false
git
=
'https://github.com/paritytech/substrate.git'
tag
=
'monthly-2021-07'
[dependencies.sp-std]
default-features
=
false
git
=
'https://github.com/paritytech/substrate.git'
...
...
This diff is collapsed.
Click to expand it.
pallets/universal-dividend/src/lib.rs
+
14
−
3
View file @
f3a556ab
...
...
@@ -31,6 +31,8 @@ use frame_support::traits::Currency;
use
sp_arithmetic
::{
per_things
::
Permill
,
traits
::
Zero
};
use
sp_std
::
prelude
::
*
;
const
OFFCHAIN_PREFIX_UD_HISTORY
:
&
[
u8
]
=
b"ud::history::"
;
#[frame_support::pallet]
pub
mod
pallet
{
use
super
::
*
;
...
...
@@ -154,9 +156,10 @@ pub mod pallet {
if
(
n
%
T
::
UD_CREATION_PERIOD
)
.is_zero
()
{
let
current_members_count
=
T
::
MembersCount
::
get
();
if
(
n
%
T
::
UD_REEVAL_PERIOD_IN_BLOCKS
)
.is_zero
()
{
Self
::
reeval_ud
(
current_members_count
)
+
Self
::
create_ud
(
current_members_count
)
Self
::
reeval_ud
(
current_members_count
)
+
Self
::
create_ud
(
current_members_count
,
n
)
}
else
{
Self
::
create_ud
(
current_members_count
)
Self
::
create_ud
(
current_members_count
,
n
)
}
}
else
{
0
...
...
@@ -182,7 +185,7 @@ pub mod pallet {
// INTERNAL FUNCTIONS //
impl
<
T
:
Config
>
Pallet
<
T
>
{
fn
create_ud
(
current_members_count
:
BalanceOf
<
T
>
)
->
Weight
{
fn
create_ud
(
current_members_count
:
BalanceOf
<
T
>
,
n
:
T
::
BlockNumber
)
->
Weight
{
let
total_weight
:
Weight
=
0
;
let
LastReeval
{
ud_amount
,
..
}
=
...
...
@@ -192,6 +195,7 @@ pub mod pallet {
for
account_id
in
T
::
MembersIds
::
get
()
{
T
::
Currency
::
deposit_creating
(
&
account_id
,
ud_amount
);
monetary_mass
+=
ud_amount
;
Self
::
write_ud_history
(
n
,
account_id
,
ud_amount
);
}
<
MonetaryMassStorage
<
T
>>
::
put
(
monetary_mass
);
...
...
@@ -245,5 +249,12 @@ pub mod pallet {
// UD(t+1) = UD(t) + c² (M(t) / N(t)) / (dt/udFrequency)
ud_t
+
c_square
*
monetary_mass
/
(
members_count
*
count_uds_beetween_two_reevals
)
}
fn
write_ud_history
(
n
:
T
::
BlockNumber
,
account_id
:
T
::
AccountId
,
ud_amount
:
BalanceOf
<
T
>
)
{
let
mut
key
=
Vec
::
with_capacity
(
57
);
key
.extend_from_slice
(
OFFCHAIN_PREFIX_UD_HISTORY
);
account_id
.encode_to
(
&
mut
key
);
n
.encode_to
(
&
mut
key
);
sp_io
::
offchain_index
::
set
(
key
.as_ref
(),
ud_amount
.encode
()
.as_ref
());
}
}
}
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